ansi-regex 4.1.0 → 5.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.d.ts +37 -0
- package/index.js +2 -6
- package/package.json +8 -6
- package/readme.md +13 -22
package/index.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
declare namespace ansiRegex {
|
|
2
|
+
interface Options {
|
|
3
|
+
/**
|
|
4
|
+
Match only the first ANSI escape.
|
|
5
|
+
|
|
6
|
+
@default false
|
|
7
|
+
*/
|
|
8
|
+
onlyFirst: boolean;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
Regular expression for matching ANSI escape codes.
|
|
14
|
+
|
|
15
|
+
@example
|
|
16
|
+
```
|
|
17
|
+
import ansiRegex = require('ansi-regex');
|
|
18
|
+
|
|
19
|
+
ansiRegex().test('\u001B[4mcake\u001B[0m');
|
|
20
|
+
//=> true
|
|
21
|
+
|
|
22
|
+
ansiRegex().test('cake');
|
|
23
|
+
//=> false
|
|
24
|
+
|
|
25
|
+
'\u001B[4mcake\u001B[0m'.match(ansiRegex());
|
|
26
|
+
//=> ['\u001B[4m', '\u001B[0m']
|
|
27
|
+
|
|
28
|
+
'\u001B[4mcake\u001B[0m'.match(ansiRegex({onlyFirst: true}));
|
|
29
|
+
//=> ['\u001B[4m']
|
|
30
|
+
|
|
31
|
+
'\u001B]8;;https://github.com\u0007click\u001B]8;;\u0007'.match(ansiRegex());
|
|
32
|
+
//=> ['\u001B]8;;https://github.com\u0007', '\u001B]8;;\u0007']
|
|
33
|
+
```
|
|
34
|
+
*/
|
|
35
|
+
declare function ansiRegex(options?: ansiRegex.Options): RegExp;
|
|
36
|
+
|
|
37
|
+
export = ansiRegex;
|
package/index.js
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
module.exports =
|
|
4
|
-
options = Object.assign({
|
|
5
|
-
onlyFirst: false
|
|
6
|
-
}, options);
|
|
7
|
-
|
|
3
|
+
module.exports = ({onlyFirst = false} = {}) => {
|
|
8
4
|
const pattern = [
|
|
9
5
|
'[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)',
|
|
10
6
|
'(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))'
|
|
11
7
|
].join('|');
|
|
12
8
|
|
|
13
|
-
return new RegExp(pattern,
|
|
9
|
+
return new RegExp(pattern, onlyFirst ? undefined : 'g');
|
|
14
10
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ansi-regex",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "Regular expression for matching ANSI escape codes",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "chalk/ansi-regex",
|
|
@@ -10,14 +10,15 @@
|
|
|
10
10
|
"url": "sindresorhus.com"
|
|
11
11
|
},
|
|
12
12
|
"engines": {
|
|
13
|
-
"node": ">=
|
|
13
|
+
"node": ">=8"
|
|
14
14
|
},
|
|
15
15
|
"scripts": {
|
|
16
|
-
"test": "xo && ava",
|
|
16
|
+
"test": "xo && ava && tsd",
|
|
17
17
|
"view-supported": "node fixtures/view-codes.js"
|
|
18
18
|
},
|
|
19
19
|
"files": [
|
|
20
|
-
"index.js"
|
|
20
|
+
"index.js",
|
|
21
|
+
"index.d.ts"
|
|
21
22
|
],
|
|
22
23
|
"keywords": [
|
|
23
24
|
"ansi",
|
|
@@ -47,7 +48,8 @@
|
|
|
47
48
|
"pattern"
|
|
48
49
|
],
|
|
49
50
|
"devDependencies": {
|
|
50
|
-
"ava": "^
|
|
51
|
-
"
|
|
51
|
+
"ava": "^2.4.0",
|
|
52
|
+
"tsd": "^0.9.0",
|
|
53
|
+
"xo": "^0.25.3"
|
|
52
54
|
}
|
|
53
55
|
}
|
package/readme.md
CHANGED
|
@@ -2,20 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
> Regular expression for matching [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code)
|
|
4
4
|
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
<div align="center">
|
|
8
|
-
<b>
|
|
9
|
-
<a href="https://tidelift.com/subscription/pkg/npm-ansi-regex?utm_source=npm-ansi-regex&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
|
|
10
|
-
</b>
|
|
11
|
-
<br>
|
|
12
|
-
<sub>
|
|
13
|
-
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
|
|
14
|
-
</sub>
|
|
15
|
-
</div>
|
|
16
|
-
|
|
17
|
-
---
|
|
18
|
-
|
|
19
5
|
|
|
20
6
|
## Install
|
|
21
7
|
|
|
@@ -48,12 +34,14 @@ ansiRegex().test('cake');
|
|
|
48
34
|
|
|
49
35
|
## API
|
|
50
36
|
|
|
51
|
-
### ansiRegex(
|
|
37
|
+
### ansiRegex(options?)
|
|
52
38
|
|
|
53
39
|
Returns a regex for matching ANSI escape codes.
|
|
54
40
|
|
|
55
41
|
#### options
|
|
56
42
|
|
|
43
|
+
Type: `object`
|
|
44
|
+
|
|
57
45
|
##### onlyFirst
|
|
58
46
|
|
|
59
47
|
Type: `boolean`<br>
|
|
@@ -71,17 +59,20 @@ Some of the codes we run as a test are codes that we acquired finding various li
|
|
|
71
59
|
On the historical side, those ECMA standards were established in the early 90's whereas the VT100, for example, was designed in the mid/late 70's. At that point in time, control codes were still pretty ungoverned and engineers used them for a multitude of things, namely to activate hardware ports that may have been proprietary. Somewhere else you see a similar 'anarchy' of codes is in the x86 architecture for processors; there are a ton of "interrupts" that can mean different things on certain brands of processors, most of which have been phased out.
|
|
72
60
|
|
|
73
61
|
|
|
74
|
-
## Security
|
|
75
|
-
|
|
76
|
-
To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure.
|
|
77
|
-
|
|
78
|
-
|
|
79
62
|
## Maintainers
|
|
80
63
|
|
|
81
64
|
- [Sindre Sorhus](https://github.com/sindresorhus)
|
|
82
65
|
- [Josh Junon](https://github.com/qix-)
|
|
83
66
|
|
|
84
67
|
|
|
85
|
-
|
|
68
|
+
---
|
|
86
69
|
|
|
87
|
-
|
|
70
|
+
<div align="center">
|
|
71
|
+
<b>
|
|
72
|
+
<a href="https://tidelift.com/subscription/pkg/npm-ansi-regex?utm_source=npm-ansi-regex&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
|
|
73
|
+
</b>
|
|
74
|
+
<br>
|
|
75
|
+
<sub>
|
|
76
|
+
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
|
|
77
|
+
</sub>
|
|
78
|
+
</div>
|