rregex 1.0.1 → 1.0.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 +42 -2
- package/lib/browser.d.ts +14 -9
- package/lib/browser.js +20 -16
- package/lib/commonjs.d.ts +13 -7
- package/lib/commonjs.js +20 -16
- package/lib/module.d.ts +13 -7
- package/lib/module.js +8 -16
- package/lib/rregex.wasm +0 -0
- package/lib/rregex.wasm.d.ts +1 -2
- package/lib/types.d.ts +14 -9
- package/package.json +15 -2
- package/babel.config.js +0 -7
- package/jest.transform.js +0 -3
- package/test/rregex.test.ts +0 -232
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/browser.d.ts
CHANGED
|
@@ -5,17 +5,11 @@
|
|
|
5
5
|
* @returns {string}
|
|
6
6
|
*/
|
|
7
7
|
export function escape(text: string): string;
|
|
8
|
-
/**
|
|
9
|
-
* @returns {any}
|
|
10
|
-
*/
|
|
11
|
-
export function get_metadata(): any;
|
|
12
8
|
|
|
13
9
|
export type Hir = {
|
|
14
10
|
'@type': 'struct'
|
|
15
11
|
'@name': 'regex_syntax::hir::Hir'
|
|
16
|
-
|
|
17
|
-
italic: boolean;
|
|
18
|
-
size: number;
|
|
12
|
+
kind: HirKind
|
|
19
13
|
}
|
|
20
14
|
|
|
21
15
|
|
|
@@ -509,7 +503,6 @@ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembl
|
|
|
509
503
|
|
|
510
504
|
export interface InitOutput {
|
|
511
505
|
readonly memory: WebAssembly.Memory;
|
|
512
|
-
readonly escape: (a: number, b: number, c: number) => void;
|
|
513
506
|
readonly __wbg_rregex_free: (a: number) => void;
|
|
514
507
|
readonly rregex_new: (a: number, b: number) => number;
|
|
515
508
|
readonly rregex_isMatch: (a: number, b: number, c: number) => number;
|
|
@@ -526,11 +519,11 @@ export interface InitOutput {
|
|
|
526
519
|
readonly rregex_shortestMatchAt: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
527
520
|
readonly rregex_syntax: (a: number) => number;
|
|
528
521
|
readonly rregex_toString: (a: number, b: number) => void;
|
|
529
|
-
readonly get_metadata: () => number;
|
|
530
522
|
readonly __wbg_rregexset_free: (a: number) => void;
|
|
531
523
|
readonly rregexset_new: (a: number) => number;
|
|
532
524
|
readonly rregexset_isMatch: (a: number, b: number, c: number) => number;
|
|
533
525
|
readonly rregexset_matches: (a: number, b: number, c: number) => number;
|
|
526
|
+
readonly escape: (a: number, b: number, c: number) => void;
|
|
534
527
|
readonly __wbindgen_malloc: (a: number) => number;
|
|
535
528
|
readonly __wbindgen_realloc: (a: number, b: number, c: number) => number;
|
|
536
529
|
readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
|
|
@@ -547,3 +540,15 @@ export interface InitOutput {
|
|
|
547
540
|
* @returns {Promise<InitOutput>}
|
|
548
541
|
*/
|
|
549
542
|
export default function init (module_or_path?: InitInput | Promise<InitInput>): Promise<InitOutput>;
|
|
543
|
+
|
|
544
|
+
export const metadata: {
|
|
545
|
+
"name": "rregex",
|
|
546
|
+
"description": "Rust Regex binding for Javascript",
|
|
547
|
+
"authors": [
|
|
548
|
+
"Fede Ramirez <i@2fd.me>"
|
|
549
|
+
],
|
|
550
|
+
"homepage": "https://2fd.github.io/rregex",
|
|
551
|
+
"repository": "https://github.com/2fd/rregex",
|
|
552
|
+
"regex": "1.0.6",
|
|
553
|
+
"regex-syntax": "0.6.25"
|
|
554
|
+
}
|
package/lib/browser.js
CHANGED
|
@@ -177,6 +177,14 @@ function debugString(val) {
|
|
|
177
177
|
// TODO we could test for more things here, like `Set`s and `Map`s.
|
|
178
178
|
return className;
|
|
179
179
|
}
|
|
180
|
+
|
|
181
|
+
let stack_pointer = 32;
|
|
182
|
+
|
|
183
|
+
function addBorrowedObject(obj) {
|
|
184
|
+
if (stack_pointer == 1) throw new Error('out of js stack');
|
|
185
|
+
heap[--stack_pointer] = obj;
|
|
186
|
+
return stack_pointer;
|
|
187
|
+
}
|
|
180
188
|
/**
|
|
181
189
|
* @param {string} text
|
|
182
190
|
* @returns {string}
|
|
@@ -196,22 +204,6 @@ export function escape(text) {
|
|
|
196
204
|
}
|
|
197
205
|
}
|
|
198
206
|
|
|
199
|
-
/**
|
|
200
|
-
* @returns {any}
|
|
201
|
-
*/
|
|
202
|
-
export function get_metadata() {
|
|
203
|
-
var ret = wasm.get_metadata();
|
|
204
|
-
return takeObject(ret);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
let stack_pointer = 32;
|
|
208
|
-
|
|
209
|
-
function addBorrowedObject(obj) {
|
|
210
|
-
if (stack_pointer == 1) throw new Error('out of js stack');
|
|
211
|
-
heap[--stack_pointer] = obj;
|
|
212
|
-
return stack_pointer;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
207
|
function handleError(f, args) {
|
|
216
208
|
try {
|
|
217
209
|
return f.apply(this, args);
|
|
@@ -670,3 +662,15 @@ async function init(input) {
|
|
|
670
662
|
|
|
671
663
|
export default init;
|
|
672
664
|
|
|
665
|
+
|
|
666
|
+
export const metadata = {
|
|
667
|
+
"name": "rregex",
|
|
668
|
+
"description": "Rust Regex binding for Javascript",
|
|
669
|
+
"authors": [
|
|
670
|
+
"Fede Ramirez <i@2fd.me>"
|
|
671
|
+
],
|
|
672
|
+
"homepage": "https://2fd.github.io/rregex",
|
|
673
|
+
"repository": "https://github.com/2fd/rregex",
|
|
674
|
+
"regex": "1.0.6",
|
|
675
|
+
"regex-syntax": "0.6.25"
|
|
676
|
+
}
|
package/lib/commonjs.d.ts
CHANGED
|
@@ -5,17 +5,11 @@
|
|
|
5
5
|
* @returns {string}
|
|
6
6
|
*/
|
|
7
7
|
export function escape(text: string): string;
|
|
8
|
-
/**
|
|
9
|
-
* @returns {any}
|
|
10
|
-
*/
|
|
11
|
-
export function get_metadata(): any;
|
|
12
8
|
|
|
13
9
|
export type Hir = {
|
|
14
10
|
'@type': 'struct'
|
|
15
11
|
'@name': 'regex_syntax::hir::Hir'
|
|
16
|
-
|
|
17
|
-
italic: boolean;
|
|
18
|
-
size: number;
|
|
12
|
+
kind: HirKind
|
|
19
13
|
}
|
|
20
14
|
|
|
21
15
|
|
|
@@ -504,3 +498,15 @@ export class RRegexSet {
|
|
|
504
498
|
*/
|
|
505
499
|
matches(text: string): any;
|
|
506
500
|
}
|
|
501
|
+
|
|
502
|
+
export const metadata: {
|
|
503
|
+
"name": "rregex",
|
|
504
|
+
"description": "Rust Regex binding for Javascript",
|
|
505
|
+
"authors": [
|
|
506
|
+
"Fede Ramirez <i@2fd.me>"
|
|
507
|
+
],
|
|
508
|
+
"homepage": "https://2fd.github.io/rregex",
|
|
509
|
+
"repository": "https://github.com/2fd/rregex",
|
|
510
|
+
"regex": "1.0.6",
|
|
511
|
+
"regex-syntax": "0.6.25"
|
|
512
|
+
}
|
package/lib/commonjs.js
CHANGED
|
@@ -179,6 +179,14 @@ function debugString(val) {
|
|
|
179
179
|
// TODO we could test for more things here, like `Set`s and `Map`s.
|
|
180
180
|
return className;
|
|
181
181
|
}
|
|
182
|
+
|
|
183
|
+
let stack_pointer = 32;
|
|
184
|
+
|
|
185
|
+
function addBorrowedObject(obj) {
|
|
186
|
+
if (stack_pointer == 1) throw new Error('out of js stack');
|
|
187
|
+
heap[--stack_pointer] = obj;
|
|
188
|
+
return stack_pointer;
|
|
189
|
+
}
|
|
182
190
|
/**
|
|
183
191
|
* @param {string} text
|
|
184
192
|
* @returns {string}
|
|
@@ -198,22 +206,6 @@ module.exports.escape = function(text) {
|
|
|
198
206
|
}
|
|
199
207
|
};
|
|
200
208
|
|
|
201
|
-
/**
|
|
202
|
-
* @returns {any}
|
|
203
|
-
*/
|
|
204
|
-
module.exports.get_metadata = function() {
|
|
205
|
-
var ret = wasm.get_metadata();
|
|
206
|
-
return takeObject(ret);
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
let stack_pointer = 32;
|
|
210
|
-
|
|
211
|
-
function addBorrowedObject(obj) {
|
|
212
|
-
if (stack_pointer == 1) throw new Error('out of js stack');
|
|
213
|
-
heap[--stack_pointer] = obj;
|
|
214
|
-
return stack_pointer;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
209
|
function handleError(f, args) {
|
|
218
210
|
try {
|
|
219
211
|
return f.apply(this, args);
|
|
@@ -643,3 +635,15 @@ const wasmInstance = new WebAssembly.Instance(wasmModule, imports);
|
|
|
643
635
|
wasm = wasmInstance.exports;
|
|
644
636
|
module.exports.__wasm = wasm;
|
|
645
637
|
|
|
638
|
+
|
|
639
|
+
module.exports.metadata = {
|
|
640
|
+
"name": "rregex",
|
|
641
|
+
"description": "Rust Regex binding for Javascript",
|
|
642
|
+
"authors": [
|
|
643
|
+
"Fede Ramirez <i@2fd.me>"
|
|
644
|
+
],
|
|
645
|
+
"homepage": "https://2fd.github.io/rregex",
|
|
646
|
+
"repository": "https://github.com/2fd/rregex",
|
|
647
|
+
"regex": "1.0.6",
|
|
648
|
+
"regex-syntax": "0.6.25"
|
|
649
|
+
}
|
package/lib/module.d.ts
CHANGED
|
@@ -5,17 +5,11 @@
|
|
|
5
5
|
* @returns {string}
|
|
6
6
|
*/
|
|
7
7
|
export function escape(text: string): string;
|
|
8
|
-
/**
|
|
9
|
-
* @returns {any}
|
|
10
|
-
*/
|
|
11
|
-
export function get_metadata(): any;
|
|
12
8
|
|
|
13
9
|
export type Hir = {
|
|
14
10
|
'@type': 'struct'
|
|
15
11
|
'@name': 'regex_syntax::hir::Hir'
|
|
16
|
-
|
|
17
|
-
italic: boolean;
|
|
18
|
-
size: number;
|
|
12
|
+
kind: HirKind
|
|
19
13
|
}
|
|
20
14
|
|
|
21
15
|
|
|
@@ -504,3 +498,15 @@ export class RRegexSet {
|
|
|
504
498
|
*/
|
|
505
499
|
matches(text: string): any;
|
|
506
500
|
}
|
|
501
|
+
|
|
502
|
+
export const metadata: {
|
|
503
|
+
"name": "rregex",
|
|
504
|
+
"description": "Rust Regex binding for Javascript",
|
|
505
|
+
"authors": [
|
|
506
|
+
"Fede Ramirez <i@2fd.me>"
|
|
507
|
+
],
|
|
508
|
+
"homepage": "https://2fd.github.io/rregex",
|
|
509
|
+
"repository": "https://github.com/2fd/rregex",
|
|
510
|
+
"regex": "1.0.6",
|
|
511
|
+
"regex-syntax": "0.6.25"
|
|
512
|
+
}
|
package/lib/module.js
CHANGED
|
@@ -180,6 +180,14 @@ function debugString(val) {
|
|
|
180
180
|
// TODO we could test for more things here, like `Set`s and `Map`s.
|
|
181
181
|
return className;
|
|
182
182
|
}
|
|
183
|
+
|
|
184
|
+
let stack_pointer = 32;
|
|
185
|
+
|
|
186
|
+
function addBorrowedObject(obj) {
|
|
187
|
+
if (stack_pointer == 1) throw new Error('out of js stack');
|
|
188
|
+
heap[--stack_pointer] = obj;
|
|
189
|
+
return stack_pointer;
|
|
190
|
+
}
|
|
183
191
|
/**
|
|
184
192
|
* @param {string} text
|
|
185
193
|
* @returns {string}
|
|
@@ -199,22 +207,6 @@ export function escape(text) {
|
|
|
199
207
|
}
|
|
200
208
|
}
|
|
201
209
|
|
|
202
|
-
/**
|
|
203
|
-
* @returns {any}
|
|
204
|
-
*/
|
|
205
|
-
export function get_metadata() {
|
|
206
|
-
var ret = wasm.get_metadata();
|
|
207
|
-
return takeObject(ret);
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
let stack_pointer = 32;
|
|
211
|
-
|
|
212
|
-
function addBorrowedObject(obj) {
|
|
213
|
-
if (stack_pointer == 1) throw new Error('out of js stack');
|
|
214
|
-
heap[--stack_pointer] = obj;
|
|
215
|
-
return stack_pointer;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
210
|
function handleError(f, args) {
|
|
219
211
|
try {
|
|
220
212
|
return f.apply(this, args);
|
package/lib/rregex.wasm
CHANGED
|
Binary file
|
package/lib/rregex.wasm.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
export const memory: WebAssembly.Memory;
|
|
4
|
-
export function escape(a: number, b: number, c: number): void;
|
|
5
4
|
export function __wbg_rregex_free(a: number): void;
|
|
6
5
|
export function rregex_new(a: number, b: number): number;
|
|
7
6
|
export function rregex_isMatch(a: number, b: number, c: number): number;
|
|
@@ -18,11 +17,11 @@ export function rregex_shortestMatch(a: number, b: number, c: number, d: number)
|
|
|
18
17
|
export function rregex_shortestMatchAt(a: number, b: number, c: number, d: number, e: number): void;
|
|
19
18
|
export function rregex_syntax(a: number): number;
|
|
20
19
|
export function rregex_toString(a: number, b: number): void;
|
|
21
|
-
export function get_metadata(): number;
|
|
22
20
|
export function __wbg_rregexset_free(a: number): void;
|
|
23
21
|
export function rregexset_new(a: number): number;
|
|
24
22
|
export function rregexset_isMatch(a: number, b: number, c: number): number;
|
|
25
23
|
export function rregexset_matches(a: number, b: number, c: number): number;
|
|
24
|
+
export function escape(a: number, b: number, c: number): void;
|
|
26
25
|
export function __wbindgen_malloc(a: number): number;
|
|
27
26
|
export function __wbindgen_realloc(a: number, b: number, c: number): number;
|
|
28
27
|
export function __wbindgen_add_to_stack_pointer(a: number): number;
|
package/lib/types.d.ts
CHANGED
|
@@ -5,17 +5,11 @@
|
|
|
5
5
|
* @returns {string}
|
|
6
6
|
*/
|
|
7
7
|
export function escape(text: string): string;
|
|
8
|
-
/**
|
|
9
|
-
* @returns {any}
|
|
10
|
-
*/
|
|
11
|
-
export function get_metadata(): any;
|
|
12
8
|
|
|
13
9
|
export type Hir = {
|
|
14
10
|
'@type': 'struct'
|
|
15
11
|
'@name': 'regex_syntax::hir::Hir'
|
|
16
|
-
|
|
17
|
-
italic: boolean;
|
|
18
|
-
size: number;
|
|
12
|
+
kind: HirKind
|
|
19
13
|
}
|
|
20
14
|
|
|
21
15
|
|
|
@@ -509,7 +503,6 @@ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembl
|
|
|
509
503
|
|
|
510
504
|
export interface InitOutput {
|
|
511
505
|
readonly memory: WebAssembly.Memory;
|
|
512
|
-
readonly escape: (a: number, b: number, c: number) => void;
|
|
513
506
|
readonly __wbg_rregex_free: (a: number) => void;
|
|
514
507
|
readonly rregex_new: (a: number, b: number) => number;
|
|
515
508
|
readonly rregex_isMatch: (a: number, b: number, c: number) => number;
|
|
@@ -526,11 +519,11 @@ export interface InitOutput {
|
|
|
526
519
|
readonly rregex_shortestMatchAt: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
527
520
|
readonly rregex_syntax: (a: number) => number;
|
|
528
521
|
readonly rregex_toString: (a: number, b: number) => void;
|
|
529
|
-
readonly get_metadata: () => number;
|
|
530
522
|
readonly __wbg_rregexset_free: (a: number) => void;
|
|
531
523
|
readonly rregexset_new: (a: number) => number;
|
|
532
524
|
readonly rregexset_isMatch: (a: number, b: number, c: number) => number;
|
|
533
525
|
readonly rregexset_matches: (a: number, b: number, c: number) => number;
|
|
526
|
+
readonly escape: (a: number, b: number, c: number) => void;
|
|
534
527
|
readonly __wbindgen_malloc: (a: number) => number;
|
|
535
528
|
readonly __wbindgen_realloc: (a: number, b: number, c: number) => number;
|
|
536
529
|
readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
|
|
@@ -547,3 +540,15 @@ export interface InitOutput {
|
|
|
547
540
|
* @returns {Promise<InitOutput>}
|
|
548
541
|
*/
|
|
549
542
|
export default function init (module_or_path?: InitInput | Promise<InitInput>): Promise<InitOutput>;
|
|
543
|
+
|
|
544
|
+
export const metadata: {
|
|
545
|
+
"name": "rregex",
|
|
546
|
+
"description": "Rust Regex binding for Javascript",
|
|
547
|
+
"authors": [
|
|
548
|
+
"Fede Ramirez <i@2fd.me>"
|
|
549
|
+
],
|
|
550
|
+
"homepage": "https://2fd.github.io/rregex",
|
|
551
|
+
"repository": "https://github.com/2fd/rregex",
|
|
552
|
+
"regex": "1.0.6",
|
|
553
|
+
"regex-syntax": "0.6.25"
|
|
554
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rregex",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "Rust Regex binding for Javascript",
|
|
5
5
|
"private": false,
|
|
6
6
|
"main": "./lib/commonjs.js",
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"babel-jest": "^27.4.2",
|
|
17
17
|
"jest": "^27.4.3",
|
|
18
18
|
"semantic-release": "^18.0.1",
|
|
19
|
+
"toml": "^3.0.0",
|
|
19
20
|
"typescript": "^4.5.2"
|
|
20
21
|
},
|
|
21
22
|
"scripts": {
|
|
@@ -29,7 +30,19 @@
|
|
|
29
30
|
"release": {
|
|
30
31
|
"ci": false,
|
|
31
32
|
"branches": [
|
|
32
|
-
|
|
33
|
+
{
|
|
34
|
+
"name": "1.0.x",
|
|
35
|
+
"range": "1.0.x",
|
|
36
|
+
"channel": "1.0.x"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"name": "1.1.x",
|
|
40
|
+
"range": "1.1.x",
|
|
41
|
+
"channel": "1.1.x"
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"name": "master"
|
|
45
|
+
}
|
|
33
46
|
]
|
|
34
47
|
},
|
|
35
48
|
"repository": {
|
package/babel.config.js
DELETED
package/jest.transform.js
DELETED
package/test/rregex.test.ts
DELETED
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
import { RRegex, RRegexSet } from '../lib/commonjs'
|
|
2
|
-
|
|
3
|
-
describe(`RRegex`, () => {
|
|
4
|
-
test(`toString`, () => {
|
|
5
|
-
expect(new RRegex('a').toString()).toBe('a')
|
|
6
|
-
})
|
|
7
|
-
|
|
8
|
-
test(`isMatch`, () => {
|
|
9
|
-
const regex = new RRegex('a')
|
|
10
|
-
expect(regex.isMatch('abc')).toBe(true)
|
|
11
|
-
expect(regex.isMatch('def')).toBe(false)
|
|
12
|
-
|
|
13
|
-
const text = 'I categorically deny having triskaidekaphobia.';
|
|
14
|
-
const re = new RRegex('\\b\\w{13}\\b')
|
|
15
|
-
expect(re.isMatch(text)).toEqual(true);
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
test(`isMatchAt`, () => {
|
|
19
|
-
const regex = new RRegex('a')
|
|
20
|
-
expect(regex.isMatchAt('ab', 0)).toBe(true)
|
|
21
|
-
expect(regex.isMatchAt('ab', 1)).toBe(false)
|
|
22
|
-
expect(regex.isMatchAt('ab', 1)).toBe(false)
|
|
23
|
-
expect(regex.isMatchAt('ab', 100)).toBe(false)
|
|
24
|
-
expect(regex.isMatchAt('aba', 0)).toBe(true)
|
|
25
|
-
expect(regex.isMatchAt('aba', 1)).toBe(true)
|
|
26
|
-
expect(regex.isMatchAt('aba', 2)).toBe(true)
|
|
27
|
-
expect(regex.isMatchAt('aba', 3)).toBe(false)
|
|
28
|
-
expect(regex.isMatchAt('aba', 100)).toBe(false)
|
|
29
|
-
expect(regex.isMatchAt('def', 0)).toBe(false)
|
|
30
|
-
|
|
31
|
-
const text = 'I categorically deny having triskaidekaphobia.'
|
|
32
|
-
const re = new RRegex('\\b\\w{13}\\b')
|
|
33
|
-
expect(re.isMatchAt(text, 1)).toBe(true)
|
|
34
|
-
expect(re.isMatchAt(text, 5)).toBe(false)
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
test(`find`, () => {
|
|
38
|
-
const regex = new RRegex('a')
|
|
39
|
-
expect(regex.find('abc')).toEqual({ value: 'a', start: 0, end: 1 })
|
|
40
|
-
expect(regex.find('def')).toBeUndefined()
|
|
41
|
-
|
|
42
|
-
const text = 'I categorically deny having triskaidekaphobia.'
|
|
43
|
-
const re = new RRegex('\\b\\w{13}\\b')
|
|
44
|
-
expect(re.find(text)).toEqual({
|
|
45
|
-
value: 'categorically',
|
|
46
|
-
start: 2,
|
|
47
|
-
end: 15,
|
|
48
|
-
})
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
test(`findAt`, () => {
|
|
52
|
-
const regex = new RRegex('a')
|
|
53
|
-
expect(regex.find('abc')).toEqual({ value: 'a', start: 0, end: 1 })
|
|
54
|
-
expect(regex.findAt('abc', 1)).toBeUndefined()
|
|
55
|
-
expect(regex.findAt('abc', 100)).toBeUndefined()
|
|
56
|
-
expect(regex.find('def')).toBeUndefined()
|
|
57
|
-
|
|
58
|
-
const text = 'I categorically deny having triskaidekaphobia.'
|
|
59
|
-
const re = new RRegex('\\b\\w{13}\\b')
|
|
60
|
-
expect(re.findAt(text, 1)).toEqual({
|
|
61
|
-
value: 'categorically',
|
|
62
|
-
start: 2,
|
|
63
|
-
end: 15,
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
expect(re.findAt(text, 5)).toEqual(undefined)
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
test(`findAll`, () => {
|
|
70
|
-
const regex = new RRegex('a')
|
|
71
|
-
expect(regex.findAll('abcabcabc')).toEqual([
|
|
72
|
-
{ value: 'a', start: 0, end: 1 },
|
|
73
|
-
{ value: 'a', start: 3, end: 4 },
|
|
74
|
-
{ value: 'a', start: 6, end: 7 },
|
|
75
|
-
])
|
|
76
|
-
expect(regex.findAll('def')).toEqual([])
|
|
77
|
-
|
|
78
|
-
const text = 'Retroactively relinquishing remunerations is reprehensible.'
|
|
79
|
-
const re = new RRegex('\\b\\w{13}\\b')
|
|
80
|
-
expect(re.findAll(text)).toEqual([
|
|
81
|
-
{
|
|
82
|
-
"end": 13,
|
|
83
|
-
"start": 0,
|
|
84
|
-
"value": "Retroactively",
|
|
85
|
-
},
|
|
86
|
-
{
|
|
87
|
-
"end": 27,
|
|
88
|
-
"start": 14,
|
|
89
|
-
"value": "relinquishing",
|
|
90
|
-
},
|
|
91
|
-
{
|
|
92
|
-
"end": 41,
|
|
93
|
-
"start": 28,
|
|
94
|
-
"value": "remunerations",
|
|
95
|
-
},
|
|
96
|
-
{
|
|
97
|
-
"end": 58,
|
|
98
|
-
"start": 45,
|
|
99
|
-
"value": "reprehensible",
|
|
100
|
-
},
|
|
101
|
-
])
|
|
102
|
-
})
|
|
103
|
-
|
|
104
|
-
test(`replace`, () => {
|
|
105
|
-
const regex = new RRegex('a')
|
|
106
|
-
expect(regex.replace('abcabcabc', 'z')).toEqual('zbcabcabc')
|
|
107
|
-
expect(regex.replace('defdefdef', 'z')).toEqual('defdefdef')
|
|
108
|
-
|
|
109
|
-
{
|
|
110
|
-
const re = new RRegex('[^01]+')
|
|
111
|
-
expect(re.replace('1078910', '')).toBe('1010')
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
{
|
|
115
|
-
const re = new RRegex('(?P<last>[^,\\s]+),\\s+(?P<first>\\S+)')
|
|
116
|
-
const result = re.replace('Springsteen, Bruce', '$first $last')
|
|
117
|
-
expect(result).toEqual('Bruce Springsteen')
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
{
|
|
121
|
-
const re = new RRegex('(?P<first>\\w+)\\s+(?P<second>\\w+)')
|
|
122
|
-
const result = re.replace("deep fried", "${first}_$second");
|
|
123
|
-
expect(result).toEqual('deep_fried')
|
|
124
|
-
}
|
|
125
|
-
})
|
|
126
|
-
|
|
127
|
-
test(`replaceAll`, () => {
|
|
128
|
-
const regex = new RRegex('a')
|
|
129
|
-
expect(regex.replaceAll('abcabcabc', 'z')).toEqual('zbczbczbc')
|
|
130
|
-
expect(regex.replaceAll('defdefdef', 'z')).toEqual('defdefdef')
|
|
131
|
-
})
|
|
132
|
-
|
|
133
|
-
test(`replacen`, () => {
|
|
134
|
-
const regex = new RRegex('a')
|
|
135
|
-
expect(regex.replacen('abcabcabc', 2, 'z')).toEqual('zbczbcabc')
|
|
136
|
-
expect(regex.replacen('defdefdef', 2, 'z')).toEqual('defdefdef')
|
|
137
|
-
})
|
|
138
|
-
|
|
139
|
-
test(`split`, () => {
|
|
140
|
-
const regex = new RRegex('a')
|
|
141
|
-
expect(regex.split('abcabcabc')).toEqual(['', 'bc', 'bc', 'bc'])
|
|
142
|
-
expect(regex.split('defdefdef')).toEqual(['defdefdef'])
|
|
143
|
-
|
|
144
|
-
const re = new RRegex('[ \\t]+')
|
|
145
|
-
const fields = re.split('a b \t c\td e');
|
|
146
|
-
expect(fields).toEqual(['a', 'b', 'c', 'd', 'e']);
|
|
147
|
-
})
|
|
148
|
-
|
|
149
|
-
test(`splitn`, () => {
|
|
150
|
-
const regex = new RRegex('a')
|
|
151
|
-
expect(regex.splitn('abcabcabc', 0)).toEqual([])
|
|
152
|
-
expect(regex.splitn('abcabcabc', 1)).toEqual(['abcabcabc'])
|
|
153
|
-
expect(regex.splitn('abcabcabc', 2)).toEqual(['', 'bcabcabc'])
|
|
154
|
-
expect(regex.splitn('abcabcabc', 3)).toEqual(['', 'bc', 'bcabc'])
|
|
155
|
-
expect(regex.splitn('abcabcabc', 4)).toEqual(['', 'bc', 'bc', 'bc'])
|
|
156
|
-
expect(regex.splitn('abcabcabc', 5)).toEqual(['', 'bc', 'bc', 'bc'])
|
|
157
|
-
expect(regex.splitn('defdefdef', 2)).toEqual(['defdefdef'])
|
|
158
|
-
|
|
159
|
-
const re = new RRegex('\\W+')
|
|
160
|
-
const fields = re.splitn('Hey! How are you?', 3)
|
|
161
|
-
expect(fields).toEqual(['Hey', 'How', 'are you?'])
|
|
162
|
-
})
|
|
163
|
-
|
|
164
|
-
test(`shortestMatch`, () => {
|
|
165
|
-
const regex = new RRegex('a')
|
|
166
|
-
expect(regex.shortestMatch('abcabcabc')).toEqual(1)
|
|
167
|
-
expect(regex.shortestMatch('bcabcabc')).toEqual(3)
|
|
168
|
-
expect(regex.shortestMatch('cabcabc')).toEqual(2)
|
|
169
|
-
expect(regex.shortestMatch('defdefdef')).toBeUndefined()
|
|
170
|
-
|
|
171
|
-
const text = 'aaaaa'
|
|
172
|
-
const pos = new RRegex('a+')
|
|
173
|
-
expect(pos.shortestMatch(text)).toBe(1)
|
|
174
|
-
})
|
|
175
|
-
|
|
176
|
-
test(`shortestMatchAt`, () => {
|
|
177
|
-
const regex = new RRegex('a')
|
|
178
|
-
expect(regex.shortestMatchAt('abcabca', 0)).toEqual(1)
|
|
179
|
-
expect(regex.shortestMatchAt('abcabca', 1)).toEqual(4)
|
|
180
|
-
expect(regex.shortestMatchAt('abcabca', 2)).toEqual(4)
|
|
181
|
-
expect(regex.shortestMatchAt('abcabca', 3)).toEqual(4)
|
|
182
|
-
expect(regex.shortestMatchAt('abcabca', 4)).toEqual(7)
|
|
183
|
-
expect(regex.shortestMatchAt('abcabca', 5)).toEqual(7)
|
|
184
|
-
expect(regex.shortestMatchAt('abcabca', 6)).toEqual(7)
|
|
185
|
-
expect(regex.shortestMatchAt('abcabca', 7)).toBeUndefined()
|
|
186
|
-
expect(regex.shortestMatchAt('abcabca', 100)).toBeUndefined()
|
|
187
|
-
expect(regex.shortestMatchAt('defdefdef', 0)).toBeUndefined()
|
|
188
|
-
expect(regex.shortestMatchAt('defdefdef', 1)).toBeUndefined()
|
|
189
|
-
expect(regex.shortestMatchAt('defdefdef', 2)).toBeUndefined()
|
|
190
|
-
})
|
|
191
|
-
|
|
192
|
-
test(`syntax`, () => {
|
|
193
|
-
const regex = new RRegex('a')
|
|
194
|
-
expect(regex.syntax()).toEqual({
|
|
195
|
-
"@name": "regex_syntax::hir::Hir",
|
|
196
|
-
"@type": "struct",
|
|
197
|
-
"kind": {
|
|
198
|
-
"@name": "regex_syntax::hir::HirKind",
|
|
199
|
-
"@type": "enum",
|
|
200
|
-
"@variant": "Literal",
|
|
201
|
-
"value": {
|
|
202
|
-
"@name": "regex_syntax::hir::Literal",
|
|
203
|
-
"@type": "enum",
|
|
204
|
-
"@variant": "Unicode",
|
|
205
|
-
"value": "a"
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
})
|
|
209
|
-
})
|
|
210
|
-
})
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
describe(`RRegexSet`, () => {
|
|
214
|
-
test(`isMatch`, () => {
|
|
215
|
-
let set = new RRegexSet(['\\w+', '\\d+'])
|
|
216
|
-
expect(set.isMatch('foo')).toBe(true)
|
|
217
|
-
expect(set.isMatch('☃')).toBe(false)
|
|
218
|
-
})
|
|
219
|
-
|
|
220
|
-
test(`matches`, () => {
|
|
221
|
-
let set = new RRegexSet([
|
|
222
|
-
'\\w+',
|
|
223
|
-
'\\d+',
|
|
224
|
-
'\\pL+',
|
|
225
|
-
'foo',
|
|
226
|
-
'bar',
|
|
227
|
-
'barfoo',
|
|
228
|
-
'foobar',
|
|
229
|
-
])
|
|
230
|
-
expect(set.matches('foobar')).toEqual([0, 2, 3, 4, 6])
|
|
231
|
-
})
|
|
232
|
-
})
|