From f0c0178d12c4e0b2b3a3e92afb15dbabb2882b9b Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Sun, 30 Jul 2017 22:28:44 -0700 Subject: [PATCH] Allow multiple arguments in base chalk object (fixes #187) --- index.js | 7 ++++--- test/chalk.js | 4 ++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 94c1ae5..ab3831c 100644 --- a/index.js +++ b/index.js @@ -197,12 +197,13 @@ function applyStyle() { } function chalkTag(chalk, strings) { - const args = [].slice.call(arguments, 2); - if (!Array.isArray(strings)) { - return strings.toString(); + // If chalk() was called by itself or with a string, + // return the string itself as a string. + return [].slice.call(arguments, 1).join(' '); } + const args = [].slice.call(arguments, 2); const parts = [strings.raw[0]]; for (let i = 1; i < strings.length; i++) { diff --git a/test/chalk.js b/test/chalk.js index 46060d4..8480dad 100644 --- a/test/chalk.js +++ b/test/chalk.js @@ -12,6 +12,10 @@ test('don\'t add any styling when called as the base function', t => { t.is(m('foo'), 'foo'); }); +test('support multiple arguments in base function', t => { + t.is(m('hello', 'there'), 'hello there'); +}); + test('style string', t => { t.is(m.underline('foo'), '\u001B[4mfoo\u001B[24m'); t.is(m.red('foo'), '\u001B[31mfoo\u001B[39m');