re2js 1.1.0 → 1.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/README.md +13 -13
- package/build/index.cjs.cjs +291 -260
- package/build/index.cjs.cjs.map +1 -1
- package/build/index.esm.d.ts +7 -7
- package/build/index.esm.d.ts.map +1 -1
- package/build/index.esm.js +291 -260
- package/build/index.esm.js.map +1 -1
- package/build/index.umd.js +291 -260
- package/build/index.umd.js.map +1 -1
- package/package.json +22 -21
package/README.md
CHANGED
|
@@ -98,18 +98,6 @@ RE2JS.DISABLE_UNICODE_GROUPS
|
|
|
98
98
|
RE2JS.LONGEST_MATCH
|
|
99
99
|
```
|
|
100
100
|
|
|
101
|
-
### Program size
|
|
102
|
-
|
|
103
|
-
The program size represents a very approximate measure of a regexp's "cost". Larger numbers are more expensive than smaller numbers.
|
|
104
|
-
|
|
105
|
-
```js
|
|
106
|
-
import { RE2JS } from 're2js'
|
|
107
|
-
|
|
108
|
-
console.log(RE2JS.compile('^').programSize()); // Outputs: 3
|
|
109
|
-
console.log(RE2JS.compile('a+b').programSize()); // Outputs: 5
|
|
110
|
-
console.log(RE2JS.compile('(a+b?)').programSize()); // Outputs: 8
|
|
111
|
-
```
|
|
112
|
-
|
|
113
101
|
### Checking for Matches
|
|
114
102
|
|
|
115
103
|
RE2JS allows you to check if a string matches a given regex pattern using the `matches()` function
|
|
@@ -385,9 +373,21 @@ RE2JS.matches(regexp, 'ab+c') // true
|
|
|
385
373
|
RE2JS.matches(regexp, 'abc') // false
|
|
386
374
|
```
|
|
387
375
|
|
|
376
|
+
### Program size
|
|
377
|
+
|
|
378
|
+
The program size represents a very approximate measure of a regexp's "cost". Larger numbers are more expensive than smaller numbers
|
|
379
|
+
|
|
380
|
+
```js
|
|
381
|
+
import { RE2JS } from 're2js'
|
|
382
|
+
|
|
383
|
+
console.log(RE2JS.compile('^').programSize()); // Outputs: 3
|
|
384
|
+
console.log(RE2JS.compile('a+b').programSize()); // Outputs: 5
|
|
385
|
+
console.log(RE2JS.compile('(a+b?)').programSize()); // Outputs: 8
|
|
386
|
+
```
|
|
387
|
+
|
|
388
388
|
## Performance
|
|
389
389
|
|
|
390
|
-
The RE2JS engine runs more slowly compared to native RegExp objects. This reduced speed is also noticeable when comparing RE2JS to the original RE2 engine. The C++ implementation of the RE2 engine includes both NFA (Nondeterministic Finite Automaton) and DFA (Deterministic Finite Automaton) engines, as well as a variety of optimizations. Russ Cox ported a simplified version of the NFA engine to Go. Later, Alan Donovan ported the NFA-based Go implementation to Java. I then ported the NFA-based Java implementation to a pure JS version. This is another reason why the pure JS version will perform more slowly compared to the original RE2 engine.
|
|
390
|
+
The RE2JS engine runs more slowly compared to native RegExp objects. This reduced speed is also noticeable when comparing RE2JS to the original RE2 engine. The C++ implementation of the RE2 engine includes both NFA (Nondeterministic Finite Automaton) and DFA (Deterministic Finite Automaton) engines, as well as a variety of optimizations. Russ Cox ported a simplified version of the NFA engine to Go. Later, Alan Donovan ported the NFA-based Go implementation to Java. I then ported the NFA-based Java implementation (plus Golang stuff, which are not present in Java implementation, like checks for regular expression complexity) to a pure JS version. This is another reason why the pure JS version will perform more slowly compared to the original RE2 engine.
|
|
391
391
|
|
|
392
392
|
Should you require high performance on the server side when using RE2, it would be beneficial to consider the following packages for JS:
|
|
393
393
|
|