ansi-regex 4.0.0 → 6.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.

Potentially problematic release.


This version of ansi-regex might be problematic. Click here for more details.

package/index.d.ts ADDED
@@ -0,0 +1,33 @@
1
+ export interface Options {
2
+ /**
3
+ Match only the first ANSI escape.
4
+
5
+ @default false
6
+ */
7
+ readonly onlyFirst: boolean;
8
+ }
9
+
10
+ /**
11
+ Regular expression for matching ANSI escape codes.
12
+
13
+ @example
14
+ ```
15
+ import ansiRegex from 'ansi-regex';
16
+
17
+ ansiRegex().test('\u001B[4mcake\u001B[0m');
18
+ //=> true
19
+
20
+ ansiRegex().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
+ */
33
+ export default function ansiRegex(options?: Options): RegExp;
package/index.js CHANGED
@@ -1,14 +1,8 @@
1
- 'use strict';
2
-
3
- module.exports = options => {
4
- options = Object.assign({
5
- onlyFirst: false
6
- }, options);
7
-
1
+ export default function ansiRegex({onlyFirst = false} = {}) {
8
2
  const pattern = [
9
- '[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?\\u0007)',
3
+ '[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)',
10
4
  '(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))'
11
5
  ].join('|');
12
6
 
13
- return new RegExp(pattern, options.onlyFirst ? undefined : 'g');
14
- };
7
+ return new RegExp(pattern, onlyFirst ? undefined : 'g');
8
+ }
package/license CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
3
+ Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
4
4
 
5
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:
6
6
 
package/package.json CHANGED
@@ -1,23 +1,27 @@
1
1
  {
2
2
  "name": "ansi-regex",
3
- "version": "4.0.0",
3
+ "version": "6.0.0",
4
4
  "description": "Regular expression for matching ANSI escape codes",
5
5
  "license": "MIT",
6
6
  "repository": "chalk/ansi-regex",
7
+ "funding": "https://github.com/chalk/ansi-regex?sponsor=1",
7
8
  "author": {
8
9
  "name": "Sindre Sorhus",
9
10
  "email": "sindresorhus@gmail.com",
10
- "url": "sindresorhus.com"
11
+ "url": "https://sindresorhus.com"
11
12
  },
13
+ "type": "module",
14
+ "exports": "./index.js",
12
15
  "engines": {
13
- "node": ">=6"
16
+ "node": ">=12"
14
17
  },
15
18
  "scripts": {
16
- "test": "xo && ava",
19
+ "test": "xo && ava && tsd",
17
20
  "view-supported": "node fixtures/view-codes.js"
18
21
  },
19
22
  "files": [
20
- "index.js"
23
+ "index.js",
24
+ "index.d.ts"
21
25
  ],
22
26
  "keywords": [
23
27
  "ansi",
@@ -47,7 +51,8 @@
47
51
  "pattern"
48
52
  ],
49
53
  "devDependencies": {
50
- "ava": "^0.25.0",
51
- "xo": "^0.23.0"
54
+ "ava": "^3.15.0",
55
+ "tsd": "^0.14.0",
56
+ "xo": "^0.38.2"
52
57
  }
53
58
  }
package/readme.md CHANGED
@@ -1,19 +1,17 @@
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
 
5
-
6
5
  ## Install
7
6
 
8
7
  ```
9
8
  $ npm install ansi-regex
10
9
  ```
11
10
 
12
-
13
11
  ## Usage
14
12
 
15
13
  ```js
16
- const ansiRegex = require('ansi-regex');
14
+ import ansiRegex from 'ansi-regex';
17
15
 
18
16
  ansiRegex().test('\u001B[4mcake\u001B[0m');
19
17
  //=> true
@@ -26,25 +24,28 @@ ansiRegex().test('cake');
26
24
 
27
25
  '\u001B[4mcake\u001B[0m'.match(ansiRegex({onlyFirst: true}));
28
26
  //=> ['\u001B[4m']
29
- ```
30
27
 
28
+ '\u001B]8;;https://github.com\u0007click\u001B]8;;\u0007'.match(ansiRegex());
29
+ //=> ['\u001B]8;;https://github.com\u0007', '\u001B]8;;\u0007']
30
+ ```
31
31
 
32
32
  ## API
33
33
 
34
- ### ansiRegex([options])
34
+ ### ansiRegex(options?)
35
35
 
36
36
  Returns a regex for matching ANSI escape codes.
37
37
 
38
38
  #### options
39
39
 
40
+ Type: `object`
41
+
40
42
  ##### onlyFirst
41
43
 
42
- Type: `boolean`<br>
44
+ Type: `boolean`\
43
45
  Default: `false` *(Matches any ANSI escape codes in a string)*
44
46
 
45
47
  Match only the first ANSI escape.
46
48
 
47
-
48
49
  ## FAQ
49
50
 
50
51
  ### Why do you test for codes not in the ECMA 48 standard?
@@ -53,13 +54,19 @@ Some of the codes we run as a test are codes that we acquired finding various li
53
54
 
54
55
  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.
55
56
 
56
-
57
57
  ## Maintainers
58
58
 
59
59
  - [Sindre Sorhus](https://github.com/sindresorhus)
60
60
  - [Josh Junon](https://github.com/qix-)
61
61
 
62
-
63
- ## License
64
-
65
- MIT
62
+ ---
63
+
64
+ <div align="center">
65
+ <b>
66
+ <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>
67
+ </b>
68
+ <br>
69
+ <sub>
70
+ Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
71
+ </sub>
72
+ </div>