rregex 1.1.3 → 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} +224 -253
- package/lib/cf.mjs +20 -0
- package/lib/commonjs.cjs +609 -0
- package/lib/{commonjs.d.ts → commonjs.d.cts} +186 -229
- package/lib/esm.d.ts +456 -0
- 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 +224 -253
- 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.d.ts +0 -512
- package/lib/module.js +0 -628
package/lib/esm.mjs
ADDED
|
@@ -0,0 +1,611 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );
|
|
5
|
+
|
|
6
|
+
if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); };
|
|
7
|
+
|
|
8
|
+
let cachedUint8ArrayMemory0 = null;
|
|
9
|
+
|
|
10
|
+
function getUint8ArrayMemory0() {
|
|
11
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
12
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
13
|
+
}
|
|
14
|
+
return cachedUint8ArrayMemory0;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function getStringFromWasm0(ptr, len) {
|
|
18
|
+
ptr = ptr >>> 0;
|
|
19
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function addToExternrefTable0(obj) {
|
|
23
|
+
const idx = wasm.__externref_table_alloc();
|
|
24
|
+
wasm.__wbindgen_export_2.set(idx, obj);
|
|
25
|
+
return idx;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function handleError(f, args) {
|
|
29
|
+
try {
|
|
30
|
+
return f.apply(this, args);
|
|
31
|
+
} catch (e) {
|
|
32
|
+
const idx = addToExternrefTable0(e);
|
|
33
|
+
wasm.__wbindgen_exn_store(idx);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function debugString(val) {
|
|
38
|
+
// primitive types
|
|
39
|
+
const type = typeof val;
|
|
40
|
+
if (type == 'number' || type == 'boolean' || val == null) {
|
|
41
|
+
return `${val}`;
|
|
42
|
+
}
|
|
43
|
+
if (type == 'string') {
|
|
44
|
+
return `"${val}"`;
|
|
45
|
+
}
|
|
46
|
+
if (type == 'symbol') {
|
|
47
|
+
const description = val.description;
|
|
48
|
+
if (description == null) {
|
|
49
|
+
return 'Symbol';
|
|
50
|
+
} else {
|
|
51
|
+
return `Symbol(${description})`;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (type == 'function') {
|
|
55
|
+
const name = val.name;
|
|
56
|
+
if (typeof name == 'string' && name.length > 0) {
|
|
57
|
+
return `Function(${name})`;
|
|
58
|
+
} else {
|
|
59
|
+
return 'Function';
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
// objects
|
|
63
|
+
if (Array.isArray(val)) {
|
|
64
|
+
const length = val.length;
|
|
65
|
+
let debug = '[';
|
|
66
|
+
if (length > 0) {
|
|
67
|
+
debug += debugString(val[0]);
|
|
68
|
+
}
|
|
69
|
+
for(let i = 1; i < length; i++) {
|
|
70
|
+
debug += ', ' + debugString(val[i]);
|
|
71
|
+
}
|
|
72
|
+
debug += ']';
|
|
73
|
+
return debug;
|
|
74
|
+
}
|
|
75
|
+
// Test for built-in
|
|
76
|
+
const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
|
|
77
|
+
let className;
|
|
78
|
+
if (builtInMatches && builtInMatches.length > 1) {
|
|
79
|
+
className = builtInMatches[1];
|
|
80
|
+
} else {
|
|
81
|
+
// Failed to match the standard '[object ClassName]'
|
|
82
|
+
return toString.call(val);
|
|
83
|
+
}
|
|
84
|
+
if (className == 'Object') {
|
|
85
|
+
// we're a user defined class or Object
|
|
86
|
+
// JSON.stringify avoids problems with cycles, and is generally much
|
|
87
|
+
// easier than looping through ownProperties of `val`.
|
|
88
|
+
try {
|
|
89
|
+
return 'Object(' + JSON.stringify(val) + ')';
|
|
90
|
+
} catch (_) {
|
|
91
|
+
return 'Object';
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
// errors
|
|
95
|
+
if (val instanceof Error) {
|
|
96
|
+
return `${val.name}: ${val.message}
|
|
97
|
+
${val.stack}`;
|
|
98
|
+
}
|
|
99
|
+
// TODO we could test for more things here, like `Set`s and `Map`s.
|
|
100
|
+
return className;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
let WASM_VECTOR_LEN = 0;
|
|
104
|
+
|
|
105
|
+
const cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder('utf-8') : { encode: () => { throw Error('TextEncoder not available') } } );
|
|
106
|
+
|
|
107
|
+
const encodeString = function (arg, view) {
|
|
108
|
+
return cachedTextEncoder.encodeInto(arg, view);
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
112
|
+
|
|
113
|
+
if (realloc === undefined) {
|
|
114
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
115
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
116
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
117
|
+
WASM_VECTOR_LEN = buf.length;
|
|
118
|
+
return ptr;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
let len = arg.length;
|
|
122
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
123
|
+
|
|
124
|
+
const mem = getUint8ArrayMemory0();
|
|
125
|
+
|
|
126
|
+
let offset = 0;
|
|
127
|
+
|
|
128
|
+
for (; offset < len; offset++) {
|
|
129
|
+
const code = arg.charCodeAt(offset);
|
|
130
|
+
if (code > 0x7F) break;
|
|
131
|
+
mem[ptr + offset] = code;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (offset !== len) {
|
|
135
|
+
if (offset !== 0) {
|
|
136
|
+
arg = arg.slice(offset);
|
|
137
|
+
}
|
|
138
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
139
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
140
|
+
const ret = encodeString(arg, view);
|
|
141
|
+
|
|
142
|
+
offset += ret.written;
|
|
143
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
WASM_VECTOR_LEN = offset;
|
|
147
|
+
return ptr;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
let cachedDataViewMemory0 = null;
|
|
151
|
+
|
|
152
|
+
function getDataViewMemory0() {
|
|
153
|
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
154
|
+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
155
|
+
}
|
|
156
|
+
return cachedDataViewMemory0;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function isLikeNone(x) {
|
|
160
|
+
return x === undefined || x === null;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* @param {string} text
|
|
164
|
+
* @returns {string}
|
|
165
|
+
*/
|
|
166
|
+
export function escape(text) {
|
|
167
|
+
let deferred2_0;
|
|
168
|
+
let deferred2_1;
|
|
169
|
+
try {
|
|
170
|
+
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
171
|
+
const len0 = WASM_VECTOR_LEN;
|
|
172
|
+
const ret = wasm.escape(ptr0, len0);
|
|
173
|
+
deferred2_0 = ret[0];
|
|
174
|
+
deferred2_1 = ret[1];
|
|
175
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
176
|
+
} finally {
|
|
177
|
+
wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function takeFromExternrefTable0(idx) {
|
|
182
|
+
const value = wasm.__wbindgen_export_2.get(idx);
|
|
183
|
+
wasm.__externref_table_dealloc(idx);
|
|
184
|
+
return value;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const RRegexFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
188
|
+
? { register: () => {}, unregister: () => {} }
|
|
189
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_rregex_free(ptr >>> 0, 1));
|
|
190
|
+
/**
|
|
191
|
+
* A compiled regular expression for matching Unicode strings.
|
|
192
|
+
* @see https://docs.rs/regex/latest/regex/
|
|
193
|
+
*/
|
|
194
|
+
export class RRegex {
|
|
195
|
+
|
|
196
|
+
__destroy_into_raw() {
|
|
197
|
+
const ptr = this.__wbg_ptr;
|
|
198
|
+
this.__wbg_ptr = 0;
|
|
199
|
+
RRegexFinalization.unregister(this);
|
|
200
|
+
return ptr;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
free() {
|
|
204
|
+
const ptr = this.__destroy_into_raw();
|
|
205
|
+
wasm.__wbg_rregex_free(ptr, 0);
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Returns the same as is_match, but starts the search at the given offset.
|
|
209
|
+
* The significance of the starting point is that it takes the surrounding context into consideration. For example, the `\A` anchor can only match when `start == 0`.
|
|
210
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.is_match_at
|
|
211
|
+
* @param {string} text
|
|
212
|
+
* @param {number} start
|
|
213
|
+
* @returns {boolean}
|
|
214
|
+
*/
|
|
215
|
+
isMatchAt(text, start) {
|
|
216
|
+
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
217
|
+
const len0 = WASM_VECTOR_LEN;
|
|
218
|
+
const ret = wasm.rregex_isMatchAt(this.__wbg_ptr, ptr0, len0, start);
|
|
219
|
+
return ret !== 0;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Replaces all non-overlapping matches in `text` with the replacement provided. This is the same as calling `replacen` with `limit` set to `0`.
|
|
223
|
+
* See the documentation for `replace` for details on how to access capturing group matches in the replacement string.
|
|
224
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replace_all
|
|
225
|
+
* @param {string} text
|
|
226
|
+
* @param {string} rep
|
|
227
|
+
* @returns {string}
|
|
228
|
+
*/
|
|
229
|
+
replaceAll(text, rep) {
|
|
230
|
+
let deferred3_0;
|
|
231
|
+
let deferred3_1;
|
|
232
|
+
try {
|
|
233
|
+
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
234
|
+
const len0 = WASM_VECTOR_LEN;
|
|
235
|
+
const ptr1 = passStringToWasm0(rep, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
236
|
+
const len1 = WASM_VECTOR_LEN;
|
|
237
|
+
const ret = wasm.rregex_replaceAll(this.__wbg_ptr, ptr0, len0, ptr1, len1);
|
|
238
|
+
deferred3_0 = ret[0];
|
|
239
|
+
deferred3_1 = ret[1];
|
|
240
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
241
|
+
} finally {
|
|
242
|
+
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Returns the end location of a match in the text given.
|
|
247
|
+
* 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.
|
|
248
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.shortest_match
|
|
249
|
+
* @param {string} text
|
|
250
|
+
* @returns {number | undefined}
|
|
251
|
+
*/
|
|
252
|
+
shortestMatch(text) {
|
|
253
|
+
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
254
|
+
const len0 = WASM_VECTOR_LEN;
|
|
255
|
+
const ret = wasm.rregex_shortestMatch(this.__wbg_ptr, ptr0, len0);
|
|
256
|
+
return ret === 0x100000001 ? undefined : ret;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Returns the same as shortest_match, but starts the search at the given offset.
|
|
260
|
+
* The significance of the starting point is that it takes the surrounding context into consideration. For example, the \A anchor can only match when `start == 0`.
|
|
261
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.shortest_match_at
|
|
262
|
+
* @param {string} text
|
|
263
|
+
* @param {number} limit
|
|
264
|
+
* @returns {number | undefined}
|
|
265
|
+
*/
|
|
266
|
+
shortestMatchAt(text, limit) {
|
|
267
|
+
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
268
|
+
const len0 = WASM_VECTOR_LEN;
|
|
269
|
+
const ret = wasm.rregex_shortestMatchAt(this.__wbg_ptr, ptr0, len0, limit);
|
|
270
|
+
return ret === 0x100000001 ? undefined : ret;
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Compiles a regular expression. Once compiled, it can be used repeatedly to search, split or replace text in a string.
|
|
274
|
+
* If an invalid expression is given, then an error is returned.
|
|
275
|
+
* @param {string} re
|
|
276
|
+
*/
|
|
277
|
+
constructor(re) {
|
|
278
|
+
const ptr0 = passStringToWasm0(re, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
279
|
+
const len0 = WASM_VECTOR_LEN;
|
|
280
|
+
const ret = wasm.rregex_new(ptr0, len0);
|
|
281
|
+
if (ret[2]) {
|
|
282
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
283
|
+
}
|
|
284
|
+
this.__wbg_ptr = ret[0] >>> 0;
|
|
285
|
+
RRegexFinalization.register(this, this.__wbg_ptr, this);
|
|
286
|
+
return this;
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Returns the start and end byte range of the leftmost-first match in `text`. If no match exists, then `undefined` is returned.
|
|
290
|
+
* Note that this should only be used if you want to discover the position of the match. Testing the existence of a match is faster if you use `is_match`.
|
|
291
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find
|
|
292
|
+
* @param {string} text
|
|
293
|
+
* @returns {any}
|
|
294
|
+
*/
|
|
295
|
+
find(text) {
|
|
296
|
+
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
297
|
+
const len0 = WASM_VECTOR_LEN;
|
|
298
|
+
const ret = wasm.rregex_find(this.__wbg_ptr, ptr0, len0);
|
|
299
|
+
return ret;
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* 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.
|
|
303
|
+
* This method will not copy the text given.
|
|
304
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.split
|
|
305
|
+
* @param {string} text
|
|
306
|
+
* @returns {any}
|
|
307
|
+
*/
|
|
308
|
+
split(text) {
|
|
309
|
+
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
310
|
+
const len0 = WASM_VECTOR_LEN;
|
|
311
|
+
const ret = wasm.rregex_split(this.__wbg_ptr, ptr0, len0);
|
|
312
|
+
return ret;
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* 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.
|
|
316
|
+
* This method will not copy the text given.
|
|
317
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.splitn
|
|
318
|
+
* @param {string} text
|
|
319
|
+
* @param {number} limit
|
|
320
|
+
* @returns {any}
|
|
321
|
+
*/
|
|
322
|
+
splitn(text, limit) {
|
|
323
|
+
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
324
|
+
const len0 = WASM_VECTOR_LEN;
|
|
325
|
+
const ret = wasm.rregex_splitn(this.__wbg_ptr, ptr0, len0, limit);
|
|
326
|
+
return ret;
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Return the Regex syntax object
|
|
330
|
+
* @returns {any}
|
|
331
|
+
*/
|
|
332
|
+
syntax() {
|
|
333
|
+
const ret = wasm.rregex_syntax(this.__wbg_ptr);
|
|
334
|
+
return ret;
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Returns the same as find, but starts the search at the given offset.
|
|
338
|
+
* The significance of the starting point is that it takes the surrounding context into consideration. For example, the \A anchor can only match when `start == 0`.
|
|
339
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find_at
|
|
340
|
+
* @param {string} text
|
|
341
|
+
* @param {number} start
|
|
342
|
+
* @returns {any}
|
|
343
|
+
*/
|
|
344
|
+
findAt(text, start) {
|
|
345
|
+
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
346
|
+
const len0 = WASM_VECTOR_LEN;
|
|
347
|
+
const ret = wasm.rregex_findAt(this.__wbg_ptr, ptr0, len0, start);
|
|
348
|
+
return ret;
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Replaces the leftmost-first match with the replacement provided.
|
|
352
|
+
* The replacement can be a regular string (where `$N` and `$name` are expanded to match capture groups) or a function that takes the matches’ `Captures` and returns the replaced string.
|
|
353
|
+
* If no match is found, then a copy of the string is returned unchanged.
|
|
354
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replace
|
|
355
|
+
* @param {string} text
|
|
356
|
+
* @param {string} rep
|
|
357
|
+
* @returns {string}
|
|
358
|
+
*/
|
|
359
|
+
replace(text, rep) {
|
|
360
|
+
let deferred3_0;
|
|
361
|
+
let deferred3_1;
|
|
362
|
+
try {
|
|
363
|
+
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
364
|
+
const len0 = WASM_VECTOR_LEN;
|
|
365
|
+
const ptr1 = passStringToWasm0(rep, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
366
|
+
const len1 = WASM_VECTOR_LEN;
|
|
367
|
+
const ret = wasm.rregex_replace(this.__wbg_ptr, ptr0, len0, ptr1, len1);
|
|
368
|
+
deferred3_0 = ret[0];
|
|
369
|
+
deferred3_1 = ret[1];
|
|
370
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
371
|
+
} finally {
|
|
372
|
+
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Returns an array for each successive non-overlapping match in text, returning the start and end byte indices with respect to text.
|
|
377
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find_iter
|
|
378
|
+
* @param {string} text
|
|
379
|
+
* @returns {any}
|
|
380
|
+
*/
|
|
381
|
+
findAll(text) {
|
|
382
|
+
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
383
|
+
const len0 = WASM_VECTOR_LEN;
|
|
384
|
+
const ret = wasm.rregex_findAll(this.__wbg_ptr, ptr0, len0);
|
|
385
|
+
return ret;
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* Returns true if and only if there is a match for the regex in the string given.
|
|
389
|
+
* It is recommended to use this method if all you need to do is test a match, since the underlying matching engine may be able to do less work.
|
|
390
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.is_match
|
|
391
|
+
* @param {string} text
|
|
392
|
+
* @returns {boolean}
|
|
393
|
+
*/
|
|
394
|
+
isMatch(text) {
|
|
395
|
+
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
396
|
+
const len0 = WASM_VECTOR_LEN;
|
|
397
|
+
const ret = wasm.rregex_isMatch(this.__wbg_ptr, ptr0, len0);
|
|
398
|
+
return ret !== 0;
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Replaces at most `limit` non-overlapping matches in `text` with the replacement provided. If `limit` is 0, then all non-overlapping matches are replaced.
|
|
402
|
+
* See the documentation for `replace` for details on how to access capturing group matches in the replacement string.
|
|
403
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replacen
|
|
404
|
+
* @param {string} text
|
|
405
|
+
* @param {number} limit
|
|
406
|
+
* @param {string} rep
|
|
407
|
+
* @returns {string}
|
|
408
|
+
*/
|
|
409
|
+
replacen(text, limit, rep) {
|
|
410
|
+
let deferred3_0;
|
|
411
|
+
let deferred3_1;
|
|
412
|
+
try {
|
|
413
|
+
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
414
|
+
const len0 = WASM_VECTOR_LEN;
|
|
415
|
+
const ptr1 = passStringToWasm0(rep, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
416
|
+
const len1 = WASM_VECTOR_LEN;
|
|
417
|
+
const ret = wasm.rregex_replacen(this.__wbg_ptr, ptr0, len0, limit, ptr1, len1);
|
|
418
|
+
deferred3_0 = ret[0];
|
|
419
|
+
deferred3_1 = ret[1];
|
|
420
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
421
|
+
} finally {
|
|
422
|
+
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* Returns a string representing the regular expression
|
|
427
|
+
* @returns {string}
|
|
428
|
+
*/
|
|
429
|
+
toString() {
|
|
430
|
+
let deferred1_0;
|
|
431
|
+
let deferred1_1;
|
|
432
|
+
try {
|
|
433
|
+
const ret = wasm.rregex_toString(this.__wbg_ptr);
|
|
434
|
+
deferred1_0 = ret[0];
|
|
435
|
+
deferred1_1 = ret[1];
|
|
436
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
437
|
+
} finally {
|
|
438
|
+
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
const RRegexSetFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
444
|
+
? { register: () => {}, unregister: () => {} }
|
|
445
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_rregexset_free(ptr >>> 0, 1));
|
|
446
|
+
/**
|
|
447
|
+
* Match multiple (possibly overlapping) regular expressions in a single scan.
|
|
448
|
+
* A regex set corresponds to the union of two or more regular expressions. That is, a regex set will match text where at least one of its constituent regular expressions matches. A regex set as its formulated here provides a touch more power: it will also report which regular expressions in the set match. Indeed, this is the key difference between regex sets and a single `Regex` with many alternates, since only one alternate can match at a time.
|
|
449
|
+
* @see https://docs.rs/regex/latest/regex/struct.RegexSet.html#method.empty
|
|
450
|
+
*/
|
|
451
|
+
export class RRegexSet {
|
|
452
|
+
|
|
453
|
+
__destroy_into_raw() {
|
|
454
|
+
const ptr = this.__wbg_ptr;
|
|
455
|
+
this.__wbg_ptr = 0;
|
|
456
|
+
RRegexSetFinalization.unregister(this);
|
|
457
|
+
return ptr;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
free() {
|
|
461
|
+
const ptr = this.__destroy_into_raw();
|
|
462
|
+
wasm.__wbg_rregexset_free(ptr, 0);
|
|
463
|
+
}
|
|
464
|
+
/**
|
|
465
|
+
* Create a new regex set with the given regular expressions.
|
|
466
|
+
* @param {Array<any>} list
|
|
467
|
+
*/
|
|
468
|
+
constructor(list) {
|
|
469
|
+
const ret = wasm.rregexset_new(list);
|
|
470
|
+
if (ret[2]) {
|
|
471
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
472
|
+
}
|
|
473
|
+
this.__wbg_ptr = ret[0] >>> 0;
|
|
474
|
+
RRegexSetFinalization.register(this, this.__wbg_ptr, this);
|
|
475
|
+
return this;
|
|
476
|
+
}
|
|
477
|
+
/**
|
|
478
|
+
* Returns the set of regular expressions that match in the given text.
|
|
479
|
+
* The set returned contains the index of each regular expression that matches in the given text. The index is in correspondence with the order of regular expressions given to RegexSet’s constructor.
|
|
480
|
+
* the set can also be used to iterate over the matched indices.
|
|
481
|
+
* @param {string} text
|
|
482
|
+
* @returns {any}
|
|
483
|
+
*/
|
|
484
|
+
matches(text) {
|
|
485
|
+
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
486
|
+
const len0 = WASM_VECTOR_LEN;
|
|
487
|
+
const ret = wasm.rregexset_matches(this.__wbg_ptr, ptr0, len0);
|
|
488
|
+
return ret;
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* Returns true if and only if one of the regexes in this set matches the text given.
|
|
492
|
+
* This method should be preferred if you only need to test whether any of the regexes in the set should match, but don’t care about which regexes matched. This is because the underlying matching engine will quit immediately after seeing the first match instead of continuing to find all matches.
|
|
493
|
+
* @see https://docs.rs/regex/latest/regex/struct.RegexSet.html#method.is_match
|
|
494
|
+
* @param {string} text
|
|
495
|
+
* @returns {boolean}
|
|
496
|
+
*/
|
|
497
|
+
isMatch(text) {
|
|
498
|
+
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
499
|
+
const len0 = WASM_VECTOR_LEN;
|
|
500
|
+
const ret = wasm.rregexset_isMatch(this.__wbg_ptr, ptr0, len0);
|
|
501
|
+
return ret !== 0;
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
const imports = {
|
|
506
|
+
wbg: {
|
|
507
|
+
__wbg_get_b9b93047fe3cf45b: function(arg0, arg1) {
|
|
508
|
+
const ret = arg0[arg1 >>> 0];
|
|
509
|
+
return ret;
|
|
510
|
+
},
|
|
511
|
+
__wbg_length_e2d2a49132c1b256: function(arg0) {
|
|
512
|
+
const ret = arg0.length;
|
|
513
|
+
return ret;
|
|
514
|
+
},
|
|
515
|
+
__wbg_new_405e22f390576ce2: function() {
|
|
516
|
+
const ret = new Object();
|
|
517
|
+
return ret;
|
|
518
|
+
},
|
|
519
|
+
__wbg_new_78feb108b6472713: function() {
|
|
520
|
+
const ret = new Array();
|
|
521
|
+
return ret;
|
|
522
|
+
},
|
|
523
|
+
__wbg_new_c68d7209be747379: function(arg0, arg1) {
|
|
524
|
+
const ret = new Error(getStringFromWasm0(arg0, arg1));
|
|
525
|
+
return ret;
|
|
526
|
+
},
|
|
527
|
+
__wbg_push_737cfc8c1432c2c6: function(arg0, arg1) {
|
|
528
|
+
const ret = arg0.push(arg1);
|
|
529
|
+
return ret;
|
|
530
|
+
},
|
|
531
|
+
__wbg_set_bb8cecf6a62b9f46: function() { return handleError(function (arg0, arg1, arg2) {
|
|
532
|
+
const ret = Reflect.set(arg0, arg1, arg2);
|
|
533
|
+
return ret;
|
|
534
|
+
}, arguments) },
|
|
535
|
+
__wbindgen_debug_string: function(arg0, arg1) {
|
|
536
|
+
const ret = debugString(arg1);
|
|
537
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
538
|
+
const len1 = WASM_VECTOR_LEN;
|
|
539
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
540
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
541
|
+
},
|
|
542
|
+
__wbindgen_init_externref_table: function() {
|
|
543
|
+
const table = wasm.__wbindgen_export_2;
|
|
544
|
+
const offset = table.grow(4);
|
|
545
|
+
table.set(0, undefined);
|
|
546
|
+
table.set(offset + 0, undefined);
|
|
547
|
+
table.set(offset + 1, null);
|
|
548
|
+
table.set(offset + 2, true);
|
|
549
|
+
table.set(offset + 3, false);
|
|
550
|
+
;
|
|
551
|
+
},
|
|
552
|
+
__wbindgen_is_string: function(arg0) {
|
|
553
|
+
const ret = typeof(arg0) === 'string';
|
|
554
|
+
return ret;
|
|
555
|
+
},
|
|
556
|
+
__wbindgen_number_new: function(arg0) {
|
|
557
|
+
const ret = arg0;
|
|
558
|
+
return ret;
|
|
559
|
+
},
|
|
560
|
+
__wbindgen_string_get: function(arg0, arg1) {
|
|
561
|
+
const obj = arg1;
|
|
562
|
+
const ret = typeof(obj) === 'string' ? obj : undefined;
|
|
563
|
+
var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
564
|
+
var len1 = WASM_VECTOR_LEN;
|
|
565
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
566
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
567
|
+
},
|
|
568
|
+
__wbindgen_string_new: function(arg0, arg1) {
|
|
569
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
570
|
+
return ret;
|
|
571
|
+
},
|
|
572
|
+
__wbindgen_throw: function(arg0, arg1) {
|
|
573
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
574
|
+
},
|
|
575
|
+
},
|
|
576
|
+
|
|
577
|
+
};
|
|
578
|
+
|
|
579
|
+
const wasm_url = new URL('rregex.wasm', import.meta.url);
|
|
580
|
+
let wasmCode = '';
|
|
581
|
+
switch (wasm_url.protocol) {
|
|
582
|
+
case 'file:':
|
|
583
|
+
wasmCode = await readFile(wasm_url);
|
|
584
|
+
break
|
|
585
|
+
case 'https:':
|
|
586
|
+
case 'http:':
|
|
587
|
+
wasmCode = await (await fetch(wasm_url)).arrayBuffer();
|
|
588
|
+
break
|
|
589
|
+
default:
|
|
590
|
+
throw new Error(`Unsupported protocol: ${wasm_url.protocol}`);
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
const wasmInstance = (await WebAssembly.instantiate(wasmCode, imports)).instance;
|
|
594
|
+
const wasm = wasmInstance.exports;
|
|
595
|
+
export const __wasm = wasm;
|
|
596
|
+
|
|
597
|
+
wasm.__wbindgen_start();
|
|
598
|
+
|
|
599
|
+
|
|
600
|
+
/** Build metadata */
|
|
601
|
+
export const metadata = {
|
|
602
|
+
"name": "rregex",
|
|
603
|
+
"description": "Rust Regex binding for Javascript",
|
|
604
|
+
"authors": [
|
|
605
|
+
"Fede Ramirez <i@2fd.me>"
|
|
606
|
+
],
|
|
607
|
+
"homepage": "http://rregex.dev",
|
|
608
|
+
"repository": "https://github.com/2fd/rregex",
|
|
609
|
+
"regex": "1.1.9",
|
|
610
|
+
"regex-syntax": "0.6.8"
|
|
611
|
+
}
|
package/lib/rregex.wasm
CHANGED
|
Binary file
|
package/lib/rregex.wasm.d.ts
CHANGED
|
@@ -1,29 +1,32 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
export const memory: WebAssembly.Memory;
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
export
|
|
9
|
-
export
|
|
10
|
-
export
|
|
11
|
-
export
|
|
12
|
-
export
|
|
13
|
-
export
|
|
14
|
-
export
|
|
15
|
-
export
|
|
16
|
-
export
|
|
17
|
-
export
|
|
18
|
-
export
|
|
19
|
-
export
|
|
20
|
-
export
|
|
21
|
-
export
|
|
22
|
-
export
|
|
23
|
-
export
|
|
24
|
-
export
|
|
25
|
-
export
|
|
26
|
-
export
|
|
27
|
-
export
|
|
28
|
-
export
|
|
29
|
-
export
|
|
4
|
+
export const escape: (a: number, b: number) => [number, number];
|
|
5
|
+
export const __wbg_rregex_free: (a: number, b: number) => void;
|
|
6
|
+
export const rregex_find: (a: number, b: number, c: number) => any;
|
|
7
|
+
export const rregex_findAll: (a: number, b: number, c: number) => any;
|
|
8
|
+
export const rregex_findAt: (a: number, b: number, c: number, d: number) => any;
|
|
9
|
+
export const rregex_isMatch: (a: number, b: number, c: number) => number;
|
|
10
|
+
export const rregex_isMatchAt: (a: number, b: number, c: number, d: number) => number;
|
|
11
|
+
export const rregex_new: (a: number, b: number) => [number, number, number];
|
|
12
|
+
export const rregex_replace: (a: number, b: number, c: number, d: number, e: number) => [number, number];
|
|
13
|
+
export const rregex_replaceAll: (a: number, b: number, c: number, d: number, e: number) => [number, number];
|
|
14
|
+
export const rregex_replacen: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number];
|
|
15
|
+
export const rregex_shortestMatch: (a: number, b: number, c: number) => number;
|
|
16
|
+
export const rregex_shortestMatchAt: (a: number, b: number, c: number, d: number) => number;
|
|
17
|
+
export const rregex_split: (a: number, b: number, c: number) => any;
|
|
18
|
+
export const rregex_splitn: (a: number, b: number, c: number, d: number) => any;
|
|
19
|
+
export const rregex_syntax: (a: number) => any;
|
|
20
|
+
export const rregex_toString: (a: number) => [number, number];
|
|
21
|
+
export const __wbg_rregexset_free: (a: number, b: number) => void;
|
|
22
|
+
export const rregexset_isMatch: (a: number, b: number, c: number) => number;
|
|
23
|
+
export const rregexset_matches: (a: number, b: number, c: number) => any;
|
|
24
|
+
export const rregexset_new: (a: any) => [number, number, number];
|
|
25
|
+
export const __wbindgen_exn_store: (a: number) => void;
|
|
26
|
+
export const __externref_table_alloc: () => number;
|
|
27
|
+
export const __wbindgen_export_2: WebAssembly.Table;
|
|
28
|
+
export const __wbindgen_malloc: (a: number, b: number) => number;
|
|
29
|
+
export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
30
|
+
export const __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
31
|
+
export const __externref_table_dealloc: (a: number) => void;
|
|
32
|
+
export const __wbindgen_start: () => void;
|