Skip to content

Commit

Permalink
Fix #244 and #248
Browse files Browse the repository at this point in the history
  • Loading branch information
DABH committed Dec 10, 2018
1 parent 2631877 commit f487e8e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
/tests/
/.travis.yml
/screenshots
*.sw*
22 changes: 14 additions & 8 deletions lib/extendStringPrototype.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,22 @@ module['exports'] = function() {
} else {
if (typeof(theme[prop]) === 'string') {
colors[prop] = colors[theme[prop]];
addProperty(prop, function() {
return colors[prop](this);
});
} else {
var tmp = colors[theme[prop][0]];
for (var t = 1; t < theme[prop].length; t++) {
tmp = tmp[theme[prop][t]];
}
colors[prop] = tmp;
var themePropApplicator = function(str) {
var ret = str || this;
for (var t = 0; t < theme[prop].length; t++) {
ret = colors[theme[prop][t]](ret);
}
return ret;
};
addProperty(prop, themePropApplicator);
colors[prop] = function(str){
return themePropApplicator(str);
};
}
addProperty(prop, function() {
return colors[prop](this);
});
}
});
}
Expand Down
8 changes: 4 additions & 4 deletions tests/basic-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ assert.equal(s, 'string');

colors.setTheme({custom: ['blue', 'bold', 'underline']});
assert.equal(colors.custom(s),
'\x1b[34m' + '\x1b[1m' + '\x1b[4m' + s +
'\x1b[24m' + '\x1b[22m' + '\x1b[39m' );
'\x1b[4m' + '\x1b[1m' + '\x1b[34m' + s +
'\x1b[39m' + '\x1b[22m' + '\x1b[24m' );

colors.setTheme({custom: ['red', 'italic', 'inverse']});
assert.equal(colors.custom(s),
'\x1b[31m' + '\x1b[3m' + '\x1b[7m' + s +
'\x1b[27m' + '\x1b[23m' + '\x1b[39m' );
'\x1b[7m' + '\x1b[3m' + '\x1b[31m' + s +
'\x1b[39m' + '\x1b[23m' + '\x1b[27m' );

0 comments on commit f487e8e

Please sign in to comment.