UNPKG

691 BTypeScriptView Raw
1export interface Options {
2 /**
3 Match only the first ANSI escape.
4
5 @default false
6 */
7 readonly onlyFirst: boolean;
8}
9
10/**
11Regular expression for matching ANSI escape codes.
12
13@example
14```
15import ansiRegex from 'ansi-regex';
16
17ansiRegex().test('\u001B[4mcake\u001B[0m');
18//=> true
19
20ansiRegex().test('cake');
21//=> false
22
23'\u001B[4mcake\u001B[0m'.match(ansiRegex());
24//=> ['\u001B[4m', '\u001B[0m']
25
26'\u001B[4mcake\u001B[0m'.match(ansiRegex({onlyFirst: true}));
27//=> ['\u001B[4m']
28
29'\u001B]8;;https://github.com\u0007click\u001B]8;;\u0007'.match(ansiRegex());
30//=> ['\u001B]8;;https://github.com\u0007', '\u001B]8;;\u0007']
31```
32*/
33export default function ansiRegex(options?: Options): RegExp;