ansi-regex 4.1.0 → 6.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.
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]+(?:;[-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.1.0",
3
+ "version": "6.0.1",
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,33 +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
-
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
-
20
5
  ## Install
21
6
 
22
7
  ```
23
8
  $ npm install ansi-regex
24
9
  ```
25
10
 
26
-
27
11
  ## Usage
28
12
 
29
13
  ```js
30
- const ansiRegex = require('ansi-regex');
14
+ import ansiRegex from 'ansi-regex';
31
15
 
32
16
  ansiRegex().test('\u001B[4mcake\u001B[0m');
33
17
  //=> true
@@ -45,23 +29,23 @@ ansiRegex().test('cake');
45
29
  //=> ['\u001B]8;;https://github.com\u0007', '\u001B]8;;\u0007']
46
30
  ```
47
31
 
48
-
49
32
  ## API
50
33
 
51
- ### ansiRegex([options])
34
+ ### ansiRegex(options?)
52
35
 
53
36
  Returns a regex for matching ANSI escape codes.
54
37
 
55
38
  #### options
56
39
 
40
+ Type: `object`
41
+
57
42
  ##### onlyFirst
58
43
 
59
- Type: `boolean`<br>
44
+ Type: `boolean`\
60
45
  Default: `false` *(Matches any ANSI escape codes in a string)*
61
46
 
62
47
  Match only the first ANSI escape.
63
48
 
64
-
65
49
  ## FAQ
66
50
 
67
51
  ### Why do you test for codes not in the ECMA 48 standard?
@@ -70,18 +54,19 @@ Some of the codes we run as a test are codes that we acquired finding various li
70
54
 
71
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.
72
56
 
73
-
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
57
  ## Maintainers
80
58
 
81
59
  - [Sindre Sorhus](https://github.com/sindresorhus)
82
60
  - [Josh Junon](https://github.com/qix-)
83
61
 
62
+ ---
84
63
 
85
- ## License
86
-
87
- MIT
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>