From 6bb27b7759ace4ccb347a6f1ec8bf4620297aff2 Mon Sep 17 00:00:00 2001 From: Andrew Kennedy Date: Mon, 7 Oct 2013 00:34:32 -0400 Subject: [PATCH 001/338] handle the ability to pass in variable arguments (ex. chalk.green("it's", "over", 9000)). updated readme to show support of variable arguments. --- chalk.js | 4 +++- readme.md | 8 ++++++-- test.js | 8 ++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/chalk.js b/chalk.js index 17c6dba..06def35 100644 --- a/chalk.js +++ b/chalk.js @@ -27,7 +27,9 @@ function init() { Object.keys(styles).forEach(function (name) { ret[name] = { get: function () { - var obj = defineProps(function self(str) { + var obj = defineProps(function self() { + var str = [].slice.call(arguments).join(' '); + if (!chalk.enabled) { return str; } diff --git a/readme.md b/readme.md index d369d2e..32aa4a9 100644 --- a/readme.md +++ b/readme.md @@ -34,13 +34,16 @@ var chalk = require('chalk'); console.log(chalk.blue('Hello world!')); // combine styled and normal strings -console.log(chalk.blue('Hello') + 'World' + chalk.red('!')); +console.log(chalk.blue('Hello'), 'World' + chalk.red('!')); // compose multiple styles using the chainable API console.log(chalk.blue.bgRed.bold('Hello world!')); // nest styles -chalk.red('Hello' + chalk.underline.bgBlue('world') + '!'); +chalk.red('Hello', chalk.underline.bgBlue('world') + '!'); + +// pass in multiple arguments +console.log(chalk.blue('Hello', 'World!', 'Foo', 'bar', 'biz', 'baz')) ``` You can easily define your own themes. @@ -58,6 +61,7 @@ console.log(error('Error!')); Chain [styles](#styles) and call the last one as a method with a string argument. +Multiple arguments are also supported. Chalk will add a space between each one. ### chalk.enabled diff --git a/test.js b/test.js index 93256e3..2241744 100644 --- a/test.js +++ b/test.js @@ -29,6 +29,14 @@ describe('chalk', function () { it('should alias gray to grey', function () { assert.equal(chalk.grey('foo'), '\x1b[90mfoo\x1b[39m'); }); + + it('should support variable number of arguments', function () { + assert.equal(chalk.red('foo', 'bar'), '\x1b[31mfoo bar\x1b[39m'); + }); + + it('should support falsy values', function () { + assert.equal(chalk.red(0), '\x1b[31m0\x1b[39m'); + }); }); describe('chalk.enabled', function () { From 50da33ff12f6d70f17aa1fdfb17b897d2a8b3127 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sat, 12 Oct 2013 19:18:24 +0200 Subject: [PATCH 002/338] stripColor() - gracefully handle non-string input --- chalk.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chalk.js b/chalk.js index 17c6dba..9e508d0 100644 --- a/chalk.js +++ b/chalk.js @@ -51,7 +51,7 @@ function init() { chalk.styles = ansi; chalk.stripColor = function (str) { - return str.replace(/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]/g, ''); + return typeof str === 'string' ? str.replace(/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]/g, '') : str; }; chalk.supportsColor = require('has-color'); From b0a0e42bfe96f77e0ce273c87b910ccc9280bbeb Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sat, 19 Oct 2013 17:58:04 +0200 Subject: [PATCH 003/338] 0.3.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 473151f..4b36db7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "chalk", - "version": "0.2.1", + "version": "0.3.0", "description": "Terminal string styling done right", "keywords": [ "color", From 15f928fce589ba47c8770d7b8e249f86fb786c4a Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sat, 19 Oct 2013 18:04:30 +0200 Subject: [PATCH 004/338] Update readme --- readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index 32aa4a9..874026a 100644 --- a/readme.md +++ b/readme.md @@ -57,7 +57,7 @@ console.log(error('Error!')); ## API -### chalk.\