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 applyStyle._styles.reduce(function (str, name) {
|
||||
var code = ansiStyles[name];
|
||||
var nestedStyles = applyStyle._styles;
|
||||
|
||||
for (var i = 0; i < nestedStyles.length; i++) {
|
||||
var code = ansiStyles[nestedStyles[i]];
|
||||
// Replace any instances already present with a re-opening code
|
||||
// otherwise only the part of the string until said closing code
|
||||
// will be colored, and the rest will simply be 'plain'.
|
||||
return code.open + str.replace(code.closeRe, code.open) + code.close;
|
||||
}, str) ;
|
||||
str = code.open + str.replace(code.closeRe, code.open) + code.close;
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
function init() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue