Keep function prototype methods

Signed-off-by: Richie Bendall <richiebendall@gmail.com>
This commit is contained in:
Richie Bendall 2021-04-20 11:52:21 +12:00
parent d798222a5a
commit b295668c18
No known key found for this signature in database
GPG key ID: 94AE1ACB662A2A6D
2 changed files with 8 additions and 0 deletions

View file

@ -54,6 +54,8 @@ function createChalk(options) {
return chalkFactory(options);
}
Object.setPrototypeOf(createChalk.prototype, Function.prototype);
for (const [styleName, style] of Object.entries(ansiStyles)) {
styles[styleName] = {
get() {

View file

@ -117,3 +117,9 @@ test('sets correct level for chalkStderr and respects it', t => {
t.is(chalkStderr.level, 3);
t.is(chalkStderr.red.bold('foo'), '\u001B[31m\u001B[1mfoo\u001B[22m\u001B[39m');
});
test('keeps function prototype methods', t => {
t.is(chalk.apply(chalk, ['foo']), 'foo');
t.is(chalk.bind(chalk, 'foo')(), 'foo');
t.is(chalk.call(chalk, 'foo'), 'foo');
});