Skip to content

Commit f487e8e

Browse files
committed
Fix #244 and #248
1 parent 2631877 commit f487e8e

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
/tests/
33
/.travis.yml
44
/screenshots
5+
*.sw*

lib/extendStringPrototype.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,22 @@ module['exports'] = function() {
7373
} else {
7474
if (typeof(theme[prop]) === 'string') {
7575
colors[prop] = colors[theme[prop]];
76+
addProperty(prop, function() {
77+
return colors[prop](this);
78+
});
7679
} else {
77-
var tmp = colors[theme[prop][0]];
78-
for (var t = 1; t < theme[prop].length; t++) {
79-
tmp = tmp[theme[prop][t]];
80-
}
81-
colors[prop] = tmp;
80+
var themePropApplicator = function(str) {
81+
var ret = str || this;
82+
for (var t = 0; t < theme[prop].length; t++) {
83+
ret = colors[theme[prop][t]](ret);
84+
}
85+
return ret;
86+
};
87+
addProperty(prop, themePropApplicator);
88+
colors[prop] = function(str){
89+
return themePropApplicator(str);
90+
};
8291
}
83-
addProperty(prop, function() {
84-
return colors[prop](this);
85-
});
8692
}
8793
});
8894
}

tests/basic-test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ assert.equal(s, 'string');
6464

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

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

0 commit comments

Comments
 (0)