rregex 1.1.4 → 1.1.5
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 +80 -191
- package/jsr.json +17 -0
- package/lib/{browser.d.ts → cf.d.ts} +216 -245
- package/lib/cf.mjs +20 -0
- package/lib/commonjs.cjs +609 -0
- package/lib/{commonjs.d.ts → commonjs.d.cts} +178 -221
- package/lib/{module.d.ts → esm.d.ts} +175 -231
- package/lib/esm.mjs +611 -0
- package/lib/rregex.wasm +0 -0
- package/lib/rregex.wasm.d.ts +29 -26
- package/lib/standalone.d.ts +517 -0
- package/lib/standalone.js +697 -0
- package/lib/types.d.ts +216 -245
- package/lib/web.d.ts +525 -0
- package/lib/web.js +700 -0
- package/package.json +127 -18
- package/lib/browser.js +0 -676
- package/lib/commonjs.js +0 -649
- package/lib/module.js +0 -628
package/README.md
CHANGED
|
@@ -1,25 +1,21 @@
|
|
|
1
1
|
# rregex
|
|
2
2
|
|
|
3
|
-
A WebAssembly build of [Rust Regex](https://docs.rs/regex/latest/regex/) for Javascript
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
* [`splitn(text: string, limit: number): string[];`](#splitntext-string-limit-number-string)
|
|
20
|
-
* [`shortestMatch(text: string): number | undefined;`](#shortestmatchtext-string-number--undefined)
|
|
21
|
-
* [`shortestMatchAt(text: string, limit: number): number | undefined;`](#shortestmatchattext-string-limit-number-number--undefined)
|
|
22
|
-
* [Known Issues](#known-issues)
|
|
3
|
+
A dependency-free WebAssembly build of [Rust Regex](https://docs.rs/regex/latest/regex/) for Javascript
|
|
4
|
+
|
|
5
|
+
  
|
|
6
|
+
[](https://jsr.io/@rregex/rregex)
|
|
7
|
+
|
|
8
|
+
- [Why Rust Regex](#why-rust-regex)
|
|
9
|
+
- [Install](#install)
|
|
10
|
+
- [Supported Runtimes](#supported-runtimes)
|
|
11
|
+
- [API](https://tsdocs.dev/docs/rregex/latest)
|
|
12
|
+
- [`RRegex`](https://tsdocs.dev/docs/rregex/latest/classes/RRegex.html)
|
|
13
|
+
- [`RRegexSet`](https://tsdocs.dev/docs/rregex/latest/classes/RRegexSet.html)
|
|
14
|
+
- [`Match`](https://tsdocs.dev/docs/rregex/latest/types/Match.html)
|
|
15
|
+
- [`Captures`](https://tsdocs.dev/docs/rregex/latest/types/Captures.html)
|
|
16
|
+
- [`escape`](https://tsdocs.dev/docs/rregex/latest/functions/escape.html)
|
|
17
|
+
- [Benchmarks](#benchmarks)
|
|
18
|
+
- [Known Issues](#known-issues)
|
|
23
19
|
|
|
24
20
|
## Why Rust Regex
|
|
25
21
|
|
|
@@ -30,202 +26,95 @@ Rust has a powerful Regex library with a lot of features that don't exists en th
|
|
|
30
26
|
## Install
|
|
31
27
|
|
|
32
28
|
```bash
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
## API
|
|
37
|
-
|
|
38
|
-
Similar to the native `Regex` object you can create a new `RRegex` instance using a string.
|
|
39
|
-
|
|
40
|
-
```typescript
|
|
41
|
-
import { RRegex } from "rregex";
|
|
42
|
-
const re = new RRegex("^d{4}-d{2}-d{2}$");
|
|
43
|
-
assert.equal(re.isMatch("2014-01-01"), true);
|
|
44
|
-
```
|
|
29
|
+
# NPM
|
|
30
|
+
npm install rregex
|
|
45
31
|
|
|
46
|
-
|
|
32
|
+
# Yarn
|
|
33
|
+
yarn add rregex
|
|
47
34
|
|
|
48
|
-
|
|
35
|
+
# PNPM
|
|
36
|
+
pnpm add rregex
|
|
49
37
|
|
|
50
|
-
|
|
38
|
+
# Deno
|
|
39
|
+
deno add @rregex/rregex
|
|
51
40
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const re = new RRegex("\\b\\w{13}\\b");
|
|
55
|
-
expect(re.isMatch(text)).toEqual(true);
|
|
41
|
+
# JSR
|
|
42
|
+
npx jsr add @rregex/rregex
|
|
56
43
|
```
|
|
57
44
|
|
|
58
|
-
|
|
45
|
+
## Supported Runtimes
|
|
59
46
|
|
|
60
|
-
|
|
47
|
+
This package includes builds for multiple runtimes
|
|
61
48
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
49
|
+
| Runtime | Import | version |
|
|
50
|
+
| ------------------ | ------------------------------------------------------- | ---------- |
|
|
51
|
+
| Node.js (esm) | `import { RRegex, RRegexSet } from 'rregex'` | `*` |
|
|
52
|
+
| Node.js (commonjs) | `const { RRegex, RRegexSet } = require('rregex')` | `*` |
|
|
53
|
+
| Deno | `import { RRegex, RRegexSet } from '@rregex/rregex'` | `>=1.10.8` |
|
|
54
|
+
| Bun | `import { RRegex, RRegexSet } from '@rregex/rregex'` | `>=1.10.8` |
|
|
55
|
+
| Cloudflare Workers | `import { RRegex, RRegexSet } from 'rregex/lib/cf.mjs'` | `>=1.10.8` |
|
|
56
|
+
| Browser | TODO | |
|
|
57
|
+
| Standalone | TODO | |
|
|
68
58
|
|
|
69
|
-
|
|
59
|
+
## Benchmarks
|
|
70
60
|
|
|
71
|
-
|
|
61
|
+
In general terms `rregex` is at least 1 order of magnitud slower than the native `RegExp` object, but still have a good performance. **Unless you required some of the features that `rregex` provides, you should always consider using the native `RegExp` object**
|
|
72
62
|
|
|
73
|
-
|
|
74
|
-
const text = "I categorically deny having triskaidekaphobia.";
|
|
75
|
-
const re = new RRegex("\\b\\w{13}\\b");
|
|
76
|
-
expect(re.find(text)).toEqual({
|
|
77
|
-
value: "categorically",
|
|
78
|
-
start: 2,
|
|
79
|
-
end: 15,
|
|
80
|
-
});
|
|
81
|
-
```
|
|
63
|
+
> Benchmarks are executed using [test/deno.bench.mjs](./test/deno.bench.mjs), and [test/node.bench.mjs](./test/node.bench.mjs)
|
|
82
64
|
|
|
83
|
-
###
|
|
65
|
+
### Email
|
|
84
66
|
|
|
85
|
-
|
|
67
|
+
| benchmark | time (avg) | iter/s |
|
|
68
|
+
| --------- | -------------: | ------: |
|
|
69
|
+
| RegExp | 254.8 µs/iter | 3,925.0 |
|
|
70
|
+
| RRegex | 1.7 ms/iter | 589.9 |
|
|
86
71
|
|
|
87
|
-
|
|
88
|
-
const text = "I categorically deny having triskaidekaphobia.";
|
|
89
|
-
const re = new RRegex("\\b\\w{13}\\b");
|
|
90
|
-
expect(re.findAt(text, 1)).toEqual({
|
|
91
|
-
value: "categorically",
|
|
92
|
-
start: 2,
|
|
93
|
-
end: 15,
|
|
94
|
-
});
|
|
72
|
+
> summary: `RegExp` is 6.65x faster than `RRegex`
|
|
95
73
|
|
|
96
|
-
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
### `findAll(text: string): Match[];`
|
|
100
|
-
|
|
101
|
-
Returns an array for each successive non-overlapping match in text, returning the start and end byte indices with respect to text ([See Documentation](https://docs.rs/regex/latest/regex/struct.Regex.html#method.find_iter))
|
|
102
|
-
|
|
103
|
-
```typescript
|
|
104
|
-
const text = 'Retroactively relinquishing remunerations is reprehensible.'
|
|
105
|
-
const re = new RRegex('\\b\\w{13}\\b')
|
|
106
|
-
expect(re.findAll(text)).toEqual([
|
|
107
|
-
{
|
|
108
|
-
"end": 13,
|
|
109
|
-
"start": 0,
|
|
110
|
-
"value": "Retroactively",
|
|
111
|
-
},
|
|
112
|
-
{
|
|
113
|
-
"end": 27,
|
|
114
|
-
"start": 14,
|
|
115
|
-
"value": "relinquishing",
|
|
116
|
-
},
|
|
117
|
-
{
|
|
118
|
-
"end": 41,
|
|
119
|
-
"start": 28,
|
|
120
|
-
"value": "remunerations",
|
|
121
|
-
},
|
|
122
|
-
{
|
|
123
|
-
"end": 58,
|
|
124
|
-
"start": 45,
|
|
125
|
-
"value": "reprehensible",
|
|
126
|
-
},
|
|
127
|
-
])
|
|
128
|
-
})
|
|
129
|
-
```
|
|
74
|
+
### IP
|
|
130
75
|
|
|
131
|
-
|
|
76
|
+
| benchmark | time (avg) | iter/s |
|
|
77
|
+
| --------- | ------------: | --------: |
|
|
78
|
+
| RegExp | 39.1 µs/iter | 25,600.0 |
|
|
79
|
+
| RRegex | 1.4 ms/iter | 698.1 |
|
|
132
80
|
|
|
133
|
-
|
|
81
|
+
> summary: `RegExp` is 36.67x faster than `RRegex`
|
|
134
82
|
|
|
135
|
-
|
|
83
|
+
### URI
|
|
136
84
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
expect(re.replace("1078910", "")).toBe("1010");
|
|
142
|
-
```
|
|
143
|
-
|
|
144
|
-
But this is a bit cumbersome to use all the time. Instead, a simple syntax is supported that expands `$name` into the corresponding capture group. Here’s the last example, but using this expansion technique with named capture groups:
|
|
145
|
-
|
|
146
|
-
```typescript
|
|
147
|
-
const re = new RRegex("(?P<last>[^,\\s]+),\\s+(?P<first>\\S+)");
|
|
148
|
-
const result = re.replace("Springsteen, Bruce", "$first $last");
|
|
149
|
-
expect(result).toEqual("Bruce Springsteen");
|
|
150
|
-
```
|
|
151
|
-
|
|
152
|
-
Note that using `$2` instead of `$first` or `$1` instead of `$last` would produce the same result. To write a literal `$` use `$$`.
|
|
153
|
-
|
|
154
|
-
Sometimes the replacement string requires use of curly braces to delineate a capture group replacement and surrounding literal text. For example, if we wanted to join two words together with an underscore:
|
|
155
|
-
|
|
156
|
-
```typescript
|
|
157
|
-
const re = new RRegex("(?P<first>\\w+)\\s+(?P<second>\\w+)");
|
|
158
|
-
const result = re.replace("deep fried", "${first}_$second");
|
|
159
|
-
expect(result).toEqual("deep_fried");
|
|
160
|
-
```
|
|
85
|
+
| benchmark | time (avg) | iter/s |
|
|
86
|
+
| --------- | -------------: | ----------: |
|
|
87
|
+
| RegExp | 422.7 ns/iter | 2,366,000.0 |
|
|
88
|
+
| RRegex | 1.5 ms/iter | 652.6 |
|
|
161
89
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
### `replaceAll(text: string, rep: string): string;`
|
|
165
|
-
|
|
166
|
-
Replaces all non-overlapping matches in `text` with the replacement provided. This is the same as calling `replacen` with `limit` set to `0`.
|
|
167
|
-
|
|
168
|
-
See the documentation for `replace` for details on how to access capturing group matches in the replacement string. ([See Documentation](https://docs.rs/regex/latest/regex/struct.Regex.html#method.replace_all))
|
|
169
|
-
|
|
170
|
-
### `replacen(text: string, limit: number, rep: string): string;`
|
|
171
|
-
|
|
172
|
-
Replaces at most `limit` non-overlapping matches in `text` with the replacement provided. If `limit` is 0, then all non-overlapping matches are replaced. ([See Documentation](https://docs.rs/regex/latest/regex/struct.Regex.html#method.replacen))
|
|
173
|
-
|
|
174
|
-
### `split(text: string): string[];`
|
|
175
|
-
|
|
176
|
-
Returns an iterator of substrings of `text` delimited by a match of the regular expression. Namely, each element of the iterator corresponds to text that isn’t matched by the regular expression. ([See Documentation](https://docs.rs/regex/latest/regex/struct.Regex.html#method.split))
|
|
177
|
-
|
|
178
|
-
```typescript
|
|
179
|
-
const re = new RRegex("[ \\t]+");
|
|
180
|
-
const fields = re.split("a b \t c\td e");
|
|
181
|
-
expect(fields).toEqual(["a", "b", "c", "d", "e"]);
|
|
182
|
-
```
|
|
183
|
-
|
|
184
|
-
### `splitn(text: string, limit: number): string[];`
|
|
185
|
-
|
|
186
|
-
Returns an iterator of at most `limit` substrings of `text` delimited by a match of the regular expression. (A limit of 0 will return no substrings.) Namely, each element of the iterator corresponds to text that isn’t matched by the regular expression. The remainder of the string that is not split will be the last element in the iterator.([See Documentation](https://docs.rs/regex/latest/regex/struct.Regex.html#method.splitn))
|
|
187
|
-
|
|
188
|
-
```typescript
|
|
189
|
-
const re = new RRegex("\\W+");
|
|
190
|
-
const fields = re.splitn("Hey! How are you?", 3);
|
|
191
|
-
expect(fields).toEqual(["Hey", "How", "are you?"]);
|
|
192
|
-
```
|
|
193
|
-
|
|
194
|
-
### `shortestMatch(text: string): number | undefined;`
|
|
195
|
-
|
|
196
|
-
Returns the end location of a match in the text given.
|
|
197
|
-
|
|
198
|
-
This method may have the same performance characteristics as `is_match`, except it provides an end location for a match. In particular, the location returned may be shorter than the proper end of the leftmost-first match. ([See Documentation](https://docs.rs/regex/latest/regex/struct.Regex.html#method.shortest_match))
|
|
199
|
-
|
|
200
|
-
```typescript
|
|
201
|
-
const text = 'aaaaa'
|
|
202
|
-
const pos = new RRegex('a+')
|
|
203
|
-
expect(pos.shortestMatch(text)).toBe(1)
|
|
204
|
-
```
|
|
90
|
+
> summary: `RegExp` is 3625x faster than `RRegex`
|
|
205
91
|
|
|
206
|
-
|
|
92
|
+
| benckmarks | benckmarks |
|
|
93
|
+
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
94
|
+
| [](https://jsbenchmark.com/#eyJjYXNlcyI6W3siaWQiOiJlZl9VbGJvYThpRGNYeGM3VUl4YnMiLCJjb2RlIjoiREFUQS5tYXRjaCgnKD86KD86MjVbMC01XXwyWzAtNF1bMC05XXxbMDFdP1swLTldWzAtOV0pXFxcXC4pezN9KD86MjVbMC01XXwyWzAtNF1bMC05XXxbMDFdP1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ZW5jaWVzIjpbeyJ1cmwiOiJodHRwczovL2Nkbi5qc2RlbGl2ci5uZXQvbnBtL3JyZWdleEAxLjEwLjEwL2xpYi93ZWIubWluLmpzIiwibmFtZSI6InJyZWdleCIsImVzbSI6dHJ1ZX1dfSwiZGF0YUNvZGUiOiJjb25zdCBkcmVzID0gYXdhaXQgZmV0Y2goJ2h0dHBzOi8vcmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbS9tYXJpb21rYS9yZWdleC1iZW5jaG1hcmsvbWFzdGVyL2lucHV0LXRleHQudHh0JylcbmNvbnN0IGRhdGEgPSBhd2FpdCBkcmVzLnRleHQoKVxuXG5jb25zdCB3cmVzID0gYXdhaXQgZmV0Y2goJ2h0dHBzOi8vY2RuLmpzZGVsaXZyLm5ldC9ucG0vcnJlZ2V4QDEuMTAuMTAvbGliL3JyZWdleC53YXNtJylcbmNvbnN0IHcgPSBhd2FpdCB3cmVzLmFycmF5QnVmZmVyKClcbnJyZWdleC5pbml0U3luYyh3KVxuXG5yZXR1cm4gZGF0YS5zbGljZSgwLCBNYXRoLmZsb29yKGRhdGEubGVuZ3RoLzUpKSJ9fQ) |
|
|
207
96
|
|
|
208
|
-
|
|
97
|
+
> **Note:** In order to compare with native regex these benchmarks follow the [`mariomka/regex-benchmark`](https://github.com/mariomka/regex-benchmark) structure
|
|
209
98
|
|
|
210
99
|
## Known Issues
|
|
211
100
|
|
|
212
|
-
If you call `splitn(text, limit)` and the expected result length is equal to `limit - 1` the result will include an extra item `""`, this behavior does not happen if `limit` es greater.
|
|
101
|
+
If you call `splitn(text, limit)` and the expected result length is equal to `limit - 1` the result will include an extra item `""`, this behavior does not happen if `limit` es greater. **`fixed at >=1.3`**
|
|
213
102
|
|
|
214
103
|
```ts
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
104
|
+
const regex = new RRegex(",");
|
|
105
|
+
expect(regex.splitn("a,b,c", 0)).toEqual([]);
|
|
106
|
+
expect(regex.splitn("a,b,c", 1)).toEqual(["a,b,c"]);
|
|
107
|
+
expect(regex.splitn("a,b,c", 2)).toEqual(["a", "b,c"]);
|
|
108
|
+
expect(regex.splitn("a,b,c", 3)).toEqual(["a", "b", "c"]);
|
|
109
|
+
|
|
110
|
+
// This result includes an unexpected extra item
|
|
111
|
+
expect(regex.splitn("a,b,c", 4)).toEqual(["a", "b", "c", ""]);
|
|
112
|
+
expect(regex.splitn("a,b,c", 5)).toEqual(["a", "b", "c"]);
|
|
113
|
+
|
|
114
|
+
expect(regex.splitn("abc", 0)).toEqual([]);
|
|
115
|
+
expect(regex.splitn("abc", 1)).toEqual(["abc"]);
|
|
116
|
+
|
|
117
|
+
// This result includes an unexpected extra item
|
|
118
|
+
expect(regex.splitn("abc", 2)).toEqual(["abc", ""]);
|
|
119
|
+
expect(regex.splitn("abc", 3)).toEqual(["abc"]);
|
|
231
120
|
```
|
package/jsr.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rregex/rregex",
|
|
3
|
+
"version": "0.0.0-development",
|
|
4
|
+
"description": "A dependency-free WebAssembly build of Rust Regex for Javascript",
|
|
5
|
+
"exports": "./lib/esm.mjs",
|
|
6
|
+
"publish": {
|
|
7
|
+
"include": [
|
|
8
|
+
"LICENSE",
|
|
9
|
+
"README.md",
|
|
10
|
+
"jsr.json",
|
|
11
|
+
"lib/rregex.wasm",
|
|
12
|
+
"lib/rregex.wasm.d.ts",
|
|
13
|
+
"lib/esm.mjs",
|
|
14
|
+
"lib/esm.d.ts"
|
|
15
|
+
]
|
|
16
|
+
}
|
|
17
|
+
}
|