ansi-regex 3.0.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +7 -3
- package/package.json +51 -51
- package/readme.md +19 -0
package/index.js
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
module.exports =
|
|
3
|
+
module.exports = options => {
|
|
4
|
+
options = Object.assign({
|
|
5
|
+
onlyFirst: false
|
|
6
|
+
}, options);
|
|
7
|
+
|
|
4
8
|
const pattern = [
|
|
5
9
|
'[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?\\u0007)',
|
|
6
|
-
'(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-
|
|
10
|
+
'(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))'
|
|
7
11
|
].join('|');
|
|
8
12
|
|
|
9
|
-
return new RegExp(pattern, 'g');
|
|
13
|
+
return new RegExp(pattern, options.onlyFirst ? undefined : 'g');
|
|
10
14
|
};
|
package/package.json
CHANGED
|
@@ -1,53 +1,53 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
2
|
+
"name": "ansi-regex",
|
|
3
|
+
"version": "4.0.0",
|
|
4
|
+
"description": "Regular expression for matching ANSI escape codes",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": "chalk/ansi-regex",
|
|
7
|
+
"author": {
|
|
8
|
+
"name": "Sindre Sorhus",
|
|
9
|
+
"email": "sindresorhus@gmail.com",
|
|
10
|
+
"url": "sindresorhus.com"
|
|
11
|
+
},
|
|
12
|
+
"engines": {
|
|
13
|
+
"node": ">=6"
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"test": "xo && ava",
|
|
17
|
+
"view-supported": "node fixtures/view-codes.js"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"index.js"
|
|
21
|
+
],
|
|
22
|
+
"keywords": [
|
|
23
|
+
"ansi",
|
|
24
|
+
"styles",
|
|
25
|
+
"color",
|
|
26
|
+
"colour",
|
|
27
|
+
"colors",
|
|
28
|
+
"terminal",
|
|
29
|
+
"console",
|
|
30
|
+
"cli",
|
|
31
|
+
"string",
|
|
32
|
+
"tty",
|
|
33
|
+
"escape",
|
|
34
|
+
"formatting",
|
|
35
|
+
"rgb",
|
|
36
|
+
"256",
|
|
37
|
+
"shell",
|
|
38
|
+
"xterm",
|
|
39
|
+
"command-line",
|
|
40
|
+
"text",
|
|
41
|
+
"regex",
|
|
42
|
+
"regexp",
|
|
43
|
+
"re",
|
|
44
|
+
"match",
|
|
45
|
+
"test",
|
|
46
|
+
"find",
|
|
47
|
+
"pattern"
|
|
48
|
+
],
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"ava": "^0.25.0",
|
|
51
|
+
"xo": "^0.23.0"
|
|
52
|
+
}
|
|
53
53
|
}
|
package/readme.md
CHANGED
|
@@ -23,9 +23,28 @@ ansiRegex().test('cake');
|
|
|
23
23
|
|
|
24
24
|
'\u001B[4mcake\u001B[0m'.match(ansiRegex());
|
|
25
25
|
//=> ['\u001B[4m', '\u001B[0m']
|
|
26
|
+
|
|
27
|
+
'\u001B[4mcake\u001B[0m'.match(ansiRegex({onlyFirst: true}));
|
|
28
|
+
//=> ['\u001B[4m']
|
|
26
29
|
```
|
|
27
30
|
|
|
28
31
|
|
|
32
|
+
## API
|
|
33
|
+
|
|
34
|
+
### ansiRegex([options])
|
|
35
|
+
|
|
36
|
+
Returns a regex for matching ANSI escape codes.
|
|
37
|
+
|
|
38
|
+
#### options
|
|
39
|
+
|
|
40
|
+
##### onlyFirst
|
|
41
|
+
|
|
42
|
+
Type: `boolean`<br>
|
|
43
|
+
Default: `false` *(Matches any ANSI escape codes in a string)*
|
|
44
|
+
|
|
45
|
+
Match only the first ANSI escape.
|
|
46
|
+
|
|
47
|
+
|
|
29
48
|
## FAQ
|
|
30
49
|
|
|
31
50
|
### Why do you test for codes not in the ECMA 48 standard?
|