Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Theme properties return object when mode == 'none' #20

merged 2 commits into from

3 participants



When colors.mode == 'none', properties created by setTheme({error:'red'}) return an object instead of a string.

It looks like all the properties added by applyTheme have this behaviour of exploding strings into objects, but stylize coerces them back to strings if mode is console or browser.

Add tests for return type of .red and .error properties for all three modes.
Modify stylize 'none' case to coerce back to strings.

This is obviously not an ideal fix, but I cannot work out WHY the applyTheme properties explode the strings into objects like that, so I've just brought 'none' into line with console and browser.


I've just encountered this as well. When colors.mode = 'none'; all methods return this passed in as str. Because this is a String instance (object) things break. The str needs to be coerced to a string primitive before it is returned.

Please fix this!


Will push out a new version tonight.


@Marak Marak merged commit e9604a5 into Marak:master
@fouber fouber referenced this pull request from a commit in fouber/colors.js
zhangyunlong fix bug #20 092920e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 12 additions and 2 deletions.
  1. +2 −2 colors.js
  2. +10 −0 test.js
4 colors.js
@@ -96,7 +96,7 @@ function stylize(str, style) {
'yellow' : ['<span style="color:yellow;">', '</span>']
} else if (exports.mode === 'none') {
- return str;
+ return str+'';
} else {
console.log('unsupported mode, try "browser", "console" or "none"');
@@ -301,4 +301,4 @@ function zalgo(text, options) {
// don't summon zalgo
addProperty('zalgo', function () {
return zalgo(this);
10 test.js
@@ -46,6 +46,11 @@ aE(s, 'red', 31);
aE(s, 'yellow', 33);
assert.equal(s, 'string');
colors.mode = 'browser';
assert.equal(s.bold, '<b>' + s + '</b>');
assert.equal(s.italic, '<i>' + s + '</i>');
@@ -57,9 +62,14 @@ stylesColors.forEach(function (color) {
assert.equal(colors[color](s), h(s, color));
colors.mode = 'none';
stylesAll.forEach(function (style) {
assert.equal(s[style], s);
assert.equal(colors[style](s), s);
Something went wrong with that request. Please try again.