Skip to content

Commit

Permalink
Keep function prototype methods (#434)
Browse files Browse the repository at this point in the history
  • Loading branch information
Richienb committed Apr 20, 2021
1 parent d798222 commit 0fba91b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions source/index.js
Expand Up @@ -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() {
Expand Down
6 changes: 6 additions & 0 deletions test/chalk.js
Expand Up @@ -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');
});

0 comments on commit 0fba91b

Please sign in to comment.