Skip to content

Commit 0fba91b

Browse files
authored
Keep function prototype methods (#434)
1 parent d798222 commit 0fba91b

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

source/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ function createChalk(options) {
5454
return chalkFactory(options);
5555
}
5656

57+
Object.setPrototypeOf(createChalk.prototype, Function.prototype);
58+
5759
for (const [styleName, style] of Object.entries(ansiStyles)) {
5860
styles[styleName] = {
5961
get() {

test/chalk.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,9 @@ test('sets correct level for chalkStderr and respects it', t => {
117117
t.is(chalkStderr.level, 3);
118118
t.is(chalkStderr.red.bold('foo'), '\u001B[31m\u001B[1mfoo\u001B[22m\u001B[39m');
119119
});
120+
121+
test('keeps function prototype methods', t => {
122+
t.is(chalk.apply(chalk, ['foo']), 'foo');
123+
t.is(chalk.bind(chalk, 'foo')(), 'foo');
124+
t.is(chalk.call(chalk, 'foo'), 'foo');
125+
});

0 commit comments

Comments
 (0)