From 0fba91b0373c86800c45096ad215d38481f49614 Mon Sep 17 00:00:00 2001 From: Richie Bendall Date: Tue, 20 Apr 2021 18:48:30 +1200 Subject: [PATCH] Keep function prototype methods (#434) --- source/index.js | 2 ++ test/chalk.js | 6 ++++++ 2 files changed, 8 insertions(+) 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'); +});