Fix support for nested styles (#335)

This commit is contained in:
Ahad Birang 2019-07-12 23:19:56 +04:30 committed by Sindre Sorhus
parent c25c32a25f
commit 87156ce8e2
2 changed files with 2 additions and 2 deletions

View file

@ -10,7 +10,7 @@ const stringReplaceAll = (string, substring, replacer) => {
let endIndex = 0; let endIndex = 0;
let returnValue = ''; let returnValue = '';
do { do {
returnValue += string.substr(endIndex, index - endIndex) + replacer; returnValue += string.substr(endIndex, index - endIndex) + substring + replacer;
endIndex = index + substringLength; endIndex = index + substringLength;
index = string.indexOf(substring, endIndex); index = string.indexOf(substring, endIndex);
} while (index !== -1); } while (index !== -1);

View file

@ -37,7 +37,7 @@ test('support nesting styles', t => {
test('support nesting styles of the same type (color, underline, bg)', t => { test('support nesting styles of the same type (color, underline, bg)', t => {
t.is( t.is(
chalk.red('a' + chalk.yellow('b' + chalk.green('c') + 'b') + 'c'), chalk.red('a' + chalk.yellow('b' + chalk.green('c') + 'b') + 'c'),
'\u001B[31ma\u001B[33mb\u001B[32mc\u001B[33mb\u001B[31mc\u001B[39m' '\u001B[31ma\u001B[33mb\u001B[32mc\u001B[39m\u001B[31m\u001B[33mb\u001B[39m\u001B[31mc\u001B[39m'
); );
}); });