Merge pull request #28 from jbnicolai/fast-js
Replaces Array.prototype.reduce with an explicit loop for performance.
This commit is contained in:
commit
23eab5cdf4
1 changed files with 8 additions and 4 deletions
12
index.js
12
index.js
|
|
@ -34,13 +34,17 @@ function applyStyle() {
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
return applyStyle._styles.reduce(function (str, name) {
|
var nestedStyles = applyStyle._styles;
|
||||||
var code = ansiStyles[name];
|
|
||||||
|
for (var i = 0; i < nestedStyles.length; i++) {
|
||||||
|
var code = ansiStyles[nestedStyles[i]];
|
||||||
// Replace any instances already present with a re-opening code
|
// Replace any instances already present with a re-opening code
|
||||||
// otherwise only the part of the string until said closing code
|
// otherwise only the part of the string until said closing code
|
||||||
// will be colored, and the rest will simply be 'plain'.
|
// will be colored, and the rest will simply be 'plain'.
|
||||||
return code.open + str.replace(code.closeRe, code.open) + code.close;
|
str = code.open + str.replace(code.closeRe, code.open) + code.close;
|
||||||
}, str) ;
|
}
|
||||||
|
|
||||||
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue