Skip to content

Commit

Permalink
Allow multiple arguments in base chalk object (fixes #187)
Browse files Browse the repository at this point in the history
  • Loading branch information
Qix- committed Aug 7, 2017
1 parent 0827d3b commit f0c0178
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 4 additions & 3 deletions index.js
Expand Up @@ -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++) {
Expand Down
4 changes: 4 additions & 0 deletions test/chalk.js
Expand Up @@ -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');
Expand Down

0 comments on commit f0c0178

Please sign in to comment.