From 492d63916c2f886335c6557e6305444828e38470 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sun, 8 Dec 2013 01:07:21 +0100 Subject: [PATCH] don't output escape codes if the input is empty --- chalk.js | 2 +- test.js | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/chalk.js b/chalk.js index c2b9428..50ad65f 100644 --- a/chalk.js +++ b/chalk.js @@ -38,7 +38,7 @@ function init() { return self._styles.reduce(function (str, name) { var code = ansi[name]; - return code.open + (str || '') + code.close; + return str ? code.open + str + code.close : ''; }, str); }, styles); diff --git a/test.js b/test.js index b27323f..53b62f2 100644 --- a/test.js +++ b/test.js @@ -37,6 +37,10 @@ describe('chalk', function () { it('should support falsy values', function () { assert.equal(chalk.red(0), '\x1b[31m0\x1b[39m'); }); + + it('don\'t output escape codes if the input is empty', function () { + assert.equal(chalk.red(), ''); + }); }); describe('chalk.enabled', function () {