ansi-regex 3.0.0 → 5.0.1

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.
Files changed (4) hide show
  1. package/index.d.ts +37 -0
  2. package/index.js +4 -4
  3. package/package.json +53 -51
  4. package/readme.md +35 -3
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,10 +1,10 @@
1
1
  'use strict';
2
2
 
3
- module.exports = () => {
3
+ module.exports = ({onlyFirst = false} = {}) => {
4
4
  const pattern = [
5
- '[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?\\u0007)',
6
- '(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))'
5
+ '[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)',
6
+ '(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))'
7
7
  ].join('|');
8
8
 
9
- return new RegExp(pattern, 'g');
9
+ return new RegExp(pattern, onlyFirst ? undefined : 'g');
10
10
  };
package/package.json CHANGED
@@ -1,53 +1,55 @@
1
1
  {
2
- "name": "ansi-regex",
3
- "version": "3.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": ">=4"
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": "*",
51
- "xo": "*"
52
- }
2
+ "name": "ansi-regex",
3
+ "version": "5.0.1",
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": ">=8"
14
+ },
15
+ "scripts": {
16
+ "test": "xo && ava && tsd",
17
+ "view-supported": "node fixtures/view-codes.js"
18
+ },
19
+ "files": [
20
+ "index.js",
21
+ "index.d.ts"
22
+ ],
23
+ "keywords": [
24
+ "ansi",
25
+ "styles",
26
+ "color",
27
+ "colour",
28
+ "colors",
29
+ "terminal",
30
+ "console",
31
+ "cli",
32
+ "string",
33
+ "tty",
34
+ "escape",
35
+ "formatting",
36
+ "rgb",
37
+ "256",
38
+ "shell",
39
+ "xterm",
40
+ "command-line",
41
+ "text",
42
+ "regex",
43
+ "regexp",
44
+ "re",
45
+ "match",
46
+ "test",
47
+ "find",
48
+ "pattern"
49
+ ],
50
+ "devDependencies": {
51
+ "ava": "^2.4.0",
52
+ "tsd": "^0.9.0",
53
+ "xo": "^0.25.3"
54
+ }
53
55
  }
package/readme.md CHANGED
@@ -1,4 +1,4 @@
1
- # ansi-regex [![Build Status](https://travis-ci.org/chalk/ansi-regex.svg?branch=master)](https://travis-ci.org/chalk/ansi-regex)
1
+ # ansi-regex
2
2
 
3
3
  > Regular expression for matching [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code)
4
4
 
@@ -23,9 +23,33 @@ 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']
29
+
30
+ '\u001B]8;;https://github.com\u0007click\u001B]8;;\u0007'.match(ansiRegex());
31
+ //=> ['\u001B]8;;https://github.com\u0007', '\u001B]8;;\u0007']
26
32
  ```
27
33
 
28
34
 
35
+ ## API
36
+
37
+ ### ansiRegex(options?)
38
+
39
+ Returns a regex for matching ANSI escape codes.
40
+
41
+ #### options
42
+
43
+ Type: `object`
44
+
45
+ ##### onlyFirst
46
+
47
+ Type: `boolean`<br>
48
+ Default: `false` *(Matches any ANSI escape codes in a string)*
49
+
50
+ Match only the first ANSI escape.
51
+
52
+
29
53
  ## FAQ
30
54
 
31
55
  ### Why do you test for codes not in the ECMA 48 standard?
@@ -41,6 +65,14 @@ On the historical side, those ECMA standards were established in the early 90's
41
65
  - [Josh Junon](https://github.com/qix-)
42
66
 
43
67
 
44
- ## License
68
+ ---
45
69
 
46
- MIT
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>