@ericcornelissen/lregexp 1.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/LICENSE +21 -0
  2. package/README.md +31 -0
  3. package/index.js +16 -0
  4. package/package.json +29 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Eric Cornelissen
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:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
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 THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # lRegExp
2
+
3
+ Transparently create linear-time ([non-backtracking]) regular expressions.
4
+
5
+ [non-backtracking]: https://v8.dev/blog/non-backtracking-regexp
6
+
7
+ ## Usage
8
+
9
+ This library exports a drop-in replacement for the built-in RegExp.
10
+
11
+ ```shell
12
+ npm install @ericcornelissen/lregexp
13
+ ```
14
+
15
+ ```javascript
16
+ import RegExp from "@ericcornelissen/lregexp";
17
+ new RegExp("[linear]{6}");
18
+ ```
19
+
20
+ ## Why
21
+
22
+ Backtracking regular expressions can take exponential time to evaluate, leading
23
+ to the dreaded _ReDoS_ vulnerability. Linear-time regular expressions avoid this
24
+ by not backtracking.
25
+
26
+ ## Caveats
27
+
28
+ Not all regular expression constructs are valid in a linear-time regular
29
+ expression and this library won't tell you your regular expression is
30
+ incompatible unless you run it with the non-backtracking engine, in which
31
+ case it throws an error.
package/index.js ADDED
@@ -0,0 +1,16 @@
1
+ import isSupportedRegexpFlag from "is-supported-regexp-flag";
2
+
3
+ const RegExp_ = globalThis.RegExp;
4
+
5
+ let lRegExp;
6
+ if (isSupportedRegexpFlag("l")) {
7
+ lRegExp = function(pattern, flags="") {
8
+ return new RegExp_(pattern, `${flags}l`);
9
+ };
10
+ } else {
11
+ lRegExp = function(pattern, flags) {
12
+ return new RegExp_(pattern, flags);
13
+ };
14
+ }
15
+
16
+ export default lRegExp;
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@ericcornelissen/lregexp",
3
+ "description": "Transparently create linear-time regular expressions",
4
+ "version": "1.0.1",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "exports": "./index.js",
8
+ "bugs": {
9
+ "url": "https://github.com/ericcornelissen/lregexp/issues"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/ericcornelissen/depreman.git"
14
+ },
15
+ "author": {
16
+ "name": "Eric Cornelissen",
17
+ "email": "ericornelissen@gmail.com",
18
+ "url": "https://ericcornelissen.dev/"
19
+ },
20
+ "keywords": [
21
+ "regexp",
22
+ "regex",
23
+ "linear",
24
+ "flag"
25
+ ],
26
+ "dependencies": {
27
+ "is-supported-regexp-flag": "^2.0.0"
28
+ }
29
+ }