UNPKG

chalk-styler

Version:

Terminal string styling done beautifully with ANSI codes, inspired by Chalk.js

20 lines (19 loc) 593 B
export function stringReplaceAll(string, substring, replacer) { return string.split(substring).join(replacer); } export function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index) { let endIndex = 0; let returnValue = ""; do { const gotCR = string[index - 1] === "\r"; returnValue += string.slice(endIndex, gotCR ? index - 1 : index) + prefix + (gotCR ? "\r\n" : "\n") + postfix; endIndex = index + 1; index = string.indexOf("\n", endIndex); } while (index !== -1); returnValue += string.slice(endIndex); return returnValue; }