rregex 1.0.1 → 1.0.2
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 +42 -2
- package/lib/rregex.wasm +0 -0
- package/package.json +1 -1
- package/test/rregex.test.ts +11 -8
package/README.md
CHANGED
|
@@ -4,6 +4,23 @@ A WebAssembly build of [Rust Regex](https://docs.rs/regex/latest/regex/) for Jav
|
|
|
4
4
|
|
|
5
5
|
> Note: this project is not intended to be used in production jet
|
|
6
6
|
|
|
7
|
+
* [Why Rust Regex](#why-rust-regex)
|
|
8
|
+
* [Install](#install)
|
|
9
|
+
* [API](#api)
|
|
10
|
+
* [`isMatch(text: string): boolean`](#ismatchtext-string-boolean)
|
|
11
|
+
* [`isMatchAt(text: string, limit: number): boolean`](#ismatchattext-string-limit-number-boolean)
|
|
12
|
+
* [`find(text: string): Match | undefined;`](#findtext-string-match--undefined)
|
|
13
|
+
* [`findAt(text: string): Match | undefined;`](#findattext-string-match--undefined)
|
|
14
|
+
* [`findAll(text: string): Match[];`](#findalltext-string-match)
|
|
15
|
+
* [`replace(text: string, rep: string): string;`](#replacetext-string-rep-string-string)
|
|
16
|
+
* [`replaceAll(text: string, rep: string): string;`](#replacealltext-string-rep-string-string)
|
|
17
|
+
* [`replacen(text: string, limit: number, rep: string): string;`](#replacentext-string-limit-number-rep-string-string)
|
|
18
|
+
* [`split(text: string): string[];`](#splittext-string-string)
|
|
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)
|
|
23
|
+
|
|
7
24
|
## Why Rust Regex
|
|
8
25
|
|
|
9
26
|
Rust has a powerful Regex library with a lot of features that don't exists en the standard `Regex` object
|
|
@@ -28,7 +45,7 @@ assert.equal(re.isMatch("2014-01-01"), true);
|
|
|
28
45
|
|
|
29
46
|
> Note: It doesn't take a second parameter because fags are part of the syntax ([See Documentation](https://docs.rs/regex/latest/regex/#grouping-and-flags))
|
|
30
47
|
|
|
31
|
-
### `isMatch(text: string): boolean
|
|
48
|
+
### `isMatch(text: string): boolean;`
|
|
32
49
|
|
|
33
50
|
Returns true if and only if there is a match for the regex in the string given. ([See Documentation](https://docs.rs/regex/latest/regex/struct.Regex.html#method.is_match))
|
|
34
51
|
|
|
@@ -38,7 +55,7 @@ const re = new RRegex("\\b\\w{13}\\b");
|
|
|
38
55
|
expect(re.isMatch(text)).toEqual(true);
|
|
39
56
|
```
|
|
40
57
|
|
|
41
|
-
### `isMatchAt(text: string, limit: number): boolean
|
|
58
|
+
### `isMatchAt(text: string, limit: number): boolean;`
|
|
42
59
|
|
|
43
60
|
Returns the same as is_match, but starts the search at the given offset. ([See Documentation](https://docs.rs/regex/latest/regex/struct.Regex.html#method.is_match_at))
|
|
44
61
|
|
|
@@ -189,3 +206,26 @@ This method may have the same performance characteristics as `is_match`, except
|
|
|
189
206
|
### `shortestMatchAt(text: string, limit: number): number | undefined;`
|
|
190
207
|
|
|
191
208
|
Returns the same as shortest_match, but starts the search at the given offset. ([See Documentation](https://docs.rs/regex/latest/regex/struct.Regex.html#method.shortest_match_at))
|
|
209
|
+
|
|
210
|
+
## Known Issues
|
|
211
|
+
|
|
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.
|
|
213
|
+
|
|
214
|
+
```ts
|
|
215
|
+
const regex = new RRegex(',')
|
|
216
|
+
expect(regex.splitn('a,b,c', 0)).toEqual([])
|
|
217
|
+
expect(regex.splitn('a,b,c', 1)).toEqual(['a,b,c'])
|
|
218
|
+
expect(regex.splitn('a,b,c', 2)).toEqual(['a', 'b,c'])
|
|
219
|
+
expect(regex.splitn('a,b,c', 3)).toEqual(['a', 'b', 'c'])
|
|
220
|
+
|
|
221
|
+
// This result includes an unexpected extra item
|
|
222
|
+
expect(regex.splitn('a,b,c', 4)).toEqual(['a', 'b', 'c', ''])
|
|
223
|
+
expect(regex.splitn('a,b,c', 5)).toEqual(['a', 'b', 'c'])
|
|
224
|
+
|
|
225
|
+
expect(regex.splitn('abc', 0)).toEqual([])
|
|
226
|
+
expect(regex.splitn('abc', 1)).toEqual(['abc'])
|
|
227
|
+
|
|
228
|
+
// This result includes an unexpected extra item
|
|
229
|
+
expect(regex.splitn('abc', 2)).toEqual(['abc', ''])
|
|
230
|
+
expect(regex.splitn('abc', 3)).toEqual(['abc'])
|
|
231
|
+
```
|
package/lib/rregex.wasm
CHANGED
|
Binary file
|
package/package.json
CHANGED
package/test/rregex.test.ts
CHANGED
|
@@ -147,14 +147,17 @@ describe(`RRegex`, () => {
|
|
|
147
147
|
})
|
|
148
148
|
|
|
149
149
|
test(`splitn`, () => {
|
|
150
|
-
const regex = new RRegex('
|
|
151
|
-
expect(regex.splitn('
|
|
152
|
-
expect(regex.splitn('
|
|
153
|
-
expect(regex.splitn('
|
|
154
|
-
expect(regex.splitn('
|
|
155
|
-
expect(regex.splitn('
|
|
156
|
-
expect(regex.splitn('
|
|
157
|
-
expect(regex.splitn('
|
|
150
|
+
const regex = new RRegex(',')
|
|
151
|
+
expect(regex.splitn('a,b,c', 0)).toEqual([])
|
|
152
|
+
expect(regex.splitn('a,b,c', 1)).toEqual(['a,b,c'])
|
|
153
|
+
expect(regex.splitn('a,b,c', 2)).toEqual(['a', 'b,c'])
|
|
154
|
+
expect(regex.splitn('a,b,c', 3)).toEqual(['a', 'b', 'c'])
|
|
155
|
+
expect(regex.splitn('a,b,c', 4)).toEqual(['a', 'b', 'c', ''])
|
|
156
|
+
expect(regex.splitn('a,b,c', 5)).toEqual(['a', 'b', 'c'])
|
|
157
|
+
expect(regex.splitn('abc', 0)).toEqual([])
|
|
158
|
+
expect(regex.splitn('abc', 1)).toEqual(['abc'])
|
|
159
|
+
expect(regex.splitn('abc', 2)).toEqual(['abc', ''])
|
|
160
|
+
expect(regex.splitn('abc', 3)).toEqual(['abc'])
|
|
158
161
|
|
|
159
162
|
const re = new RRegex('\\W+')
|
|
160
163
|
const fields = re.splitn('Hey! How are you?', 3)
|