rregex 1.7.0 → 1.7.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 +79 -190
- package/jsr.json +17 -0
- package/lib/{browser.d.ts → cf.d.ts} +211 -249
- package/lib/cf.mjs +20 -0
- package/lib/commonjs.cjs +609 -0
- package/lib/{commonjs.d.ts → commonjs.d.cts} +179 -222
- 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 +211 -249
- package/lib/web.d.ts +525 -0
- package/lib/web.js +700 -0
- package/package.json +107 -18
- package/lib/browser.js +0 -720
- package/lib/commonjs.js +0 -667
- package/lib/module.js +0 -646
package/lib/browser.js
DELETED
|
@@ -1,720 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
let wasm;
|
|
3
|
-
|
|
4
|
-
const heap = new Array(32).fill(undefined);
|
|
5
|
-
|
|
6
|
-
heap.push(undefined, null, true, false);
|
|
7
|
-
|
|
8
|
-
function getObject(idx) { return heap[idx]; }
|
|
9
|
-
|
|
10
|
-
let heap_next = heap.length;
|
|
11
|
-
|
|
12
|
-
function dropObject(idx) {
|
|
13
|
-
if (idx < 36) return;
|
|
14
|
-
heap[idx] = heap_next;
|
|
15
|
-
heap_next = idx;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function takeObject(idx) {
|
|
19
|
-
const ret = getObject(idx);
|
|
20
|
-
dropObject(idx);
|
|
21
|
-
return ret;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
25
|
-
|
|
26
|
-
cachedTextDecoder.decode();
|
|
27
|
-
|
|
28
|
-
let cachedUint8Memory0;
|
|
29
|
-
function getUint8Memory0() {
|
|
30
|
-
if (cachedUint8Memory0.byteLength === 0) {
|
|
31
|
-
cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);
|
|
32
|
-
}
|
|
33
|
-
return cachedUint8Memory0;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function getStringFromWasm0(ptr, len) {
|
|
37
|
-
return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function addHeapObject(obj) {
|
|
41
|
-
if (heap_next === heap.length) heap.push(heap.length + 1);
|
|
42
|
-
const idx = heap_next;
|
|
43
|
-
heap_next = heap[idx];
|
|
44
|
-
|
|
45
|
-
heap[idx] = obj;
|
|
46
|
-
return idx;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
let WASM_VECTOR_LEN = 0;
|
|
50
|
-
|
|
51
|
-
const cachedTextEncoder = new TextEncoder('utf-8');
|
|
52
|
-
|
|
53
|
-
const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
|
|
54
|
-
? function (arg, view) {
|
|
55
|
-
return cachedTextEncoder.encodeInto(arg, view);
|
|
56
|
-
}
|
|
57
|
-
: function (arg, view) {
|
|
58
|
-
const buf = cachedTextEncoder.encode(arg);
|
|
59
|
-
view.set(buf);
|
|
60
|
-
return {
|
|
61
|
-
read: arg.length,
|
|
62
|
-
written: buf.length
|
|
63
|
-
};
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
function passStringToWasm0(arg, malloc, realloc) {
|
|
67
|
-
|
|
68
|
-
if (realloc === undefined) {
|
|
69
|
-
const buf = cachedTextEncoder.encode(arg);
|
|
70
|
-
const ptr = malloc(buf.length);
|
|
71
|
-
getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
72
|
-
WASM_VECTOR_LEN = buf.length;
|
|
73
|
-
return ptr;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
let len = arg.length;
|
|
77
|
-
let ptr = malloc(len);
|
|
78
|
-
|
|
79
|
-
const mem = getUint8Memory0();
|
|
80
|
-
|
|
81
|
-
let offset = 0;
|
|
82
|
-
|
|
83
|
-
for (; offset < len; offset++) {
|
|
84
|
-
const code = arg.charCodeAt(offset);
|
|
85
|
-
if (code > 0x7F) break;
|
|
86
|
-
mem[ptr + offset] = code;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
if (offset !== len) {
|
|
90
|
-
if (offset !== 0) {
|
|
91
|
-
arg = arg.slice(offset);
|
|
92
|
-
}
|
|
93
|
-
ptr = realloc(ptr, len, len = offset + arg.length * 3);
|
|
94
|
-
const view = getUint8Memory0().subarray(ptr + offset, ptr + len);
|
|
95
|
-
const ret = encodeString(arg, view);
|
|
96
|
-
|
|
97
|
-
offset += ret.written;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
WASM_VECTOR_LEN = offset;
|
|
101
|
-
return ptr;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
function isLikeNone(x) {
|
|
105
|
-
return x === undefined || x === null;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
let cachedInt32Memory0;
|
|
109
|
-
function getInt32Memory0() {
|
|
110
|
-
if (cachedInt32Memory0.byteLength === 0) {
|
|
111
|
-
cachedInt32Memory0 = new Int32Array(wasm.memory.buffer);
|
|
112
|
-
}
|
|
113
|
-
return cachedInt32Memory0;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
function debugString(val) {
|
|
117
|
-
// primitive types
|
|
118
|
-
const type = typeof val;
|
|
119
|
-
if (type == 'number' || type == 'boolean' || val == null) {
|
|
120
|
-
return `${val}`;
|
|
121
|
-
}
|
|
122
|
-
if (type == 'string') {
|
|
123
|
-
return `"${val}"`;
|
|
124
|
-
}
|
|
125
|
-
if (type == 'symbol') {
|
|
126
|
-
const description = val.description;
|
|
127
|
-
if (description == null) {
|
|
128
|
-
return 'Symbol';
|
|
129
|
-
} else {
|
|
130
|
-
return `Symbol(${description})`;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
if (type == 'function') {
|
|
134
|
-
const name = val.name;
|
|
135
|
-
if (typeof name == 'string' && name.length > 0) {
|
|
136
|
-
return `Function(${name})`;
|
|
137
|
-
} else {
|
|
138
|
-
return 'Function';
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
// objects
|
|
142
|
-
if (Array.isArray(val)) {
|
|
143
|
-
const length = val.length;
|
|
144
|
-
let debug = '[';
|
|
145
|
-
if (length > 0) {
|
|
146
|
-
debug += debugString(val[0]);
|
|
147
|
-
}
|
|
148
|
-
for(let i = 1; i < length; i++) {
|
|
149
|
-
debug += ', ' + debugString(val[i]);
|
|
150
|
-
}
|
|
151
|
-
debug += ']';
|
|
152
|
-
return debug;
|
|
153
|
-
}
|
|
154
|
-
// Test for built-in
|
|
155
|
-
const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
|
|
156
|
-
let className;
|
|
157
|
-
if (builtInMatches.length > 1) {
|
|
158
|
-
className = builtInMatches[1];
|
|
159
|
-
} else {
|
|
160
|
-
// Failed to match the standard '[object ClassName]'
|
|
161
|
-
return toString.call(val);
|
|
162
|
-
}
|
|
163
|
-
if (className == 'Object') {
|
|
164
|
-
// we're a user defined class or Object
|
|
165
|
-
// JSON.stringify avoids problems with cycles, and is generally much
|
|
166
|
-
// easier than looping through ownProperties of `val`.
|
|
167
|
-
try {
|
|
168
|
-
return 'Object(' + JSON.stringify(val) + ')';
|
|
169
|
-
} catch (_) {
|
|
170
|
-
return 'Object';
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
// errors
|
|
174
|
-
if (val instanceof Error) {
|
|
175
|
-
return `${val.name}: ${val.message}\n${val.stack}`;
|
|
176
|
-
}
|
|
177
|
-
// TODO we could test for more things here, like `Set`s and `Map`s.
|
|
178
|
-
return className;
|
|
179
|
-
}
|
|
180
|
-
/**
|
|
181
|
-
* @param {string} text
|
|
182
|
-
* @returns {string}
|
|
183
|
-
*/
|
|
184
|
-
export function escape(text) {
|
|
185
|
-
try {
|
|
186
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
187
|
-
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
188
|
-
const len0 = WASM_VECTOR_LEN;
|
|
189
|
-
wasm.escape(retptr, ptr0, len0);
|
|
190
|
-
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
191
|
-
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
192
|
-
return getStringFromWasm0(r0, r1);
|
|
193
|
-
} finally {
|
|
194
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
195
|
-
wasm.__wbindgen_free(r0, r1);
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
let stack_pointer = 32;
|
|
200
|
-
|
|
201
|
-
function addBorrowedObject(obj) {
|
|
202
|
-
if (stack_pointer == 1) throw new Error('out of js stack');
|
|
203
|
-
heap[--stack_pointer] = obj;
|
|
204
|
-
return stack_pointer;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
function handleError(f, args) {
|
|
208
|
-
try {
|
|
209
|
-
return f.apply(this, args);
|
|
210
|
-
} catch (e) {
|
|
211
|
-
wasm.__wbindgen_exn_store(addHeapObject(e));
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
/**
|
|
215
|
-
* A compiled regular expression for matching Unicode strings.
|
|
216
|
-
* @see https://docs.rs/regex/latest/regex/
|
|
217
|
-
*/
|
|
218
|
-
export class RRegex {
|
|
219
|
-
|
|
220
|
-
static __wrap(ptr) {
|
|
221
|
-
const obj = Object.create(RRegex.prototype);
|
|
222
|
-
obj.ptr = ptr;
|
|
223
|
-
|
|
224
|
-
return obj;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
__destroy_into_raw() {
|
|
228
|
-
const ptr = this.ptr;
|
|
229
|
-
this.ptr = 0;
|
|
230
|
-
|
|
231
|
-
return ptr;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
free() {
|
|
235
|
-
const ptr = this.__destroy_into_raw();
|
|
236
|
-
wasm.__wbg_rregex_free(ptr);
|
|
237
|
-
}
|
|
238
|
-
/**
|
|
239
|
-
* Compiles a regular expression. Once compiled, it can be used repeatedly to search, split or replace text in a string.
|
|
240
|
-
* If an invalid expression is given, then an error is returned.
|
|
241
|
-
* @param {string} re
|
|
242
|
-
*/
|
|
243
|
-
constructor(re) {
|
|
244
|
-
try {
|
|
245
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
246
|
-
const ptr0 = passStringToWasm0(re, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
247
|
-
const len0 = WASM_VECTOR_LEN;
|
|
248
|
-
wasm.rregex_new(retptr, ptr0, len0);
|
|
249
|
-
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
250
|
-
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
251
|
-
var r2 = getInt32Memory0()[retptr / 4 + 2];
|
|
252
|
-
if (r2) {
|
|
253
|
-
throw takeObject(r1);
|
|
254
|
-
}
|
|
255
|
-
return RRegex.__wrap(r0);
|
|
256
|
-
} finally {
|
|
257
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
/**
|
|
261
|
-
* Returns true if and only if there is a match for the regex in the string given.
|
|
262
|
-
* 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.
|
|
263
|
-
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.is_match
|
|
264
|
-
* @param {string} text
|
|
265
|
-
* @returns {boolean}
|
|
266
|
-
*/
|
|
267
|
-
isMatch(text) {
|
|
268
|
-
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
269
|
-
const len0 = WASM_VECTOR_LEN;
|
|
270
|
-
const ret = wasm.rregex_isMatch(this.ptr, ptr0, len0);
|
|
271
|
-
return ret !== 0;
|
|
272
|
-
}
|
|
273
|
-
/**
|
|
274
|
-
* Returns the same as is_match, but starts the search at the given offset.
|
|
275
|
-
* 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`.
|
|
276
|
-
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.is_match_at
|
|
277
|
-
* @param {string} text
|
|
278
|
-
* @param {number} start
|
|
279
|
-
* @returns {boolean}
|
|
280
|
-
*/
|
|
281
|
-
isMatchAt(text, start) {
|
|
282
|
-
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
283
|
-
const len0 = WASM_VECTOR_LEN;
|
|
284
|
-
const ret = wasm.rregex_isMatchAt(this.ptr, ptr0, len0, start);
|
|
285
|
-
return ret !== 0;
|
|
286
|
-
}
|
|
287
|
-
/**
|
|
288
|
-
* Returns the start and end byte range of the leftmost-first match in `text`. If no match exists, then `undefined` is returned.
|
|
289
|
-
* 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`.
|
|
290
|
-
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find
|
|
291
|
-
* @param {string} text
|
|
292
|
-
* @returns {any}
|
|
293
|
-
*/
|
|
294
|
-
find(text) {
|
|
295
|
-
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
296
|
-
const len0 = WASM_VECTOR_LEN;
|
|
297
|
-
const ret = wasm.rregex_find(this.ptr, ptr0, len0);
|
|
298
|
-
return takeObject(ret);
|
|
299
|
-
}
|
|
300
|
-
/**
|
|
301
|
-
* Returns the same as find, but starts the search at the given offset.
|
|
302
|
-
* 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`.
|
|
303
|
-
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find_at
|
|
304
|
-
* @param {string} text
|
|
305
|
-
* @param {number} start
|
|
306
|
-
* @returns {any}
|
|
307
|
-
*/
|
|
308
|
-
findAt(text, start) {
|
|
309
|
-
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
310
|
-
const len0 = WASM_VECTOR_LEN;
|
|
311
|
-
const ret = wasm.rregex_findAt(this.ptr, ptr0, len0, start);
|
|
312
|
-
return takeObject(ret);
|
|
313
|
-
}
|
|
314
|
-
/**
|
|
315
|
-
* Returns an array for each successive non-overlapping match in text, returning the start and end byte indices with respect to text.
|
|
316
|
-
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find_iter
|
|
317
|
-
* @param {string} text
|
|
318
|
-
* @returns {any}
|
|
319
|
-
*/
|
|
320
|
-
findAll(text) {
|
|
321
|
-
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
322
|
-
const len0 = WASM_VECTOR_LEN;
|
|
323
|
-
const ret = wasm.rregex_findAll(this.ptr, ptr0, len0);
|
|
324
|
-
return takeObject(ret);
|
|
325
|
-
}
|
|
326
|
-
/**
|
|
327
|
-
* Replaces the leftmost-first match with the replacement provided.
|
|
328
|
-
* 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.
|
|
329
|
-
* If no match is found, then a copy of the string is returned unchanged.
|
|
330
|
-
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replace
|
|
331
|
-
* @param {string} text
|
|
332
|
-
* @param {string} rep
|
|
333
|
-
* @returns {string}
|
|
334
|
-
*/
|
|
335
|
-
replace(text, rep) {
|
|
336
|
-
try {
|
|
337
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
338
|
-
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
339
|
-
const len0 = WASM_VECTOR_LEN;
|
|
340
|
-
const ptr1 = passStringToWasm0(rep, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
341
|
-
const len1 = WASM_VECTOR_LEN;
|
|
342
|
-
wasm.rregex_replace(retptr, this.ptr, ptr0, len0, ptr1, len1);
|
|
343
|
-
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
344
|
-
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
345
|
-
return getStringFromWasm0(r0, r1);
|
|
346
|
-
} finally {
|
|
347
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
348
|
-
wasm.__wbindgen_free(r0, r1);
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
/**
|
|
352
|
-
* Replaces at most `limit` non-overlapping matches in `text` with the replacement provided. If `limit` is 0, then all non-overlapping matches are replaced.
|
|
353
|
-
* See the documentation for `replace` for details on how to access capturing group matches in the replacement string.
|
|
354
|
-
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replacen
|
|
355
|
-
* @param {string} text
|
|
356
|
-
* @param {number} limit
|
|
357
|
-
* @param {string} rep
|
|
358
|
-
* @returns {string}
|
|
359
|
-
*/
|
|
360
|
-
replacen(text, limit, rep) {
|
|
361
|
-
try {
|
|
362
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
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
|
-
wasm.rregex_replacen(retptr, this.ptr, ptr0, len0, limit, ptr1, len1);
|
|
368
|
-
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
369
|
-
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
370
|
-
return getStringFromWasm0(r0, r1);
|
|
371
|
-
} finally {
|
|
372
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
373
|
-
wasm.__wbindgen_free(r0, r1);
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
/**
|
|
377
|
-
* Replaces all non-overlapping matches in `text` with the replacement provided. This is the same as calling `replacen` with `limit` set to `0`.
|
|
378
|
-
* See the documentation for `replace` for details on how to access capturing group matches in the replacement string.
|
|
379
|
-
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replace_all
|
|
380
|
-
* @param {string} text
|
|
381
|
-
* @param {string} rep
|
|
382
|
-
* @returns {string}
|
|
383
|
-
*/
|
|
384
|
-
replaceAll(text, rep) {
|
|
385
|
-
try {
|
|
386
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
387
|
-
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
388
|
-
const len0 = WASM_VECTOR_LEN;
|
|
389
|
-
const ptr1 = passStringToWasm0(rep, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
390
|
-
const len1 = WASM_VECTOR_LEN;
|
|
391
|
-
wasm.rregex_replaceAll(retptr, this.ptr, ptr0, len0, ptr1, len1);
|
|
392
|
-
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
393
|
-
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
394
|
-
return getStringFromWasm0(r0, r1);
|
|
395
|
-
} finally {
|
|
396
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
397
|
-
wasm.__wbindgen_free(r0, r1);
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
/**
|
|
401
|
-
* 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.
|
|
402
|
-
* This method will not copy the text given.
|
|
403
|
-
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.split
|
|
404
|
-
* @param {string} text
|
|
405
|
-
* @returns {any}
|
|
406
|
-
*/
|
|
407
|
-
split(text) {
|
|
408
|
-
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
409
|
-
const len0 = WASM_VECTOR_LEN;
|
|
410
|
-
const ret = wasm.rregex_split(this.ptr, ptr0, len0);
|
|
411
|
-
return takeObject(ret);
|
|
412
|
-
}
|
|
413
|
-
/**
|
|
414
|
-
* 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.
|
|
415
|
-
* This method will not copy the text given.
|
|
416
|
-
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.splitn
|
|
417
|
-
* @param {string} text
|
|
418
|
-
* @param {number} limit
|
|
419
|
-
* @returns {any}
|
|
420
|
-
*/
|
|
421
|
-
splitn(text, limit) {
|
|
422
|
-
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
423
|
-
const len0 = WASM_VECTOR_LEN;
|
|
424
|
-
const ret = wasm.rregex_splitn(this.ptr, ptr0, len0, limit);
|
|
425
|
-
return takeObject(ret);
|
|
426
|
-
}
|
|
427
|
-
/**
|
|
428
|
-
* Returns the end location of a match in the text given.
|
|
429
|
-
* 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.
|
|
430
|
-
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.shortest_match
|
|
431
|
-
* @param {string} text
|
|
432
|
-
* @returns {number | undefined}
|
|
433
|
-
*/
|
|
434
|
-
shortestMatch(text) {
|
|
435
|
-
try {
|
|
436
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
437
|
-
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
438
|
-
const len0 = WASM_VECTOR_LEN;
|
|
439
|
-
wasm.rregex_shortestMatch(retptr, this.ptr, ptr0, len0);
|
|
440
|
-
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
441
|
-
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
442
|
-
return r0 === 0 ? undefined : r1 >>> 0;
|
|
443
|
-
} finally {
|
|
444
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
/**
|
|
448
|
-
* Returns the same as shortest_match, but starts the search at the given offset.
|
|
449
|
-
* 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`.
|
|
450
|
-
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.shortest_match_at
|
|
451
|
-
* @param {string} text
|
|
452
|
-
* @param {number} limit
|
|
453
|
-
* @returns {number | undefined}
|
|
454
|
-
*/
|
|
455
|
-
shortestMatchAt(text, limit) {
|
|
456
|
-
try {
|
|
457
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
458
|
-
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
459
|
-
const len0 = WASM_VECTOR_LEN;
|
|
460
|
-
wasm.rregex_shortestMatchAt(retptr, this.ptr, ptr0, len0, limit);
|
|
461
|
-
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
462
|
-
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
463
|
-
return r0 === 0 ? undefined : r1 >>> 0;
|
|
464
|
-
} finally {
|
|
465
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
/**
|
|
469
|
-
* Return the Regex syntax object
|
|
470
|
-
* @returns {any}
|
|
471
|
-
*/
|
|
472
|
-
syntax() {
|
|
473
|
-
const ret = wasm.rregex_syntax(this.ptr);
|
|
474
|
-
return takeObject(ret);
|
|
475
|
-
}
|
|
476
|
-
/**
|
|
477
|
-
* Returns a string representing the regular expression
|
|
478
|
-
* @returns {string}
|
|
479
|
-
*/
|
|
480
|
-
toString() {
|
|
481
|
-
try {
|
|
482
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
483
|
-
wasm.rregex_toString(retptr, this.ptr);
|
|
484
|
-
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
485
|
-
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
486
|
-
return getStringFromWasm0(r0, r1);
|
|
487
|
-
} finally {
|
|
488
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
489
|
-
wasm.__wbindgen_free(r0, r1);
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
/**
|
|
494
|
-
* Match multiple (possibly overlapping) regular expressions in a single scan.
|
|
495
|
-
* 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.
|
|
496
|
-
* @see https://docs.rs/regex/latest/regex/struct.RegexSet.html#method.empty
|
|
497
|
-
*/
|
|
498
|
-
export class RRegexSet {
|
|
499
|
-
|
|
500
|
-
static __wrap(ptr) {
|
|
501
|
-
const obj = Object.create(RRegexSet.prototype);
|
|
502
|
-
obj.ptr = ptr;
|
|
503
|
-
|
|
504
|
-
return obj;
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
__destroy_into_raw() {
|
|
508
|
-
const ptr = this.ptr;
|
|
509
|
-
this.ptr = 0;
|
|
510
|
-
|
|
511
|
-
return ptr;
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
free() {
|
|
515
|
-
const ptr = this.__destroy_into_raw();
|
|
516
|
-
wasm.__wbg_rregexset_free(ptr);
|
|
517
|
-
}
|
|
518
|
-
/**
|
|
519
|
-
* Create a new regex set with the given regular expressions.
|
|
520
|
-
* @param {Array<any>} list
|
|
521
|
-
*/
|
|
522
|
-
constructor(list) {
|
|
523
|
-
try {
|
|
524
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
525
|
-
wasm.rregexset_new(retptr, addBorrowedObject(list));
|
|
526
|
-
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
527
|
-
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
528
|
-
var r2 = getInt32Memory0()[retptr / 4 + 2];
|
|
529
|
-
if (r2) {
|
|
530
|
-
throw takeObject(r1);
|
|
531
|
-
}
|
|
532
|
-
return RRegexSet.__wrap(r0);
|
|
533
|
-
} finally {
|
|
534
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
535
|
-
heap[stack_pointer++] = undefined;
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
/**
|
|
539
|
-
* Returns true if and only if one of the regexes in this set matches the text given.
|
|
540
|
-
* 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.
|
|
541
|
-
* @see https://docs.rs/regex/latest/regex/struct.RegexSet.html#method.is_match
|
|
542
|
-
* @param {string} text
|
|
543
|
-
* @returns {boolean}
|
|
544
|
-
*/
|
|
545
|
-
isMatch(text) {
|
|
546
|
-
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
547
|
-
const len0 = WASM_VECTOR_LEN;
|
|
548
|
-
const ret = wasm.rregexset_isMatch(this.ptr, ptr0, len0);
|
|
549
|
-
return ret !== 0;
|
|
550
|
-
}
|
|
551
|
-
/**
|
|
552
|
-
* Returns the set of regular expressions that match in the given text.
|
|
553
|
-
* 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.
|
|
554
|
-
* the set can also be used to iterate over the matched indices.
|
|
555
|
-
* @param {string} text
|
|
556
|
-
* @returns {any}
|
|
557
|
-
*/
|
|
558
|
-
matches(text) {
|
|
559
|
-
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
560
|
-
const len0 = WASM_VECTOR_LEN;
|
|
561
|
-
const ret = wasm.rregexset_matches(this.ptr, ptr0, len0);
|
|
562
|
-
return takeObject(ret);
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
async function load(module, imports) {
|
|
567
|
-
if (typeof Response === 'function' && module instanceof Response) {
|
|
568
|
-
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
569
|
-
try {
|
|
570
|
-
return await WebAssembly.instantiateStreaming(module, imports);
|
|
571
|
-
|
|
572
|
-
} catch (e) {
|
|
573
|
-
if (module.headers.get('Content-Type') != 'application/wasm') {
|
|
574
|
-
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
|
575
|
-
|
|
576
|
-
} else {
|
|
577
|
-
throw e;
|
|
578
|
-
}
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
|
-
|
|
582
|
-
const bytes = await module.arrayBuffer();
|
|
583
|
-
return await WebAssembly.instantiate(bytes, imports);
|
|
584
|
-
|
|
585
|
-
} else {
|
|
586
|
-
const instance = await WebAssembly.instantiate(module, imports);
|
|
587
|
-
|
|
588
|
-
if (instance instanceof WebAssembly.Instance) {
|
|
589
|
-
return { instance, module };
|
|
590
|
-
|
|
591
|
-
} else {
|
|
592
|
-
return instance;
|
|
593
|
-
}
|
|
594
|
-
}
|
|
595
|
-
}
|
|
596
|
-
|
|
597
|
-
function getImports() {
|
|
598
|
-
const imports = {};
|
|
599
|
-
imports.wbg = {};
|
|
600
|
-
imports.wbg.__wbindgen_object_drop_ref = function(arg0) {
|
|
601
|
-
takeObject(arg0);
|
|
602
|
-
};
|
|
603
|
-
imports.wbg.__wbindgen_string_new = function(arg0, arg1) {
|
|
604
|
-
const ret = getStringFromWasm0(arg0, arg1);
|
|
605
|
-
return addHeapObject(ret);
|
|
606
|
-
};
|
|
607
|
-
imports.wbg.__wbindgen_number_new = function(arg0) {
|
|
608
|
-
const ret = arg0;
|
|
609
|
-
return addHeapObject(ret);
|
|
610
|
-
};
|
|
611
|
-
imports.wbg.__wbindgen_is_string = function(arg0) {
|
|
612
|
-
const ret = typeof(getObject(arg0)) === 'string';
|
|
613
|
-
return ret;
|
|
614
|
-
};
|
|
615
|
-
imports.wbg.__wbindgen_string_get = function(arg0, arg1) {
|
|
616
|
-
const obj = getObject(arg1);
|
|
617
|
-
const ret = typeof(obj) === 'string' ? obj : undefined;
|
|
618
|
-
var ptr0 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
619
|
-
var len0 = WASM_VECTOR_LEN;
|
|
620
|
-
getInt32Memory0()[arg0 / 4 + 1] = len0;
|
|
621
|
-
getInt32Memory0()[arg0 / 4 + 0] = ptr0;
|
|
622
|
-
};
|
|
623
|
-
imports.wbg.__wbg_get_f0f4f1608ebf633e = function(arg0, arg1) {
|
|
624
|
-
const ret = getObject(arg0)[arg1 >>> 0];
|
|
625
|
-
return addHeapObject(ret);
|
|
626
|
-
};
|
|
627
|
-
imports.wbg.__wbg_length_93debb0e2e184ab6 = function(arg0) {
|
|
628
|
-
const ret = getObject(arg0).length;
|
|
629
|
-
return ret;
|
|
630
|
-
};
|
|
631
|
-
imports.wbg.__wbg_new_2ab697f1555e0dbc = function() {
|
|
632
|
-
const ret = new Array();
|
|
633
|
-
return addHeapObject(ret);
|
|
634
|
-
};
|
|
635
|
-
imports.wbg.__wbg_new_306ce8d57919e6ae = function() {
|
|
636
|
-
const ret = new Object();
|
|
637
|
-
return addHeapObject(ret);
|
|
638
|
-
};
|
|
639
|
-
imports.wbg.__wbg_push_811c8b08bf4ff9d5 = function(arg0, arg1) {
|
|
640
|
-
const ret = getObject(arg0).push(getObject(arg1));
|
|
641
|
-
return ret;
|
|
642
|
-
};
|
|
643
|
-
imports.wbg.__wbg_new_651776e932b7e9c7 = function(arg0, arg1) {
|
|
644
|
-
const ret = new Error(getStringFromWasm0(arg0, arg1));
|
|
645
|
-
return addHeapObject(ret);
|
|
646
|
-
};
|
|
647
|
-
imports.wbg.__wbg_set_b12cd0ab82903c2f = function() { return handleError(function (arg0, arg1, arg2) {
|
|
648
|
-
const ret = Reflect.set(getObject(arg0), getObject(arg1), getObject(arg2));
|
|
649
|
-
return ret;
|
|
650
|
-
}, arguments) };
|
|
651
|
-
imports.wbg.__wbindgen_debug_string = function(arg0, arg1) {
|
|
652
|
-
const ret = debugString(getObject(arg1));
|
|
653
|
-
const ptr0 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
654
|
-
const len0 = WASM_VECTOR_LEN;
|
|
655
|
-
getInt32Memory0()[arg0 / 4 + 1] = len0;
|
|
656
|
-
getInt32Memory0()[arg0 / 4 + 0] = ptr0;
|
|
657
|
-
};
|
|
658
|
-
imports.wbg.__wbindgen_throw = function(arg0, arg1) {
|
|
659
|
-
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
660
|
-
};
|
|
661
|
-
|
|
662
|
-
return imports;
|
|
663
|
-
}
|
|
664
|
-
|
|
665
|
-
function initMemory(imports, maybe_memory) {
|
|
666
|
-
|
|
667
|
-
}
|
|
668
|
-
|
|
669
|
-
function finalizeInit(instance, module) {
|
|
670
|
-
wasm = instance.exports;
|
|
671
|
-
init.__wbindgen_wasm_module = module;
|
|
672
|
-
cachedInt32Memory0 = new Int32Array(wasm.memory.buffer);
|
|
673
|
-
cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
return wasm;
|
|
677
|
-
}
|
|
678
|
-
|
|
679
|
-
function initSync(bytes) {
|
|
680
|
-
const imports = getImports();
|
|
681
|
-
|
|
682
|
-
initMemory(imports);
|
|
683
|
-
|
|
684
|
-
const module = new WebAssembly.Module(bytes);
|
|
685
|
-
const instance = new WebAssembly.Instance(module, imports);
|
|
686
|
-
|
|
687
|
-
return finalizeInit(instance, module);
|
|
688
|
-
}
|
|
689
|
-
|
|
690
|
-
async function init(input) {
|
|
691
|
-
if (typeof input === 'undefined') {
|
|
692
|
-
input = new URL('rregex.wasm', import.meta.url);
|
|
693
|
-
}
|
|
694
|
-
const imports = getImports();
|
|
695
|
-
|
|
696
|
-
if (typeof input === 'string' || (typeof Request === 'function' && input instanceof Request) || (typeof URL === 'function' && input instanceof URL)) {
|
|
697
|
-
input = fetch(input);
|
|
698
|
-
}
|
|
699
|
-
|
|
700
|
-
initMemory(imports);
|
|
701
|
-
|
|
702
|
-
const { instance, module } = await load(await input, imports);
|
|
703
|
-
|
|
704
|
-
return finalizeInit(instance, module);
|
|
705
|
-
}
|
|
706
|
-
|
|
707
|
-
export { initSync }
|
|
708
|
-
export default init;
|
|
709
|
-
|
|
710
|
-
export const metadata = {
|
|
711
|
-
"name": "rregex",
|
|
712
|
-
"description": "Rust Regex binding for Javascript",
|
|
713
|
-
"authors": [
|
|
714
|
-
"Fede Ramirez <i@2fd.me>"
|
|
715
|
-
],
|
|
716
|
-
"homepage": "https://2fd.github.io/rregex",
|
|
717
|
-
"repository": "https://github.com/2fd/rregex",
|
|
718
|
-
"regex": "1.7.0",
|
|
719
|
-
"regex-syntax": "0.6.28"
|
|
720
|
-
}
|