@common.js/super-regex 0.2.0 → 0.2.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/package.json +14 -5
- package/readme.md +0 -81
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@common.js/super-regex",
|
|
3
|
-
"version": "0.2.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"description": "super-regex package exported as CommonJS modules",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "etienne-martin/common.js",
|
|
7
7
|
"funding": "https://github.com/sponsors/sindresorhus",
|
|
8
8
|
"type": "commonjs",
|
|
9
|
+
"exports": "./index.js",
|
|
9
10
|
"types": "./index.d.ts",
|
|
10
11
|
"engines": {
|
|
11
12
|
"node": ">=14.16"
|
|
@@ -18,9 +19,9 @@
|
|
|
18
19
|
"index.d.ts"
|
|
19
20
|
],
|
|
20
21
|
"dependencies": {
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
22
|
+
"clone-regexp": "npm:@common.js/clone-regexp@3.0.1",
|
|
23
|
+
"function-timeout": "npm:@common.js/function-timeout@0.1.2",
|
|
24
|
+
"time-span": "npm:@common.js/time-span@5.1.1"
|
|
24
25
|
},
|
|
25
26
|
"devDependencies": {
|
|
26
27
|
"ava": "^4.3.0",
|
|
@@ -28,5 +29,13 @@
|
|
|
28
29
|
"xo": "^0.49.0"
|
|
29
30
|
},
|
|
30
31
|
"homepage": "https://github.com/etienne-martin/common.js#readme",
|
|
32
|
+
"commonjs": {
|
|
33
|
+
"source": {
|
|
34
|
+
"name": "super-regex",
|
|
35
|
+
"version": "0.2.0"
|
|
36
|
+
},
|
|
37
|
+
"transformRevision": 1,
|
|
38
|
+
"buildKey": "471c5128fe86649250fda114ed71a11c6ce9ebf2e9f2c29f423792acfd01b58c"
|
|
39
|
+
},
|
|
31
40
|
"main": "./index.js"
|
|
32
41
|
}
|
package/readme.md
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
# super-regex
|
|
2
|
-
|
|
3
|
-
> Make a regular expression time out if it takes too long to execute
|
|
4
|
-
|
|
5
|
-
This can be used to prevent [ReDoS vulnerabilities](https://en.wikipedia.org/wiki/ReDoS) when running a regular expression against untrusted user input.
|
|
6
|
-
|
|
7
|
-
This package also has a better API than the built-in regular expression methods. For example, none of the methods mutate the regex.
|
|
8
|
-
|
|
9
|
-
The timeout only works in Node.js. In the browser, it will simply not time out.
|
|
10
|
-
|
|
11
|
-
## Install
|
|
12
|
-
|
|
13
|
-
```sh
|
|
14
|
-
npm install super-regex
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
## Usage
|
|
18
|
-
|
|
19
|
-
```js
|
|
20
|
-
import {isMatch} from 'super-regex';
|
|
21
|
-
|
|
22
|
-
console.log(isMatch(/\d+/, getUserInput(), {timeout: 1000}));
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
## API
|
|
26
|
-
|
|
27
|
-
### isMatch(regex, string, options?)
|
|
28
|
-
|
|
29
|
-
Returns a boolean for whether the given `regex` matches the given `string`.
|
|
30
|
-
|
|
31
|
-
If the regex takes longer to match than the given timeout, it returns `false`.
|
|
32
|
-
|
|
33
|
-
*This method is similar to [`RegExp#test`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/test), but differs in that the given `regex` is [never mutated, even when it has the `/g` flag](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/test#using_test_on_a_regex_with_the_global_flag).*
|
|
34
|
-
|
|
35
|
-
### firstMatch(regex, string, options?)
|
|
36
|
-
|
|
37
|
-
Returns the first `Match` or `undefined` if there was no match.
|
|
38
|
-
|
|
39
|
-
If the regex takes longer to match than the given timeout, it returns `undefined`.
|
|
40
|
-
|
|
41
|
-
### matches(regex, string, options?)
|
|
42
|
-
|
|
43
|
-
Returns an iterable of `Match`es.
|
|
44
|
-
|
|
45
|
-
If the regex takes longer to match than the given timeout, it returns an empty array.
|
|
46
|
-
|
|
47
|
-
**The `regex` must have the `/g` flag.**
|
|
48
|
-
|
|
49
|
-
#### options
|
|
50
|
-
|
|
51
|
-
Type: `object`
|
|
52
|
-
|
|
53
|
-
##### timeout?
|
|
54
|
-
|
|
55
|
-
Type: `number` *(integer)*
|
|
56
|
-
|
|
57
|
-
The time in milliseconds to wait before timing out.
|
|
58
|
-
|
|
59
|
-
##### matchTimeout?
|
|
60
|
-
|
|
61
|
-
Type: `number` *(integer)*
|
|
62
|
-
|
|
63
|
-
Only works in `matches()`.
|
|
64
|
-
|
|
65
|
-
The time in milliseconds to wait before timing out when searching for each match.
|
|
66
|
-
|
|
67
|
-
### Match
|
|
68
|
-
|
|
69
|
-
```ts
|
|
70
|
-
{
|
|
71
|
-
match: string;
|
|
72
|
-
index: number;
|
|
73
|
-
groups: string[];
|
|
74
|
-
namedGroups: {string: string}; // object with string values
|
|
75
|
-
input: string;
|
|
76
|
-
}
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
## Related
|
|
80
|
-
|
|
81
|
-
- [function-timeout](https://github.com/sindresorhus/function-timeout) - Make a synchronous function have a timeout
|