ansi-regex 2.1.1 → 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 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,4 +1,10 @@
1
1
  'use strict';
2
- module.exports = function () {
3
- return /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-PRZcf-nqry=><]/g;
2
+
3
+ module.exports = ({onlyFirst = false} = {}) => {
4
+ const pattern = [
5
+ '[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)',
6
+ '(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))'
7
+ ].join('|');
8
+
9
+ return new RegExp(pattern, onlyFirst ? undefined : 'g');
4
10
  };
package/license CHANGED
@@ -1,21 +1,9 @@
1
- The MIT License (MIT)
1
+ MIT License
2
2
 
3
3
  Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
4
4
 
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
11
6
 
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
14
8
 
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/package.json CHANGED
@@ -1,64 +1,55 @@
1
1
  {
2
- "name": "ansi-regex",
3
- "version": "2.1.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
- "maintainers": [
13
- "Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)",
14
- "Joshua Appelman <jappelman@xebia.com> (jbnicolai.com)",
15
- "JD Ballard <i.am.qix@gmail.com> (github.com/qix-)"
16
- ],
17
- "engines": {
18
- "node": ">=0.10.0"
19
- },
20
- "scripts": {
21
- "test": "xo && ava --verbose",
22
- "view-supported": "node fixtures/view-codes.js"
23
- },
24
- "files": [
25
- "index.js"
26
- ],
27
- "keywords": [
28
- "ansi",
29
- "styles",
30
- "color",
31
- "colour",
32
- "colors",
33
- "terminal",
34
- "console",
35
- "cli",
36
- "string",
37
- "tty",
38
- "escape",
39
- "formatting",
40
- "rgb",
41
- "256",
42
- "shell",
43
- "xterm",
44
- "command-line",
45
- "text",
46
- "regex",
47
- "regexp",
48
- "re",
49
- "match",
50
- "test",
51
- "find",
52
- "pattern"
53
- ],
54
- "devDependencies": {
55
- "ava": "0.17.0",
56
- "xo": "0.16.0"
57
- },
58
- "xo": {
59
- "rules": {
60
- "guard-for-in": 0,
61
- "no-loop-func": 0
62
- }
63
- }
2
+ "name": "ansi-regex",
3
+ "version": "5.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": ">=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
+ }
64
55
  }
package/readme.md CHANGED
@@ -1,12 +1,12 @@
1
1
  # ansi-regex [![Build Status](https://travis-ci.org/chalk/ansi-regex.svg?branch=master)](https://travis-ci.org/chalk/ansi-regex)
2
2
 
3
- > Regular expression for matching [ANSI escape codes](http://en.wikipedia.org/wiki/ANSI_escape_code)
3
+ > Regular expression for matching [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code)
4
4
 
5
5
 
6
6
  ## Install
7
7
 
8
8
  ```
9
- $ npm install --save ansi-regex
9
+ $ npm install ansi-regex
10
10
  ```
11
11
 
12
12
 
@@ -15,25 +15,64 @@ $ npm install --save ansi-regex
15
15
  ```js
16
16
  const ansiRegex = require('ansi-regex');
17
17
 
18
- ansiRegex().test('\u001b[4mcake\u001b[0m');
18
+ ansiRegex().test('\u001B[4mcake\u001B[0m');
19
19
  //=> true
20
20
 
21
21
  ansiRegex().test('cake');
22
22
  //=> false
23
23
 
24
- '\u001b[4mcake\u001b[0m'.match(ansiRegex());
25
- //=> ['\u001b[4m', '\u001b[0m']
24
+ '\u001B[4mcake\u001B[0m'.match(ansiRegex());
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
 
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
+
28
53
  ## FAQ
29
54
 
30
55
  ### Why do you test for codes not in the ECMA 48 standard?
31
56
 
32
- Some of the codes we run as a test are codes that we acquired finding various lists of non-standard or manufacturer specific codes. If I recall correctly, we test for both standard and non-standard codes, as most of them follow the same or similar format and can be safely matched in strings without the risk of removing actual string content. There are a few non-standard control codes that do not follow the traditional format (i.e. they end in numbers) thus forcing us to exclude them from the test because we cannot reliably match them.
57
+ Some of the codes we run as a test are codes that we acquired finding various lists of non-standard or manufacturer specific codes. We test for both standard and non-standard codes, as most of them follow the same or similar format and can be safely matched in strings without the risk of removing actual string content. There are a few non-standard control codes that do not follow the traditional format (i.e. they end in numbers) thus forcing us to exclude them from the test because we cannot reliably match them.
33
58
 
34
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.
35
60
 
36
61
 
37
- ## License
62
+ ## Maintainers
63
+
64
+ - [Sindre Sorhus](https://github.com/sindresorhus)
65
+ - [Josh Junon](https://github.com/qix-)
66
+
67
+
68
+ ---
38
69
 
39
- MIT © [Sindre Sorhus](http://sindresorhus.com)
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>