diff --git a/source/index.js b/source/index.js index 0f159d4..8db69d2 100644 --- a/source/index.js +++ b/source/index.js @@ -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() { diff --git a/test/chalk.js b/test/chalk.js index adc1aed..af43558 100644 --- a/test/chalk.js +++ b/test/chalk.js @@ -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'); +});