1 | export const indentString = (
|
2 | str: string,
|
3 | count = 1,
|
4 | {
|
5 | indent = ' ',
|
6 | includeEmptyLines = false,
|
7 | }: {
|
8 | readonly indent?: string;
|
9 | readonly includeEmptyLines?: boolean;
|
10 | } = { indent: ' ', includeEmptyLines: false },
|
11 | ) => {
|
12 | if (count === 0) {
|
13 | return str;
|
14 | }
|
15 |
|
16 | const regex = includeEmptyLines ? /^/gm : /^(?!\s*$)/gm;
|
17 |
|
18 | return str.replace(regex, indent.repeat(count));
|
19 | };
|
20 |
|
21 | const ansiRegex = new RegExp(
|
22 | [
|
23 | '[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?\\u0007)',
|
24 | '(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))',
|
25 | ].join('|'),
|
26 | 'g',
|
27 | );
|
28 |
|
29 | export const stripAnsi = (input: string) => input.replace(ansiRegex, '');
|