don't output escape codes if the input is empty

This commit is contained in:
Sindre Sorhus 2013-12-08 01:07:21 +01:00
parent 879defda72
commit 492d63916c
2 changed files with 5 additions and 1 deletions

View file

@ -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);

View file

@ -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 () {