rregex 1.10.12 → 1.11.0

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/lib/standalone.js CHANGED
@@ -7,1277 +7,1140 @@ let wasm_bindgen;
7
7
  }
8
8
  let wasm = undefined;
9
9
 
10
- const heap = new Array(128).fill(undefined);
11
-
12
- heap.push(undefined, null, true, false);
13
-
14
- let heap_next = heap.length;
15
-
16
- function addHeapObject(obj) {
17
- if (heap_next === heap.length) heap.push(heap.length + 1);
18
- const idx = heap_next;
19
- heap_next = heap[idx];
20
-
21
- heap[idx] = obj;
10
+ function addToExternrefTable0(obj) {
11
+ const idx = wasm.__externref_table_alloc();
12
+ wasm.__wbindgen_export_2.set(idx, obj);
22
13
  return idx;
23
14
  }
24
15
 
25
- function getObject(idx) { return heap[idx]; }
26
-
27
- function dropObject(idx) {
28
- if (idx < 132) return;
29
- heap[idx] = heap_next;
30
- heap_next = idx;
31
- }
32
-
33
- function takeObject(idx) {
34
- const ret = getObject(idx);
35
- dropObject(idx);
36
- return ret;
37
- }
38
-
39
- const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );
40
-
41
- if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); };
42
-
43
- let cachedUint8Memory0 = null;
44
-
45
- function getUint8Memory0() {
46
- if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) {
47
- cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);
16
+ function handleError(f, args) {
17
+ try {
18
+ return f.apply(this, args);
19
+ } catch (e) {
20
+ const idx = addToExternrefTable0(e);
21
+ wasm.__wbindgen_exn_store(idx);
22
+ }
48
23
  }
49
- return cachedUint8Memory0;
50
- }
51
24
 
52
- function getStringFromWasm0(ptr, len) {
53
- ptr = ptr >>> 0;
54
- return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
55
- }
25
+ const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );
56
26
 
57
- let WASM_VECTOR_LEN = 0;
27
+ if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); };
58
28
 
59
- const cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder('utf-8') : { encode: () => { throw Error('TextEncoder not available') } } );
29
+ let cachedUint8ArrayMemory0 = null;
60
30
 
61
- const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
62
- ? function (arg, view) {
63
- return cachedTextEncoder.encodeInto(arg, view);
64
- }
65
- : function (arg, view) {
66
- const buf = cachedTextEncoder.encode(arg);
67
- view.set(buf);
68
- return {
69
- read: arg.length,
70
- written: buf.length
71
- };
72
- });
73
-
74
- function passStringToWasm0(arg, malloc, realloc) {
75
-
76
- if (realloc === undefined) {
77
- const buf = cachedTextEncoder.encode(arg);
78
- const ptr = malloc(buf.length, 1) >>> 0;
79
- getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf);
80
- WASM_VECTOR_LEN = buf.length;
81
- return ptr;
31
+ function getUint8ArrayMemory0() {
32
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
33
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
34
+ }
35
+ return cachedUint8ArrayMemory0;
82
36
  }
83
37
 
84
- let len = arg.length;
85
- let ptr = malloc(len, 1) >>> 0;
38
+ function getStringFromWasm0(ptr, len) {
39
+ ptr = ptr >>> 0;
40
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
41
+ }
86
42
 
87
- const mem = getUint8Memory0();
43
+ let WASM_VECTOR_LEN = 0;
88
44
 
89
- let offset = 0;
45
+ const cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder('utf-8') : { encode: () => { throw Error('TextEncoder not available') } } );
90
46
 
91
- for (; offset < len; offset++) {
92
- const code = arg.charCodeAt(offset);
93
- if (code > 0x7F) break;
94
- mem[ptr + offset] = code;
47
+ const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
48
+ ? function (arg, view) {
49
+ return cachedTextEncoder.encodeInto(arg, view);
95
50
  }
96
-
97
- if (offset !== len) {
98
- if (offset !== 0) {
99
- arg = arg.slice(offset);
51
+ : function (arg, view) {
52
+ const buf = cachedTextEncoder.encode(arg);
53
+ view.set(buf);
54
+ return {
55
+ read: arg.length,
56
+ written: buf.length
57
+ };
58
+ });
59
+
60
+ function passStringToWasm0(arg, malloc, realloc) {
61
+
62
+ if (realloc === undefined) {
63
+ const buf = cachedTextEncoder.encode(arg);
64
+ const ptr = malloc(buf.length, 1) >>> 0;
65
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
66
+ WASM_VECTOR_LEN = buf.length;
67
+ return ptr;
100
68
  }
101
- ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
102
- const view = getUint8Memory0().subarray(ptr + offset, ptr + len);
103
- const ret = encodeString(arg, view);
104
69
 
105
- offset += ret.written;
106
- ptr = realloc(ptr, len, offset, 1) >>> 0;
107
- }
70
+ let len = arg.length;
71
+ let ptr = malloc(len, 1) >>> 0;
108
72
 
109
- WASM_VECTOR_LEN = offset;
110
- return ptr;
111
- }
73
+ const mem = getUint8ArrayMemory0();
112
74
 
113
- function isLikeNone(x) {
114
- return x === undefined || x === null;
115
- }
75
+ let offset = 0;
116
76
 
117
- let cachedInt32Memory0 = null;
77
+ for (; offset < len; offset++) {
78
+ const code = arg.charCodeAt(offset);
79
+ if (code > 0x7F) break;
80
+ mem[ptr + offset] = code;
81
+ }
118
82
 
119
- function getInt32Memory0() {
120
- if (cachedInt32Memory0 === null || cachedInt32Memory0.byteLength === 0) {
121
- cachedInt32Memory0 = new Int32Array(wasm.memory.buffer);
122
- }
123
- return cachedInt32Memory0;
124
- }
83
+ if (offset !== len) {
84
+ if (offset !== 0) {
85
+ arg = arg.slice(offset);
86
+ }
87
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
88
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
89
+ const ret = encodeString(arg, view);
125
90
 
126
- let cachedUint32Memory0 = null;
91
+ offset += ret.written;
92
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
93
+ }
127
94
 
128
- function getUint32Memory0() {
129
- if (cachedUint32Memory0 === null || cachedUint32Memory0.byteLength === 0) {
130
- cachedUint32Memory0 = new Uint32Array(wasm.memory.buffer);
95
+ WASM_VECTOR_LEN = offset;
96
+ return ptr;
131
97
  }
132
- return cachedUint32Memory0;
133
- }
134
98
 
135
- function getArrayJsValueFromWasm0(ptr, len) {
136
- ptr = ptr >>> 0;
137
- const mem = getUint32Memory0();
138
- const slice = mem.subarray(ptr / 4, ptr / 4 + len);
139
- const result = [];
140
- for (let i = 0; i < slice.length; i++) {
141
- result.push(takeObject(slice[i]));
99
+ function isLikeNone(x) {
100
+ return x === undefined || x === null;
142
101
  }
143
- return result;
144
- }
145
102
 
146
- let stack_pointer = 128;
103
+ let cachedDataViewMemory0 = null;
147
104
 
148
- function addBorrowedObject(obj) {
149
- if (stack_pointer == 1) throw new Error('out of js stack');
150
- heap[--stack_pointer] = obj;
151
- return stack_pointer;
152
- }
153
- /**
154
- * Escapes all regular expression meta characters in `text`.
155
- *
156
- * The string returned may be safely used as a literal in a regular
157
- * expression.
158
- * @param {string} text
159
- * @returns {string}
160
- */
161
- __exports.escape = function(text) {
162
- let deferred2_0;
163
- let deferred2_1;
164
- try {
165
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
166
- const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
167
- const len0 = WASM_VECTOR_LEN;
168
- wasm.escape(retptr, ptr0, len0);
169
- var r0 = getInt32Memory0()[retptr / 4 + 0];
170
- var r1 = getInt32Memory0()[retptr / 4 + 1];
171
- deferred2_0 = r0;
172
- deferred2_1 = r1;
173
- return getStringFromWasm0(r0, r1);
174
- } finally {
175
- wasm.__wbindgen_add_to_stack_pointer(16);
176
- wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
177
- }
178
- };
179
-
180
- function handleError(f, args) {
181
- try {
182
- return f.apply(this, args);
183
- } catch (e) {
184
- wasm.__wbindgen_exn_store(addHeapObject(e));
105
+ function getDataViewMemory0() {
106
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
107
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
108
+ }
109
+ return cachedDataViewMemory0;
185
110
  }
186
- }
187
111
 
188
- const RRegexFinalization = (typeof FinalizationRegistry === 'undefined')
189
- ? { register: () => {}, unregister: () => {} }
190
- : new FinalizationRegistry(ptr => wasm.__wbg_rregex_free(ptr >>> 0));
191
- /**
192
- * A compiled regular expression for matching Unicode strings.
193
- *
194
- * A `RRegex` can be used to search haystacks, split haystacks into substrings
195
- * or replace substrings in a haystack with a different substring. All
196
- * searching is done with an implicit `(?s:.)*?` at the beginning and end of
197
- * an pattern. To force an expression to match the whole string (or a prefix
198
- * or a suffix), you must use an anchor like `^` or `$` (or `\A` and `\z`).
199
- *
200
- * While this library will handle Unicode strings (whether in the regular
201
- * expression or in the haystack), all positions returned are **byte
202
- * offsets**. Every byte offset is guaranteed to be at a Unicode code point
203
- * boundary. That is, all offsets returned by the `RRegex` API are guaranteed
204
- * to be ranges that can slice an `Uint8Array` created with a TextEncoder.
205
- *
206
- * # Example: slicing over UTF strings
207
- *
208
- * ```typescript
209
- * import { RRegex } from "rregex"
210
- *
211
- * const re = new RRegex("ä")
212
- * const m = re.find("äöü") // { start: 0, end: 2 }
213
- *
214
- * const buff = new TextEncoder().encode("äöü")
215
- * const slice = buff.slice(m.start, m.end)
216
- * expect(new TextDecoder().decode(slice)).toBe("ä")
217
- * ```
218
- *
219
- * # Example: find the offsets of a US phone number:
220
- *
221
- * ```typescript
222
- * import { RRegex } from "rregex"
223
- *
224
- * const re = new RRegex("[0-9]{3}-[0-9]{3}-[0-9]{4}");
225
- * const m = re.find("phone: 111-222-3333");
226
- * expect(m.start).toBe(7);
227
- * expect(m.end).toBe(19);
228
- * ```
229
- *
230
- * @see https://docs.rs/regex/latest/regex/
231
- */
232
- class RRegex {
233
-
234
- __destroy_into_raw() {
235
- const ptr = this.__wbg_ptr;
236
- this.__wbg_ptr = 0;
237
- RRegexFinalization.unregister(this);
238
- return ptr;
112
+ function takeFromExternrefTable0(idx) {
113
+ const value = wasm.__wbindgen_export_2.get(idx);
114
+ wasm.__externref_table_dealloc(idx);
115
+ return value;
239
116
  }
240
117
 
241
- free() {
242
- const ptr = this.__destroy_into_raw();
243
- wasm.__wbg_rregex_free(ptr);
244
- }
245
- /**
246
- * Compiles a regular expression. Once compiled, it can be used repeatedly
247
- * to search, split or replace text in a string.
248
- *
249
- * If an invalid expression is given, then an error is returned.
250
- * @param {string} re
251
- */
252
- constructor(re) {
253
- try {
254
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
255
- const ptr0 = passStringToWasm0(re, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
256
- const len0 = WASM_VECTOR_LEN;
257
- wasm.rregex_new(retptr, ptr0, len0);
258
- var r0 = getInt32Memory0()[retptr / 4 + 0];
259
- var r1 = getInt32Memory0()[retptr / 4 + 1];
260
- var r2 = getInt32Memory0()[retptr / 4 + 2];
261
- if (r2) {
262
- throw takeObject(r1);
263
- }
264
- this.__wbg_ptr = r0 >>> 0;
265
- return this;
266
- } finally {
267
- wasm.__wbindgen_add_to_stack_pointer(16);
118
+ function getArrayJsValueFromWasm0(ptr, len) {
119
+ ptr = ptr >>> 0;
120
+ const mem = getDataViewMemory0();
121
+ const result = [];
122
+ for (let i = ptr; i < ptr + 4 * len; i += 4) {
123
+ result.push(wasm.__wbindgen_export_2.get(mem.getUint32(i, true)));
268
124
  }
125
+ wasm.__externref_drop_slice(ptr, len);
126
+ return result;
269
127
  }
270
128
  /**
271
- * Returns true if and only if there is a match for the regex in the
272
- * string given.
273
- *
274
- * It is recommended to use this method if all you need to do is test
275
- * a match, since the underlying matching engine may be able to do less
276
- * work.
277
- *
278
- * # Example
279
- *
280
- * Test if some text contains at least one word with exactly 13
281
- * Unicode word characters:
282
- *
283
- * ```typescript
284
- * import { RRegex } from "rregex"
285
- *
286
- * const text = "I categorically deny having triskaidekaphobia."
287
- * expect(new RRegex("\\b\\w{13}\\b").is_match(text)).toBe(true)
288
- * ```
289
- *
290
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.is_match
291
- * @param {string} text - The string against which to match the regular expression
292
- * @return {boolean}
293
- */
294
- isMatch(text) {
295
- const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
296
- const len0 = WASM_VECTOR_LEN;
297
- const ret = wasm.rregex_isMatch(this.__wbg_ptr, ptr0, len0);
298
- return ret !== 0;
299
- }
300
- /**
301
- * Returns the same as is_match, but starts the search at the given offset.
302
- * The significance of the starting point is that it takes the surrounding
303
- * context into consideration. For example, the `\A` anchor can only match
304
- * when `start == 0`.
305
- *
306
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.is_match_at
307
- * @param {string} text - The string against which to match the regular expression
308
- * @param {number} start - Zero-based index at which to start matching
309
- * @return {boolean}
310
- */
311
- isMatchAt(text, start) {
312
- const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
313
- const len0 = WASM_VECTOR_LEN;
314
- const ret = wasm.rregex_isMatchAt(this.__wbg_ptr, ptr0, len0, start);
315
- return ret !== 0;
316
- }
317
- /**
318
- * Returns the start and end byte range of the leftmost-first match in
319
- * `text`. If no match exists, then `undefined` is returned.
320
- *
321
- * Note that this should only be used if you want to discover the position
322
- * of the match. Testing the existence of a match is faster if you use
323
- * `isMatch`.
324
- *
325
- * # Example
326
- *
327
- * Find the start and end location of the first word with exactly 13
328
- * Unicode word characters:
329
- *
330
- * ```typescript
331
- * import { RRegex } from "rregex"
332
- *
333
- * const text = "I categorically deny having triskaidekaphobia."
334
- * const m = new RRegex("\\b\\w{13}\\b").find(text)
335
- * expect(m.start).toBe(2)
336
- * expect(m.end).toBe(15)
337
- * ```
338
- *
339
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find
340
- * @param {string} text - The string against which to match the regular expression
341
- * @return {Match}
342
- */
343
- find(text) {
129
+ * Escapes all regular expression meta characters in `text`.
130
+ *
131
+ * The string returned may be safely used as a literal in a regular
132
+ * expression.
133
+ * @param {string} text
134
+ * @returns {string}
135
+ */
136
+ __exports.escape = function(text) {
137
+ let deferred2_0;
138
+ let deferred2_1;
344
139
  try {
345
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
346
140
  const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
347
141
  const len0 = WASM_VECTOR_LEN;
348
- wasm.rregex_find(retptr, this.__wbg_ptr, ptr0, len0);
349
- var r0 = getInt32Memory0()[retptr / 4 + 0];
350
- var r1 = getInt32Memory0()[retptr / 4 + 1];
351
- var r2 = getInt32Memory0()[retptr / 4 + 2];
352
- if (r2) {
353
- throw takeObject(r1);
354
- }
355
- return takeObject(r0);
142
+ const ret = wasm.escape(ptr0, len0);
143
+ deferred2_0 = ret[0];
144
+ deferred2_1 = ret[1];
145
+ return getStringFromWasm0(ret[0], ret[1]);
356
146
  } finally {
357
- wasm.__wbindgen_add_to_stack_pointer(16);
147
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
358
148
  }
359
- }
149
+ };
150
+
151
+ const RRegexFinalization = (typeof FinalizationRegistry === 'undefined')
152
+ ? { register: () => {}, unregister: () => {} }
153
+ : new FinalizationRegistry(ptr => wasm.__wbg_rregex_free(ptr >>> 0, 1));
360
154
  /**
361
- * Returns the same as find, but starts the search at the given
362
- * offset.
363
- *
364
- * The significance of the starting point is that it takes the surrounding
365
- * context into consideration. For example, the `\A` anchor can only
366
- * match when `start == 0`.
367
- *
368
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find_at
369
- * @param {string} text - The string against which to match the regular expression
370
- * @param {number} start - Zero-based index at which to start matching
371
- * @returns {Match}
372
- */
373
- findAt(text, start) {
374
- try {
375
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
376
- const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
155
+ * A compiled regular expression for matching Unicode strings.
156
+ *
157
+ * A `RRegex` can be used to search haystacks, split haystacks into substrings
158
+ * or replace substrings in a haystack with a different substring. All
159
+ * searching is done with an implicit `(?s:.)*?` at the beginning and end of
160
+ * an pattern. To force an expression to match the whole string (or a prefix
161
+ * or a suffix), you must use an anchor like `^` or `$` (or `\A` and `\z`).
162
+ *
163
+ * While this library will handle Unicode strings (whether in the regular
164
+ * expression or in the haystack), all positions returned are **byte
165
+ * offsets**. Every byte offset is guaranteed to be at a Unicode code point
166
+ * boundary. That is, all offsets returned by the `RRegex` API are guaranteed
167
+ * to be ranges that can slice an `Uint8Array` created with a TextEncoder.
168
+ *
169
+ * # Example: slicing over UTF strings
170
+ *
171
+ * ```typescript
172
+ * import { RRegex } from "rregex"
173
+ *
174
+ * const re = new RRegex("ä")
175
+ * const m = re.find("äöü") // { start: 0, end: 2 }
176
+ *
177
+ * const buff = new TextEncoder().encode("äöü")
178
+ * const slice = buff.slice(m.start, m.end)
179
+ * expect(new TextDecoder().decode(slice)).toBe("ä")
180
+ * ```
181
+ *
182
+ * # Example: find the offsets of a US phone number:
183
+ *
184
+ * ```typescript
185
+ * import { RRegex } from "rregex"
186
+ *
187
+ * const re = new RRegex("[0-9]{3}-[0-9]{3}-[0-9]{4}");
188
+ * const m = re.find("phone: 111-222-3333");
189
+ * expect(m.start).toBe(7);
190
+ * expect(m.end).toBe(19);
191
+ * ```
192
+ *
193
+ * @see https://docs.rs/regex/latest/regex/
194
+ */
195
+ class RRegex {
196
+
197
+ __destroy_into_raw() {
198
+ const ptr = this.__wbg_ptr;
199
+ this.__wbg_ptr = 0;
200
+ RRegexFinalization.unregister(this);
201
+ return ptr;
202
+ }
203
+
204
+ free() {
205
+ const ptr = this.__destroy_into_raw();
206
+ wasm.__wbg_rregex_free(ptr, 0);
207
+ }
208
+ /**
209
+ * Compiles a regular expression. Once compiled, it can be used repeatedly
210
+ * to search, split or replace text in a string.
211
+ *
212
+ * If an invalid expression is given, then an error is returned.
213
+ * @param {string} re
214
+ */
215
+ constructor(re) {
216
+ const ptr0 = passStringToWasm0(re, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
377
217
  const len0 = WASM_VECTOR_LEN;
378
- wasm.rregex_findAt(retptr, this.__wbg_ptr, ptr0, len0, start);
379
- var r0 = getInt32Memory0()[retptr / 4 + 0];
380
- var r1 = getInt32Memory0()[retptr / 4 + 1];
381
- var r2 = getInt32Memory0()[retptr / 4 + 2];
382
- if (r2) {
383
- throw takeObject(r1);
218
+ const ret = wasm.rregex_new(ptr0, len0);
219
+ if (ret[2]) {
220
+ throw takeFromExternrefTable0(ret[1]);
384
221
  }
385
- return takeObject(r0);
386
- } finally {
387
- wasm.__wbindgen_add_to_stack_pointer(16);
222
+ this.__wbg_ptr = ret[0] >>> 0;
223
+ RRegexFinalization.register(this, this.__wbg_ptr, this);
224
+ return this;
388
225
  }
389
- }
390
- /**
391
- * Returns an array for each successive non-overlapping match in `text``,
392
- * returning the start and end byte indices with respect to `text`.
393
- *
394
- * # Example
395
- *
396
- * Find the start and end location of every word with exactly 13 Unicode
397
- * word characters:
398
- *
399
- * ```typescript
400
- * import { RRegex } from "rregex"
401
- *
402
- * const text = "Retroactively relinquishing remunerations is reprehensible."
403
- * const matches = new RRegex("\\b\\w{13}\\b").findAll(text)
404
- * ```
405
- *
406
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find_iter
407
- * @param {string} text - The string against which to match the regular expression
408
- * @returns {Match}
409
- */
410
- findAll(text) {
411
- try {
412
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
226
+ /**
227
+ * Returns true if and only if there is a match for the regex in the
228
+ * string given.
229
+ *
230
+ * It is recommended to use this method if all you need to do is test
231
+ * a match, since the underlying matching engine may be able to do less
232
+ * work.
233
+ *
234
+ * # Example
235
+ *
236
+ * Test if some text contains at least one word with exactly 13
237
+ * Unicode word characters:
238
+ *
239
+ * ```typescript
240
+ * import { RRegex } from "rregex"
241
+ *
242
+ * const text = "I categorically deny having triskaidekaphobia."
243
+ * expect(new RRegex("\\b\\w{13}\\b").is_match(text)).toBe(true)
244
+ * ```
245
+ *
246
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.is_match
247
+ * @param {string} text - The string against which to match the regular expression
248
+ * @return {boolean}
249
+ */
250
+ isMatch(text) {
413
251
  const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
414
252
  const len0 = WASM_VECTOR_LEN;
415
- wasm.rregex_findAll(retptr, this.__wbg_ptr, ptr0, len0);
416
- var r0 = getInt32Memory0()[retptr / 4 + 0];
417
- var r1 = getInt32Memory0()[retptr / 4 + 1];
418
- var r2 = getInt32Memory0()[retptr / 4 + 2];
419
- if (r2) {
420
- throw takeObject(r1);
421
- }
422
- return takeObject(r0);
423
- } finally {
424
- wasm.__wbindgen_add_to_stack_pointer(16);
253
+ const ret = wasm.rregex_isMatch(this.__wbg_ptr, ptr0, len0);
254
+ return ret !== 0;
425
255
  }
426
- }
427
- /**
428
- * Returns a list of the capture names in this regex.
429
- *
430
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.capture_names
431
- */
432
- captureNames() {
433
- try {
434
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
435
- wasm.rregex_captureNames(retptr, this.__wbg_ptr);
436
- var r0 = getInt32Memory0()[retptr / 4 + 0];
437
- var r1 = getInt32Memory0()[retptr / 4 + 1];
438
- var v1 = getArrayJsValueFromWasm0(r0, r1).slice();
439
- wasm.__wbindgen_free(r0, r1 * 4, 4);
440
- return v1;
441
- } finally {
442
- wasm.__wbindgen_add_to_stack_pointer(16);
256
+ /**
257
+ * Returns the same as is_match, but starts the search at the given offset.
258
+ * The significance of the starting point is that it takes the surrounding
259
+ * context into consideration. For example, the `\A` anchor can only match
260
+ * when `start == 0`.
261
+ *
262
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.is_match_at
263
+ * @param {string} text - The string against which to match the regular expression
264
+ * @param {number} start - Zero-based index at which to start matching
265
+ * @return {boolean}
266
+ */
267
+ isMatchAt(text, start) {
268
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
269
+ const len0 = WASM_VECTOR_LEN;
270
+ const ret = wasm.rregex_isMatchAt(this.__wbg_ptr, ptr0, len0, start);
271
+ return ret !== 0;
443
272
  }
444
- }
445
- /**
446
- * Returns the capture groups corresponding to the leftmost-first
447
- * match in `text`. Capture group `0` always corresponds to the entire
448
- * match. If no match is found, then `undefined` is returned.
449
- *
450
- * You should only use `captures` if you need access to the location of
451
- * capturing group matches. Otherwise, `find` is faster for discovering
452
- * the location of the overall match.
453
- *
454
- * # Examples
455
- *
456
- * Say you have some text with movie names and their release years,
457
- * like "'Citizen Kane' (1941)". It'd be nice if we could search for text
458
- * looking like that, while also extracting the movie name and its release
459
- * year separately.
460
- *
461
- * ```typescript
462
- * import { RRegex } from "rregex"
463
- *
464
- * const re = new RRegex("'([^']+)'\\s+\\((\\d{4})\)")
465
- * const text = "Not my favorite movie: 'Citizen Kane' (1941)."
466
- * const caps = re.captures(text)
467
- * expect(caps.get[1].value).toBe("Citizen Kane")
468
- * expect(caps.get[2].value).toBe("1941")
469
- * expect(caps.get[0].value).toBe("'Citizen Kane' (1941)")
470
- * ```
471
- *
472
- * Note that the full match is at capture group `0`. Each subsequent
473
- * capture group is indexed by the order of its opening `(`.
474
- *
475
- * We can make this example a bit clearer by using *named* capture groups:
476
- *
477
- * ```typescript
478
- * import { RRegex } from "rregex"
479
- *
480
- * const re = new RRegex("'(?P<title>[^']+)'\\s+\\((?P<year>\\d{4})\)")
481
- * const text = "Not my favorite movie: 'Citizen Kane' (1941)."
482
- * const caps = re.captures(text)
483
- * expect(caps.name["title"].value).toBe("Citizen Kane")
484
- * expect(caps.name["year"].value).toBe("1941")
485
- * expect(caps.get[0].value).toBe("'Citizen Kane' (1941)")
486
- * ```
487
- *
488
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.captures
489
- * @param {string} text - The string against which to match the regular expression
490
- * @returns {Captures|undefined}
491
- */
492
- captures(text) {
493
- try {
494
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
273
+ /**
274
+ * Returns the start and end byte range of the leftmost-first match in
275
+ * `text`. If no match exists, then `undefined` is returned.
276
+ *
277
+ * Note that this should only be used if you want to discover the position
278
+ * of the match. Testing the existence of a match is faster if you use
279
+ * `isMatch`.
280
+ *
281
+ * # Example
282
+ *
283
+ * Find the start and end location of the first word with exactly 13
284
+ * Unicode word characters:
285
+ *
286
+ * ```typescript
287
+ * import { RRegex } from "rregex"
288
+ *
289
+ * const text = "I categorically deny having triskaidekaphobia."
290
+ * const m = new RRegex("\\b\\w{13}\\b").find(text)
291
+ * expect(m.start).toBe(2)
292
+ * expect(m.end).toBe(15)
293
+ * ```
294
+ *
295
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find
296
+ * @param {string} text - The string against which to match the regular expression
297
+ * @return {Match}
298
+ */
299
+ find(text) {
495
300
  const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
496
301
  const len0 = WASM_VECTOR_LEN;
497
- wasm.rregex_captures(retptr, this.__wbg_ptr, ptr0, len0);
498
- var r0 = getInt32Memory0()[retptr / 4 + 0];
499
- var r1 = getInt32Memory0()[retptr / 4 + 1];
500
- var r2 = getInt32Memory0()[retptr / 4 + 2];
501
- if (r2) {
502
- throw takeObject(r1);
302
+ const ret = wasm.rregex_find(this.__wbg_ptr, ptr0, len0);
303
+ if (ret[2]) {
304
+ throw takeFromExternrefTable0(ret[1]);
503
305
  }
504
- return takeObject(r0);
505
- } finally {
506
- wasm.__wbindgen_add_to_stack_pointer(16);
306
+ return takeFromExternrefTable0(ret[0]);
507
307
  }
508
- }
509
- /**
510
- * Returns a list with all the non-overlapping capture groups matched
511
- * in `text`. This is operationally the same as `findAll`, except it
512
- * returns information about capturing group matches.
513
- *
514
- * # Example
515
- *
516
- * We can use this to find all movie titles and their release years in
517
- * some text, where the movie is formatted like "'Title' (xxxx)":
518
- *
519
- * ```typescript
520
- * import { RRegex } from "rregex"
521
- *
522
- * const re = new RRegex("'(?P<title>[^']+)'\\s+\\((?P<year>\\d{4})\\)")
523
- * const text = "'Citizen Kane' (1941), 'The Wizard of Oz' (1939), 'M' (1931)."
524
- * for caps of re.captures_iter(text) {
525
- * console.log(
526
- * "Movie:", caps.name["title"].value, ","
527
- * "Released:", caps.name["year"].value
528
- * );
529
- * }
530
- * // Output:
531
- * // Movie: Citizen Kane, Released: 1941
532
- * // Movie: The Wizard of Oz, Released: 1939
533
- * // Movie: M, Released: 1931
534
- * ```
535
- *
536
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.captures_iter
537
- * @param {string} text - The string against which to match the regular expression
538
- * @returns {Captures[]}
539
- */
540
- capturesAll(text) {
541
- try {
542
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
308
+ /**
309
+ * Returns the same as find, but starts the search at the given
310
+ * offset.
311
+ *
312
+ * The significance of the starting point is that it takes the surrounding
313
+ * context into consideration. For example, the `\A` anchor can only
314
+ * match when `start == 0`.
315
+ *
316
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find_at
317
+ * @param {string} text - The string against which to match the regular expression
318
+ * @param {number} start - Zero-based index at which to start matching
319
+ * @returns {Match}
320
+ */
321
+ findAt(text, start) {
543
322
  const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
544
323
  const len0 = WASM_VECTOR_LEN;
545
- wasm.rregex_capturesAll(retptr, this.__wbg_ptr, ptr0, len0);
546
- var r0 = getInt32Memory0()[retptr / 4 + 0];
547
- var r1 = getInt32Memory0()[retptr / 4 + 1];
548
- var r2 = getInt32Memory0()[retptr / 4 + 2];
549
- if (r2) {
550
- throw takeObject(r1);
324
+ const ret = wasm.rregex_findAt(this.__wbg_ptr, ptr0, len0, start);
325
+ if (ret[2]) {
326
+ throw takeFromExternrefTable0(ret[1]);
551
327
  }
552
- return takeObject(r0);
553
- } finally {
554
- wasm.__wbindgen_add_to_stack_pointer(16);
328
+ return takeFromExternrefTable0(ret[0]);
555
329
  }
556
- }
557
- /**
558
- * Returns the number of captures.
559
- *
560
- * This includes all named and unnamed groups, including the implicit
561
- * unnamed group that is always present and corresponds to the entire match.
562
- *
563
- * Since the implicit unnamed group is always included in this length, the
564
- * length returned is guaranteed to be greater than zero.
565
- *
566
- * ## Example
567
- *
568
- * ```typescript
569
- * import { RRegex } from "rregex"
570
- *
571
- * const re1 = new RRegex("(?P<y>\\d{4})-(?P<m>\\d{2})-(?P<d>\\d{2})")
572
- * expect(re1.capturesLength()).toEqual(4)
573
- *
574
- * const re2 = new RRegex("foo")
575
- * expect(re2.capturesLength()).toEqual(1)
576
- *
577
- * const re3 = new RRegex("(foo)")
578
- * expect(re3.capturesLength()).toEqual(2)
579
- *
580
- * const re4 = new RRegex("(?<a>.(?<b>.))(.)(?:.)(?<c>.)")
581
- * expect(re4.capturesLength()).toEqual(5)
582
- *
583
- * const re5 = new RRegex("[a&&b]")
584
- * expect(re5.capturesLength()).toEqual(1)
585
- * ```
586
- *
587
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.captures_len
588
- * @returns {number}
589
- */
590
- capturesLength() {
591
- const ret = wasm.rregex_capturesLength(this.__wbg_ptr);
592
- return ret >>> 0;
593
- }
594
- /**
595
- * Replaces the leftmost-first match with the replacement provided.
596
- * The replacement can be a regular string (where `$N` and `$name` are
597
- * expanded to match capture groups) or a function that takes the matches'
598
- * `Captures` and returns the replaced string.
599
- *
600
- * If no match is found, then a copy of the string is returned unchanged.
601
- *
602
- * # Replacement string syntax
603
- *
604
- * All instances of `$name` in the replacement text is replaced with the
605
- * corresponding capture group `name`.
606
- *
607
- * `name` may be an integer corresponding to the index of the
608
- * capture group (counted by order of opening parenthesis where `0` is the
609
- * entire match) or it can be a name (consisting of letters, digits or
610
- * underscores) corresponding to a named capture group.
611
- *
612
- * If `name` isn't a valid capture group (whether the name doesn't exist
613
- * or isn't a valid index), then it is replaced with the empty string.
614
- *
615
- * The longest possible name is used. e.g., `$1a` looks up the capture
616
- * group named `1a` and not the capture group at index `1`. To exert more
617
- * precise control over the name, use braces, e.g., `${1}a`.
618
- *
619
- * To write a literal `$` use `$$`.
620
- *
621
- * # Examples
622
- *
623
- * Note that this function is polymorphic with respect to the replacement.
624
- * In typical usage, this can just be a normal string:
625
- *
626
- * ```typescript
627
- * import { RRegex } from "rregex"
628
- *
629
- * const re = new RRegex("[^01]+")
630
- * expect(re.replace("1078910", "").toBe("1010")
631
- * ```
632
- *
633
- * Here's the example using this expansion technique with named capture
634
- * groups:
635
- *
636
- * ```typescript
637
- * import { RRegex } from "rregex"
638
- *
639
- * const re = new RRegex("(?P<last>[^,\\s]+),\\s+(?P<first>\\S+)")
640
- * const result = re.replace("Springsteen, Bruce", "$first $last")
641
- * expect(result).toBe("Bruce Springsteen")
642
- * ```
643
- *
644
- * Note that using `$2` instead of `$first` or `$1` instead of `$last`
645
- * would produce the same result. To write a literal `$` use `$$`.
646
- *
647
- * Sometimes the replacement string requires use of curly braces to
648
- * delineate a capture group replacement and surrounding literal text.
649
- * For example, if we wanted to join two words together with an
650
- * underscore:
651
- *
652
- * ```typescript
653
- * import { RRegex } from "rregex"
654
- *
655
- * const re = new RRegex("(?P<first>\\w+)\\s+(?P<second>\\w+)")
656
- * const result = re.replace("deep fried", "${first}_$second")
657
- * expect(result).toBe("deep_fried")
658
- * ```
659
- *
660
- * Without the curly braces, the capture group name `first_` would be
661
- * used, and since it doesn't exist, it would be replaced with the empty
662
- * string.
663
- *
664
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replace
665
- * @param {string} text - The string against which to match the regular expression
666
- * @param {string} rep - It's a string, it will replace the substring matched by `pattern`.
667
- * @returns {string}
668
- */
669
- replace(text, rep) {
670
- let deferred3_0;
671
- let deferred3_1;
672
- try {
673
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
330
+ /**
331
+ * Returns an array for each successive non-overlapping match in `text``,
332
+ * returning the start and end byte indices with respect to `text`.
333
+ *
334
+ * # Example
335
+ *
336
+ * Find the start and end location of every word with exactly 13 Unicode
337
+ * word characters:
338
+ *
339
+ * ```typescript
340
+ * import { RRegex } from "rregex"
341
+ *
342
+ * const text = "Retroactively relinquishing remunerations is reprehensible."
343
+ * const matches = new RRegex("\\b\\w{13}\\b").findAll(text)
344
+ * ```
345
+ *
346
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find_iter
347
+ * @param {string} text - The string against which to match the regular expression
348
+ * @returns {Match}
349
+ */
350
+ findAll(text) {
674
351
  const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
675
352
  const len0 = WASM_VECTOR_LEN;
676
- const ptr1 = passStringToWasm0(rep, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
677
- const len1 = WASM_VECTOR_LEN;
678
- wasm.rregex_replace(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1);
679
- var r0 = getInt32Memory0()[retptr / 4 + 0];
680
- var r1 = getInt32Memory0()[retptr / 4 + 1];
681
- deferred3_0 = r0;
682
- deferred3_1 = r1;
683
- return getStringFromWasm0(r0, r1);
684
- } finally {
685
- wasm.__wbindgen_add_to_stack_pointer(16);
686
- wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
353
+ const ret = wasm.rregex_findAll(this.__wbg_ptr, ptr0, len0);
354
+ if (ret[2]) {
355
+ throw takeFromExternrefTable0(ret[1]);
356
+ }
357
+ return takeFromExternrefTable0(ret[0]);
687
358
  }
688
- }
689
- /**
690
- * Replaces at most `limit` non-overlapping matches in `text` with the
691
- * replacement provided. If `limit` is 0, then all non-overlapping matches
692
- * are replaced.
693
- *
694
- * See the documentation for `replace` for details on how to access
695
- * capturing group matches in the replacement string.
696
- *
697
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replacen
698
- * @param {string} text - The string against which to match the regular expression
699
- * @param {number} limit - Max number of replacement
700
- * @param {string} rep - It's a string, it will replace the substring matched by `pattern`.
701
- * @returns {string}
702
- */
703
- replacen(text, limit, rep) {
704
- let deferred3_0;
705
- let deferred3_1;
706
- try {
707
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
359
+ /**
360
+ * Returns a list of the capture names in this regex.
361
+ *
362
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.capture_names
363
+ */
364
+ captureNames() {
365
+ const ret = wasm.rregex_captureNames(this.__wbg_ptr);
366
+ var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
367
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
368
+ return v1;
369
+ }
370
+ /**
371
+ * Returns the capture groups corresponding to the leftmost-first
372
+ * match in `text`. Capture group `0` always corresponds to the entire
373
+ * match. If no match is found, then `undefined` is returned.
374
+ *
375
+ * You should only use `captures` if you need access to the location of
376
+ * capturing group matches. Otherwise, `find` is faster for discovering
377
+ * the location of the overall match.
378
+ *
379
+ * # Examples
380
+ *
381
+ * Say you have some text with movie names and their release years,
382
+ * like "'Citizen Kane' (1941)". It'd be nice if we could search for text
383
+ * looking like that, while also extracting the movie name and its release
384
+ * year separately.
385
+ *
386
+ * ```typescript
387
+ * import { RRegex } from "rregex"
388
+ *
389
+ * const re = new RRegex("'([^']+)'\\s+\\((\\d{4})\)")
390
+ * const text = "Not my favorite movie: 'Citizen Kane' (1941)."
391
+ * const caps = re.captures(text)
392
+ * expect(caps.get[1].value).toBe("Citizen Kane")
393
+ * expect(caps.get[2].value).toBe("1941")
394
+ * expect(caps.get[0].value).toBe("'Citizen Kane' (1941)")
395
+ * ```
396
+ *
397
+ * Note that the full match is at capture group `0`. Each subsequent
398
+ * capture group is indexed by the order of its opening `(`.
399
+ *
400
+ * We can make this example a bit clearer by using *named* capture groups:
401
+ *
402
+ * ```typescript
403
+ * import { RRegex } from "rregex"
404
+ *
405
+ * const re = new RRegex("'(?P<title>[^']+)'\\s+\\((?P<year>\\d{4})\)")
406
+ * const text = "Not my favorite movie: 'Citizen Kane' (1941)."
407
+ * const caps = re.captures(text)
408
+ * expect(caps.name["title"].value).toBe("Citizen Kane")
409
+ * expect(caps.name["year"].value).toBe("1941")
410
+ * expect(caps.get[0].value).toBe("'Citizen Kane' (1941)")
411
+ * ```
412
+ *
413
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.captures
414
+ * @param {string} text - The string against which to match the regular expression
415
+ * @returns {Captures|undefined}
416
+ */
417
+ captures(text) {
708
418
  const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
709
419
  const len0 = WASM_VECTOR_LEN;
710
- const ptr1 = passStringToWasm0(rep, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
711
- const len1 = WASM_VECTOR_LEN;
712
- wasm.rregex_replacen(retptr, this.__wbg_ptr, ptr0, len0, limit, ptr1, len1);
713
- var r0 = getInt32Memory0()[retptr / 4 + 0];
714
- var r1 = getInt32Memory0()[retptr / 4 + 1];
715
- deferred3_0 = r0;
716
- deferred3_1 = r1;
717
- return getStringFromWasm0(r0, r1);
718
- } finally {
719
- wasm.__wbindgen_add_to_stack_pointer(16);
720
- wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
420
+ const ret = wasm.rregex_captures(this.__wbg_ptr, ptr0, len0);
421
+ if (ret[2]) {
422
+ throw takeFromExternrefTable0(ret[1]);
423
+ }
424
+ return takeFromExternrefTable0(ret[0]);
721
425
  }
722
- }
723
- /**
724
- * Replaces all non-overlapping matches in `text` with the replacement
725
- * provided. This is the same as calling `replacen` with `limit` set to
726
- * `0`.
727
- *
728
- * See the documentation for `replace` for details on how to access
729
- * capturing group matches in the replacement string.
730
- *
731
- * See the documentation for `replace` for details on how to access capturing group matches in the replacement string.
732
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replace_all
733
- * @param {string} text - The string against which to match the regular expression
734
- * @param {string} rep - It's a string, it will replace the substring matched by `pattern`.
735
- * @returns {string}
736
- */
737
- replaceAll(text, rep) {
738
- let deferred3_0;
739
- let deferred3_1;
740
- try {
741
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
426
+ /**
427
+ * Returns a list with all the non-overlapping capture groups matched
428
+ * in `text`. This is operationally the same as `findAll`, except it
429
+ * returns information about capturing group matches.
430
+ *
431
+ * # Example
432
+ *
433
+ * We can use this to find all movie titles and their release years in
434
+ * some text, where the movie is formatted like "'Title' (xxxx)":
435
+ *
436
+ * ```typescript
437
+ * import { RRegex } from "rregex"
438
+ *
439
+ * const re = new RRegex("'(?P<title>[^']+)'\\s+\\((?P<year>\\d{4})\\)")
440
+ * const text = "'Citizen Kane' (1941), 'The Wizard of Oz' (1939), 'M' (1931)."
441
+ * for caps of re.captures_iter(text) {
442
+ * console.log(
443
+ * "Movie:", caps.name["title"].value, ","
444
+ * "Released:", caps.name["year"].value
445
+ * );
446
+ * }
447
+ * // Output:
448
+ * // Movie: Citizen Kane, Released: 1941
449
+ * // Movie: The Wizard of Oz, Released: 1939
450
+ * // Movie: M, Released: 1931
451
+ * ```
452
+ *
453
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.captures_iter
454
+ * @param {string} text - The string against which to match the regular expression
455
+ * @returns {Captures[]}
456
+ */
457
+ capturesAll(text) {
742
458
  const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
743
459
  const len0 = WASM_VECTOR_LEN;
744
- const ptr1 = passStringToWasm0(rep, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
745
- const len1 = WASM_VECTOR_LEN;
746
- wasm.rregex_replaceAll(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1);
747
- var r0 = getInt32Memory0()[retptr / 4 + 0];
748
- var r1 = getInt32Memory0()[retptr / 4 + 1];
749
- deferred3_0 = r0;
750
- deferred3_1 = r1;
751
- return getStringFromWasm0(r0, r1);
752
- } finally {
753
- wasm.__wbindgen_add_to_stack_pointer(16);
754
- wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
460
+ const ret = wasm.rregex_capturesAll(this.__wbg_ptr, ptr0, len0);
461
+ if (ret[2]) {
462
+ throw takeFromExternrefTable0(ret[1]);
463
+ }
464
+ return takeFromExternrefTable0(ret[0]);
755
465
  }
756
- }
757
- /**
758
- * Returns an iterator of substrings of `text` delimited by a match of the
759
- * regular expression. Namely, each element of the iterator corresponds to
760
- * text that *isn't* matched by the regular expression.
761
- *
762
- * This method will *not* copy the text given.
763
- *
764
- * # Example
765
- *
766
- * To split a string delimited by arbitrary amounts of spaces or tabs:
767
- *
768
- * ```typescript
769
- * import { RRegex } from "rregex"
770
- *
771
- * const re = new RRegex(r"[ \\t]+")
772
- * const fields = re.split("a b \t c\td e")
773
- * expect(fields).toEqual(["a", "b", "c", "d", "e"])
774
- * ```
775
- *
776
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.split
777
- * @param {string} text - The string against which to match the regular expression
778
- * @returns {string[]}
779
- */
780
- split(text) {
781
- try {
782
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
466
+ /**
467
+ * Returns the number of captures.
468
+ *
469
+ * This includes all named and unnamed groups, including the implicit
470
+ * unnamed group that is always present and corresponds to the entire match.
471
+ *
472
+ * Since the implicit unnamed group is always included in this length, the
473
+ * length returned is guaranteed to be greater than zero.
474
+ *
475
+ * ## Example
476
+ *
477
+ * ```typescript
478
+ * import { RRegex } from "rregex"
479
+ *
480
+ * const re1 = new RRegex("(?P<y>\\d{4})-(?P<m>\\d{2})-(?P<d>\\d{2})")
481
+ * expect(re1.capturesLength()).toEqual(4)
482
+ *
483
+ * const re2 = new RRegex("foo")
484
+ * expect(re2.capturesLength()).toEqual(1)
485
+ *
486
+ * const re3 = new RRegex("(foo)")
487
+ * expect(re3.capturesLength()).toEqual(2)
488
+ *
489
+ * const re4 = new RRegex("(?<a>.(?<b>.))(.)(?:.)(?<c>.)")
490
+ * expect(re4.capturesLength()).toEqual(5)
491
+ *
492
+ * const re5 = new RRegex("[a&&b]")
493
+ * expect(re5.capturesLength()).toEqual(1)
494
+ * ```
495
+ *
496
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.captures_len
497
+ * @returns {number}
498
+ */
499
+ capturesLength() {
500
+ const ret = wasm.rregex_capturesLength(this.__wbg_ptr);
501
+ return ret >>> 0;
502
+ }
503
+ /**
504
+ * Replaces the leftmost-first match with the replacement provided.
505
+ * The replacement can be a regular string (where `$N` and `$name` are
506
+ * expanded to match capture groups) or a function that takes the matches'
507
+ * `Captures` and returns the replaced string.
508
+ *
509
+ * If no match is found, then a copy of the string is returned unchanged.
510
+ *
511
+ * # Replacement string syntax
512
+ *
513
+ * All instances of `$name` in the replacement text is replaced with the
514
+ * corresponding capture group `name`.
515
+ *
516
+ * `name` may be an integer corresponding to the index of the
517
+ * capture group (counted by order of opening parenthesis where `0` is the
518
+ * entire match) or it can be a name (consisting of letters, digits or
519
+ * underscores) corresponding to a named capture group.
520
+ *
521
+ * If `name` isn't a valid capture group (whether the name doesn't exist
522
+ * or isn't a valid index), then it is replaced with the empty string.
523
+ *
524
+ * The longest possible name is used. e.g., `$1a` looks up the capture
525
+ * group named `1a` and not the capture group at index `1`. To exert more
526
+ * precise control over the name, use braces, e.g., `${1}a`.
527
+ *
528
+ * To write a literal `$` use `$$`.
529
+ *
530
+ * # Examples
531
+ *
532
+ * Note that this function is polymorphic with respect to the replacement.
533
+ * In typical usage, this can just be a normal string:
534
+ *
535
+ * ```typescript
536
+ * import { RRegex } from "rregex"
537
+ *
538
+ * const re = new RRegex("[^01]+")
539
+ * expect(re.replace("1078910", "").toBe("1010")
540
+ * ```
541
+ *
542
+ * Here's the example using this expansion technique with named capture
543
+ * groups:
544
+ *
545
+ * ```typescript
546
+ * import { RRegex } from "rregex"
547
+ *
548
+ * const re = new RRegex("(?P<last>[^,\\s]+),\\s+(?P<first>\\S+)")
549
+ * const result = re.replace("Springsteen, Bruce", "$first $last")
550
+ * expect(result).toBe("Bruce Springsteen")
551
+ * ```
552
+ *
553
+ * Note that using `$2` instead of `$first` or `$1` instead of `$last`
554
+ * would produce the same result. To write a literal `$` use `$$`.
555
+ *
556
+ * Sometimes the replacement string requires use of curly braces to
557
+ * delineate a capture group replacement and surrounding literal text.
558
+ * For example, if we wanted to join two words together with an
559
+ * underscore:
560
+ *
561
+ * ```typescript
562
+ * import { RRegex } from "rregex"
563
+ *
564
+ * const re = new RRegex("(?P<first>\\w+)\\s+(?P<second>\\w+)")
565
+ * const result = re.replace("deep fried", "${first}_$second")
566
+ * expect(result).toBe("deep_fried")
567
+ * ```
568
+ *
569
+ * Without the curly braces, the capture group name `first_` would be
570
+ * used, and since it doesn't exist, it would be replaced with the empty
571
+ * string.
572
+ *
573
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replace
574
+ * @param {string} text - The string against which to match the regular expression
575
+ * @param {string} rep - It's a string, it will replace the substring matched by `pattern`.
576
+ * @returns {string}
577
+ */
578
+ replace(text, rep) {
579
+ let deferred3_0;
580
+ let deferred3_1;
581
+ try {
582
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
583
+ const len0 = WASM_VECTOR_LEN;
584
+ const ptr1 = passStringToWasm0(rep, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
585
+ const len1 = WASM_VECTOR_LEN;
586
+ const ret = wasm.rregex_replace(this.__wbg_ptr, ptr0, len0, ptr1, len1);
587
+ deferred3_0 = ret[0];
588
+ deferred3_1 = ret[1];
589
+ return getStringFromWasm0(ret[0], ret[1]);
590
+ } finally {
591
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
592
+ }
593
+ }
594
+ /**
595
+ * Replaces at most `limit` non-overlapping matches in `text` with the
596
+ * replacement provided. If `limit` is 0, then all non-overlapping matches
597
+ * are replaced.
598
+ *
599
+ * See the documentation for `replace` for details on how to access
600
+ * capturing group matches in the replacement string.
601
+ *
602
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replacen
603
+ * @param {string} text - The string against which to match the regular expression
604
+ * @param {number} limit - Max number of replacement
605
+ * @param {string} rep - It's a string, it will replace the substring matched by `pattern`.
606
+ * @returns {string}
607
+ */
608
+ replacen(text, limit, rep) {
609
+ let deferred3_0;
610
+ let deferred3_1;
611
+ try {
612
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
613
+ const len0 = WASM_VECTOR_LEN;
614
+ const ptr1 = passStringToWasm0(rep, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
615
+ const len1 = WASM_VECTOR_LEN;
616
+ const ret = wasm.rregex_replacen(this.__wbg_ptr, ptr0, len0, limit, ptr1, len1);
617
+ deferred3_0 = ret[0];
618
+ deferred3_1 = ret[1];
619
+ return getStringFromWasm0(ret[0], ret[1]);
620
+ } finally {
621
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
622
+ }
623
+ }
624
+ /**
625
+ * Replaces all non-overlapping matches in `text` with the replacement
626
+ * provided. This is the same as calling `replacen` with `limit` set to
627
+ * `0`.
628
+ *
629
+ * See the documentation for `replace` for details on how to access
630
+ * capturing group matches in the replacement string.
631
+ *
632
+ * See the documentation for `replace` for details on how to access capturing group matches in the replacement string.
633
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replace_all
634
+ * @param {string} text - The string against which to match the regular expression
635
+ * @param {string} rep - It's a string, it will replace the substring matched by `pattern`.
636
+ * @returns {string}
637
+ */
638
+ replaceAll(text, rep) {
639
+ let deferred3_0;
640
+ let deferred3_1;
641
+ try {
642
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
643
+ const len0 = WASM_VECTOR_LEN;
644
+ const ptr1 = passStringToWasm0(rep, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
645
+ const len1 = WASM_VECTOR_LEN;
646
+ const ret = wasm.rregex_replaceAll(this.__wbg_ptr, ptr0, len0, ptr1, len1);
647
+ deferred3_0 = ret[0];
648
+ deferred3_1 = ret[1];
649
+ return getStringFromWasm0(ret[0], ret[1]);
650
+ } finally {
651
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
652
+ }
653
+ }
654
+ /**
655
+ * Returns an iterator of substrings of `text` delimited by a match of the
656
+ * regular expression. Namely, each element of the iterator corresponds to
657
+ * text that *isn't* matched by the regular expression.
658
+ *
659
+ * This method will *not* copy the text given.
660
+ *
661
+ * # Example
662
+ *
663
+ * To split a string delimited by arbitrary amounts of spaces or tabs:
664
+ *
665
+ * ```typescript
666
+ * import { RRegex } from "rregex"
667
+ *
668
+ * const re = new RRegex(r"[ \\t]+")
669
+ * const fields = re.split("a b \t c\td e")
670
+ * expect(fields).toEqual(["a", "b", "c", "d", "e"])
671
+ * ```
672
+ *
673
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.split
674
+ * @param {string} text - The string against which to match the regular expression
675
+ * @returns {string[]}
676
+ */
677
+ split(text) {
783
678
  const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
784
679
  const len0 = WASM_VECTOR_LEN;
785
- wasm.rregex_split(retptr, this.__wbg_ptr, ptr0, len0);
786
- var r0 = getInt32Memory0()[retptr / 4 + 0];
787
- var r1 = getInt32Memory0()[retptr / 4 + 1];
788
- var v2 = getArrayJsValueFromWasm0(r0, r1).slice();
789
- wasm.__wbindgen_free(r0, r1 * 4, 4);
680
+ const ret = wasm.rregex_split(this.__wbg_ptr, ptr0, len0);
681
+ var v2 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
682
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
790
683
  return v2;
791
- } finally {
792
- wasm.__wbindgen_add_to_stack_pointer(16);
793
684
  }
794
- }
795
- /**
796
- * Returns an iterator of at most `limit` substrings of `text` delimited
797
- * by a match of the regular expression. (A `limit` of `0` will return no
798
- * substrings.) Namely, each element of the iterator corresponds to text
799
- * that *isn't* matched by the regular expression. The remainder of the
800
- * string that is not split will be the last element in the iterator.
801
- *
802
- * This method will *not* copy the text given.
803
- *
804
- * # Example
805
- *
806
- * Get the first two words in some text:
807
- *
808
- * ```typescript
809
- * import { RRegex } from "rregex"
810
- *
811
- * const re = new RRegex(r"\\W+")
812
- * const fields = re.splitn("Hey! How are you?", 3)
813
- * expect(fields).toEqual(["Hey", "How", "are you?"])
814
- * ```
815
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.splitn
816
- * @param {string} text - The string against which to match the regular expression
817
- * @param {number} limit - Max number result elements
818
- * @returns {string[]}
819
- */
820
- splitn(text, limit) {
821
- try {
822
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
685
+ /**
686
+ * Returns an iterator of at most `limit` substrings of `text` delimited
687
+ * by a match of the regular expression. (A `limit` of `0` will return no
688
+ * substrings.) Namely, each element of the iterator corresponds to text
689
+ * that *isn't* matched by the regular expression. The remainder of the
690
+ * string that is not split will be the last element in the iterator.
691
+ *
692
+ * This method will *not* copy the text given.
693
+ *
694
+ * # Example
695
+ *
696
+ * Get the first two words in some text:
697
+ *
698
+ * ```typescript
699
+ * import { RRegex } from "rregex"
700
+ *
701
+ * const re = new RRegex(r"\\W+")
702
+ * const fields = re.splitn("Hey! How are you?", 3)
703
+ * expect(fields).toEqual(["Hey", "How", "are you?"])
704
+ * ```
705
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.splitn
706
+ * @param {string} text - The string against which to match the regular expression
707
+ * @param {number} limit - Max number result elements
708
+ * @returns {string[]}
709
+ */
710
+ splitn(text, limit) {
823
711
  const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
824
712
  const len0 = WASM_VECTOR_LEN;
825
- wasm.rregex_splitn(retptr, this.__wbg_ptr, ptr0, len0, limit);
826
- var r0 = getInt32Memory0()[retptr / 4 + 0];
827
- var r1 = getInt32Memory0()[retptr / 4 + 1];
828
- var v2 = getArrayJsValueFromWasm0(r0, r1).slice();
829
- wasm.__wbindgen_free(r0, r1 * 4, 4);
713
+ const ret = wasm.rregex_splitn(this.__wbg_ptr, ptr0, len0, limit);
714
+ var v2 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
715
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
830
716
  return v2;
831
- } finally {
832
- wasm.__wbindgen_add_to_stack_pointer(16);
833
717
  }
834
- }
835
- /**
836
- * Returns the end location of a match in the text given.
837
- *
838
- * This method may have the same performance characteristics as
839
- * `isMatch`, except it provides an end location for a match. In
840
- * particular, the location returned *may be shorter* than the proper end
841
- * of the leftmost-first match that you would find via `Regex.find`.
842
- *
843
- * Note that it is not guaranteed that this routine finds the shortest or
844
- * "earliest" possible match. Instead, the main idea of this API is that
845
- * it returns the offset at the point at which the internal regex engine
846
- * has determined that a match has occurred. This may vary depending on
847
- * which internal regex engine is used, and thus, the offset itself may
848
- * change.
849
- *
850
- * # Example
851
- *
852
- * Typically, `a+` would match the entire first sequence of `a` in some
853
- * text, but `shortest_match` can give up as soon as it sees the first
854
- * `a`.
855
- *
856
- * ```typescript
857
- * import { RRegex } from "rregex"
858
- *
859
- * const text = "aaaaa"
860
- * const = new RRegex("a+").shortest_match(text)
861
- * expect(pos).toBe(1)
862
- * ```
863
- *
864
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.shortest_match
865
- * @param {string} text - The string against which to match the regular expression
866
- * @returns {number|undefined}
867
- */
868
- shortestMatch(text) {
869
- try {
870
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
718
+ /**
719
+ * Returns the end location of a match in the text given.
720
+ *
721
+ * This method may have the same performance characteristics as
722
+ * `isMatch`, except it provides an end location for a match. In
723
+ * particular, the location returned *may be shorter* than the proper end
724
+ * of the leftmost-first match that you would find via `Regex.find`.
725
+ *
726
+ * Note that it is not guaranteed that this routine finds the shortest or
727
+ * "earliest" possible match. Instead, the main idea of this API is that
728
+ * it returns the offset at the point at which the internal regex engine
729
+ * has determined that a match has occurred. This may vary depending on
730
+ * which internal regex engine is used, and thus, the offset itself may
731
+ * change.
732
+ *
733
+ * # Example
734
+ *
735
+ * Typically, `a+` would match the entire first sequence of `a` in some
736
+ * text, but `shortest_match` can give up as soon as it sees the first
737
+ * `a`.
738
+ *
739
+ * ```typescript
740
+ * import { RRegex } from "rregex"
741
+ *
742
+ * const text = "aaaaa"
743
+ * const = new RRegex("a+").shortest_match(text)
744
+ * expect(pos).toBe(1)
745
+ * ```
746
+ *
747
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.shortest_match
748
+ * @param {string} text - The string against which to match the regular expression
749
+ * @returns {number|undefined}
750
+ */
751
+ shortestMatch(text) {
871
752
  const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
872
753
  const len0 = WASM_VECTOR_LEN;
873
- wasm.rregex_shortestMatch(retptr, this.__wbg_ptr, ptr0, len0);
874
- var r0 = getInt32Memory0()[retptr / 4 + 0];
875
- var r1 = getInt32Memory0()[retptr / 4 + 1];
876
- return r0 === 0 ? undefined : r1 >>> 0;
877
- } finally {
878
- wasm.__wbindgen_add_to_stack_pointer(16);
754
+ const ret = wasm.rregex_shortestMatch(this.__wbg_ptr, ptr0, len0);
755
+ return ret === 0x100000001 ? undefined : ret;
879
756
  }
880
- }
881
- /**
882
- * Returns the same as `shortest_match`, but starts the search at the
883
- * given offset.
884
- *
885
- * The significance of the starting point is that it takes the surrounding
886
- * context into consideration. For example, the `\A` anchor can only match
887
- * when `start == 0`.
888
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.shortest_match_at
889
- * @param {string} text - The string against which to match the regular expression
890
- * @param {number} start - Zero-based index at which to start matching
891
- * @returns {number|undefined}
892
- */
893
- shortestMatchAt(text, start) {
894
- try {
895
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
757
+ /**
758
+ * Returns the same as `shortest_match`, but starts the search at the
759
+ * given offset.
760
+ *
761
+ * The significance of the starting point is that it takes the surrounding
762
+ * context into consideration. For example, the `\A` anchor can only match
763
+ * when `start == 0`.
764
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.shortest_match_at
765
+ * @param {string} text - The string against which to match the regular expression
766
+ * @param {number} start - Zero-based index at which to start matching
767
+ * @returns {number|undefined}
768
+ */
769
+ shortestMatchAt(text, start) {
896
770
  const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
897
771
  const len0 = WASM_VECTOR_LEN;
898
- wasm.rregex_shortestMatchAt(retptr, this.__wbg_ptr, ptr0, len0, start);
899
- var r0 = getInt32Memory0()[retptr / 4 + 0];
900
- var r1 = getInt32Memory0()[retptr / 4 + 1];
901
- return r0 === 0 ? undefined : r1 >>> 0;
902
- } finally {
903
- wasm.__wbindgen_add_to_stack_pointer(16);
772
+ const ret = wasm.rregex_shortestMatchAt(this.__wbg_ptr, ptr0, len0, start);
773
+ return ret === 0x100000001 ? undefined : ret;
904
774
  }
905
- }
906
- /**
907
- * Returns the regular expression into a high level intermediate
908
- * representation.
909
- * @returns {any}
910
- */
911
- syntax() {
912
- try {
913
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
914
- wasm.rregex_syntax(retptr, this.__wbg_ptr);
915
- var r0 = getInt32Memory0()[retptr / 4 + 0];
916
- var r1 = getInt32Memory0()[retptr / 4 + 1];
917
- var r2 = getInt32Memory0()[retptr / 4 + 2];
918
- if (r2) {
919
- throw takeObject(r1);
775
+ /**
776
+ * Returns the regular expression into a high level intermediate
777
+ * representation.
778
+ * @returns {any}
779
+ */
780
+ syntax() {
781
+ const ret = wasm.rregex_syntax(this.__wbg_ptr);
782
+ if (ret[2]) {
783
+ throw takeFromExternrefTable0(ret[1]);
920
784
  }
921
- return takeObject(r0);
922
- } finally {
923
- wasm.__wbindgen_add_to_stack_pointer(16);
785
+ return takeFromExternrefTable0(ret[0]);
924
786
  }
925
- }
926
- /**
927
- * Returns a string representing the regular expression
928
- * @returns {string}
929
- */
930
- toString() {
931
- let deferred1_0;
932
- let deferred1_1;
933
- try {
934
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
935
- wasm.rregex_toString(retptr, this.__wbg_ptr);
936
- var r0 = getInt32Memory0()[retptr / 4 + 0];
937
- var r1 = getInt32Memory0()[retptr / 4 + 1];
938
- deferred1_0 = r0;
939
- deferred1_1 = r1;
940
- return getStringFromWasm0(r0, r1);
941
- } finally {
942
- wasm.__wbindgen_add_to_stack_pointer(16);
943
- wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
787
+ /**
788
+ * Returns a string representing the regular expression
789
+ * @returns {string}
790
+ */
791
+ toString() {
792
+ let deferred1_0;
793
+ let deferred1_1;
794
+ try {
795
+ const ret = wasm.rregex_toString(this.__wbg_ptr);
796
+ deferred1_0 = ret[0];
797
+ deferred1_1 = ret[1];
798
+ return getStringFromWasm0(ret[0], ret[1]);
799
+ } finally {
800
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
801
+ }
944
802
  }
945
803
  }
946
- }
947
- __exports.RRegex = RRegex;
948
-
949
- const RRegexSetFinalization = (typeof FinalizationRegistry === 'undefined')
950
- ? { register: () => {}, unregister: () => {} }
951
- : new FinalizationRegistry(ptr => wasm.__wbg_rregexset_free(ptr >>> 0));
952
- /**
953
- * Match multiple (possibly overlapping) regular expressions in a single scan.
954
- * A regex set corresponds to the union of two or more regular expressions.
955
- *
956
- * That is, a regex set will match text where at least one of its constituent
957
- * regular expressions matches. A regex set as its formulated here provides a
958
- * touch more power: it will also report which regular expressions in the set match.
959
- * Indeed, this is the key difference between regex sets and a single `Regex`
960
- * with many alternates, since only one alternate can match at a time.
961
- *
962
- * @see https://docs.rs/regex/latest/regex/struct.RegexSet.html#method.empty
963
- */
964
- class RRegexSet {
965
-
966
- __destroy_into_raw() {
967
- const ptr = this.__wbg_ptr;
968
- this.__wbg_ptr = 0;
969
- RRegexSetFinalization.unregister(this);
970
- return ptr;
971
- }
804
+ __exports.RRegex = RRegex;
972
805
 
973
- free() {
974
- const ptr = this.__destroy_into_raw();
975
- wasm.__wbg_rregexset_free(ptr);
976
- }
806
+ const RRegexSetFinalization = (typeof FinalizationRegistry === 'undefined')
807
+ ? { register: () => {}, unregister: () => {} }
808
+ : new FinalizationRegistry(ptr => wasm.__wbg_rregexset_free(ptr >>> 0, 1));
977
809
  /**
978
- * Create a new regex set with the given regular expressions.
979
- *
980
- * This takes an of strings, if any item in the list is not a valid regular
981
- * expressions, then an error is returned.
982
- *
983
- * # Example
984
- *
985
- * Create a new regex set from an iterator of strings:
986
- *
987
- * ```typescript
988
- * import { RegexSet } from "rregex"
989
- *
990
- * const set = new RegexSet(["\\w+", "\\d+"])
991
- * expect(set.is_match("foo")).toBe(true)
992
- * ```
993
- * @param {Array<any>} list
994
- */
995
- constructor(list) {
996
- try {
997
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
998
- wasm.rregexset_new(retptr, addBorrowedObject(list));
999
- var r0 = getInt32Memory0()[retptr / 4 + 0];
1000
- var r1 = getInt32Memory0()[retptr / 4 + 1];
1001
- var r2 = getInt32Memory0()[retptr / 4 + 2];
1002
- if (r2) {
1003
- throw takeObject(r1);
810
+ * Match multiple (possibly overlapping) regular expressions in a single scan.
811
+ * A regex set corresponds to the union of two or more regular expressions.
812
+ *
813
+ * That is, a regex set will match text where at least one of its constituent
814
+ * regular expressions matches. A regex set as its formulated here provides a
815
+ * touch more power: it will also report which regular expressions in the set match.
816
+ * Indeed, this is the key difference between regex sets and a single `Regex`
817
+ * with many alternates, since only one alternate can match at a time.
818
+ *
819
+ * @see https://docs.rs/regex/latest/regex/struct.RegexSet.html#method.empty
820
+ */
821
+ class RRegexSet {
822
+
823
+ __destroy_into_raw() {
824
+ const ptr = this.__wbg_ptr;
825
+ this.__wbg_ptr = 0;
826
+ RRegexSetFinalization.unregister(this);
827
+ return ptr;
828
+ }
829
+
830
+ free() {
831
+ const ptr = this.__destroy_into_raw();
832
+ wasm.__wbg_rregexset_free(ptr, 0);
833
+ }
834
+ /**
835
+ * Create a new regex set with the given regular expressions.
836
+ *
837
+ * This takes an of strings, if any item in the list is not a valid regular
838
+ * expressions, then an error is returned.
839
+ *
840
+ * # Example
841
+ *
842
+ * Create a new regex set from an iterator of strings:
843
+ *
844
+ * ```typescript
845
+ * import { RegexSet } from "rregex"
846
+ *
847
+ * const set = new RegexSet(["\\w+", "\\d+"])
848
+ * expect(set.is_match("foo")).toBe(true)
849
+ * ```
850
+ * @param {Array<any>} list
851
+ */
852
+ constructor(list) {
853
+ const ret = wasm.rregexset_new(list);
854
+ if (ret[2]) {
855
+ throw takeFromExternrefTable0(ret[1]);
1004
856
  }
1005
- this.__wbg_ptr = r0 >>> 0;
857
+ this.__wbg_ptr = ret[0] >>> 0;
858
+ RRegexSetFinalization.register(this, this.__wbg_ptr, this);
1006
859
  return this;
1007
- } finally {
1008
- wasm.__wbindgen_add_to_stack_pointer(16);
1009
- heap[stack_pointer++] = undefined;
1010
860
  }
1011
- }
1012
- /**
1013
- * Returns true if and only if one of the regexes in this set matches
1014
- * the text given.
1015
- *
1016
- * This method should be preferred if you only need to test whether any
1017
- * of the regexes in the set should match, but don't care about *which*
1018
- * regexes matched. This is because the underlying matching engine will
1019
- * quit immediately after seeing the first match instead of continuing to
1020
- * find all matches.
1021
- *
1022
- * Note that as with searches using `Regex`, the expression is unanchored
1023
- * by default. That is, if the regex does not start with `^` or `\A`, or
1024
- * end with `$` or `\z`, then it is permitted to match anywhere in the
1025
- * text.
1026
- *
1027
- * # Example
1028
- *
1029
- * Tests whether a set matches some text:
1030
- *
1031
- * ```typescript
1032
- * import { RegexSet } from "rregex"
1033
- *
1034
- * const set = new RegexSet(["\\w+", "\\d+"])
1035
- * expect(set.is_match("foo")).toBe(true)
1036
- * expect(!set.is_match("☃")).toBe(false)
1037
- * ```
1038
- *
1039
- * @see https://docs.rs/regex/latest/regex/struct.RegexSet.html#method.is_match
1040
- * @param {string} text - The string against which to match the regular expression
1041
- * @return {boolean}
1042
- */
1043
- isMatch(text) {
1044
- const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1045
- const len0 = WASM_VECTOR_LEN;
1046
- const ret = wasm.rregexset_isMatch(this.__wbg_ptr, ptr0, len0);
1047
- return ret !== 0;
1048
- }
1049
- /**
1050
- * Returns the set of regular expressions that match in the given text.
1051
- *
1052
- * The set returned contains the index of each regular expression that
1053
- * matches in the given text. The index is in correspondence with the
1054
- * order of regular expressions given to `RegexSet`'s constructor.
1055
- *
1056
- * The set can also be used to iterate over the matched indices.
1057
- *
1058
- * Note that as with searches using `Regex`, the expression is unanchored
1059
- * by default. That is, if the regex does not start with `^` or `\A`, or
1060
- * end with `$` or `\z`, then it is permitted to match anywhere in the
1061
- * text.
1062
- *
1063
- * # Example
1064
- *
1065
- * Tests which regular expressions match the given text:
1066
- *
1067
- * ```typescript
1068
- * import { RegexSet } from "rregex"
1069
- *
1070
- * const set = new RegexSet([
1071
- * "\\w+",
1072
- * "\\d+",
1073
- * "\\pL+",
1074
- * "foo",
1075
- * "bar",
1076
- * "barfoo",
1077
- * "foobar",
1078
- * ])
1079
- * const matches = set.matches("foobar")
1080
- * expect(matches).toBe([0, 2, 3, 4, 6])
1081
- * ```
1082
- *
1083
- * @see https://docs.rs/regex/latest/regex/struct.RegexSet.html#method.matches
1084
- * @param {string} text - The string against which to match the regular expression
1085
- * @return {number[]}
1086
- */
1087
- matches(text) {
1088
- try {
1089
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
861
+ /**
862
+ * Returns true if and only if one of the regexes in this set matches
863
+ * the text given.
864
+ *
865
+ * This method should be preferred if you only need to test whether any
866
+ * of the regexes in the set should match, but don't care about *which*
867
+ * regexes matched. This is because the underlying matching engine will
868
+ * quit immediately after seeing the first match instead of continuing to
869
+ * find all matches.
870
+ *
871
+ * Note that as with searches using `Regex`, the expression is unanchored
872
+ * by default. That is, if the regex does not start with `^` or `\A`, or
873
+ * end with `$` or `\z`, then it is permitted to match anywhere in the
874
+ * text.
875
+ *
876
+ * # Example
877
+ *
878
+ * Tests whether a set matches some text:
879
+ *
880
+ * ```typescript
881
+ * import { RegexSet } from "rregex"
882
+ *
883
+ * const set = new RegexSet(["\\w+", "\\d+"])
884
+ * expect(set.is_match("foo")).toBe(true)
885
+ * expect(!set.is_match("☃")).toBe(false)
886
+ * ```
887
+ *
888
+ * @see https://docs.rs/regex/latest/regex/struct.RegexSet.html#method.is_match
889
+ * @param {string} text - The string against which to match the regular expression
890
+ * @return {boolean}
891
+ */
892
+ isMatch(text) {
893
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
894
+ const len0 = WASM_VECTOR_LEN;
895
+ const ret = wasm.rregexset_isMatch(this.__wbg_ptr, ptr0, len0);
896
+ return ret !== 0;
897
+ }
898
+ /**
899
+ * Returns the set of regular expressions that match in the given text.
900
+ *
901
+ * The set returned contains the index of each regular expression that
902
+ * matches in the given text. The index is in correspondence with the
903
+ * order of regular expressions given to `RegexSet`'s constructor.
904
+ *
905
+ * The set can also be used to iterate over the matched indices.
906
+ *
907
+ * Note that as with searches using `Regex`, the expression is unanchored
908
+ * by default. That is, if the regex does not start with `^` or `\A`, or
909
+ * end with `$` or `\z`, then it is permitted to match anywhere in the
910
+ * text.
911
+ *
912
+ * # Example
913
+ *
914
+ * Tests which regular expressions match the given text:
915
+ *
916
+ * ```typescript
917
+ * import { RegexSet } from "rregex"
918
+ *
919
+ * const set = new RegexSet([
920
+ * "\\w+",
921
+ * "\\d+",
922
+ * "\\pL+",
923
+ * "foo",
924
+ * "bar",
925
+ * "barfoo",
926
+ * "foobar",
927
+ * ])
928
+ * const matches = set.matches("foobar")
929
+ * expect(matches).toBe([0, 2, 3, 4, 6])
930
+ * ```
931
+ *
932
+ * @see https://docs.rs/regex/latest/regex/struct.RegexSet.html#method.matches
933
+ * @param {string} text - The string against which to match the regular expression
934
+ * @return {number[]}
935
+ */
936
+ matches(text) {
1090
937
  const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1091
938
  const len0 = WASM_VECTOR_LEN;
1092
- wasm.rregexset_matches(retptr, this.__wbg_ptr, ptr0, len0);
1093
- var r0 = getInt32Memory0()[retptr / 4 + 0];
1094
- var r1 = getInt32Memory0()[retptr / 4 + 1];
1095
- var v2 = getArrayJsValueFromWasm0(r0, r1).slice();
1096
- wasm.__wbindgen_free(r0, r1 * 4, 4);
939
+ const ret = wasm.rregexset_matches(this.__wbg_ptr, ptr0, len0);
940
+ var v2 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
941
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
1097
942
  return v2;
1098
- } finally {
1099
- wasm.__wbindgen_add_to_stack_pointer(16);
1100
943
  }
1101
944
  }
1102
- }
1103
- __exports.RRegexSet = RRegexSet;
945
+ __exports.RRegexSet = RRegexSet;
1104
946
 
1105
- async function __wbg_load(module, imports) {
1106
- if (typeof Response === 'function' && module instanceof Response) {
1107
- if (typeof WebAssembly.instantiateStreaming === 'function') {
1108
- try {
1109
- return await WebAssembly.instantiateStreaming(module, imports);
947
+ async function __wbg_load(module, imports) {
948
+ if (typeof Response === 'function' && module instanceof Response) {
949
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
950
+ try {
951
+ return await WebAssembly.instantiateStreaming(module, imports);
1110
952
 
1111
- } catch (e) {
1112
- if (module.headers.get('Content-Type') != 'application/wasm') {
1113
- 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);
953
+ } catch (e) {
954
+ if (module.headers.get('Content-Type') != 'application/wasm') {
955
+ 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);
1114
956
 
1115
- } else {
1116
- throw e;
957
+ } else {
958
+ throw e;
959
+ }
1117
960
  }
1118
961
  }
1119
- }
1120
962
 
1121
- const bytes = await module.arrayBuffer();
1122
- return await WebAssembly.instantiate(bytes, imports);
963
+ const bytes = await module.arrayBuffer();
964
+ return await WebAssembly.instantiate(bytes, imports);
1123
965
 
1124
- } else {
1125
- const instance = await WebAssembly.instantiate(module, imports);
966
+ } else {
967
+ const instance = await WebAssembly.instantiate(module, imports);
1126
968
 
1127
- if (instance instanceof WebAssembly.Instance) {
1128
- return { instance, module };
969
+ if (instance instanceof WebAssembly.Instance) {
970
+ return { instance, module };
1129
971
 
1130
- } else {
1131
- return instance;
972
+ } else {
973
+ return instance;
974
+ }
1132
975
  }
1133
976
  }
1134
- }
1135
977
 
1136
- function __wbg_get_imports() {
1137
- const imports = {};
1138
- imports.wbg = {};
1139
- imports.wbg.__wbindgen_number_new = function(arg0) {
1140
- const ret = arg0;
1141
- return addHeapObject(ret);
1142
- };
1143
- imports.wbg.__wbindgen_object_drop_ref = function(arg0) {
1144
- takeObject(arg0);
1145
- };
1146
- imports.wbg.__wbindgen_string_new = function(arg0, arg1) {
1147
- const ret = getStringFromWasm0(arg0, arg1);
1148
- return addHeapObject(ret);
1149
- };
1150
- imports.wbg.__wbindgen_string_get = function(arg0, arg1) {
1151
- const obj = getObject(arg1);
1152
- const ret = typeof(obj) === 'string' ? obj : undefined;
1153
- var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1154
- var len1 = WASM_VECTOR_LEN;
1155
- getInt32Memory0()[arg0 / 4 + 1] = len1;
1156
- getInt32Memory0()[arg0 / 4 + 0] = ptr1;
1157
- };
1158
- imports.wbg.__wbindgen_error_new = function(arg0, arg1) {
1159
- const ret = new Error(getStringFromWasm0(arg0, arg1));
1160
- return addHeapObject(ret);
1161
- };
1162
- imports.wbg.__wbindgen_bigint_from_u64 = function(arg0) {
1163
- const ret = BigInt.asUintN(64, arg0);
1164
- return addHeapObject(ret);
1165
- };
1166
- imports.wbg.__wbg_set_f975102236d3c502 = function(arg0, arg1, arg2) {
1167
- getObject(arg0)[takeObject(arg1)] = takeObject(arg2);
1168
- };
1169
- imports.wbg.__wbindgen_object_clone_ref = function(arg0) {
1170
- const ret = getObject(arg0);
1171
- return addHeapObject(ret);
1172
- };
1173
- imports.wbg.__wbg_get_bd8e338fbd5f5cc8 = function(arg0, arg1) {
1174
- const ret = getObject(arg0)[arg1 >>> 0];
1175
- return addHeapObject(ret);
1176
- };
1177
- imports.wbg.__wbg_length_cd7af8117672b8b8 = function(arg0) {
1178
- const ret = getObject(arg0).length;
1179
- return ret;
1180
- };
1181
- imports.wbg.__wbg_new_16b304a2cfa7ff4a = function() {
1182
- const ret = new Array();
1183
- return addHeapObject(ret);
1184
- };
1185
- imports.wbg.__wbg_new_72fb9a18b5ae2624 = function() {
1186
- const ret = new Object();
1187
- return addHeapObject(ret);
1188
- };
1189
- imports.wbg.__wbg_set_d4638f722068f043 = function(arg0, arg1, arg2) {
1190
- getObject(arg0)[arg1 >>> 0] = takeObject(arg2);
1191
- };
1192
- imports.wbg.__wbg_from_89e3fc3ba5e6fb48 = function(arg0) {
1193
- const ret = Array.from(getObject(arg0));
1194
- return addHeapObject(ret);
1195
- };
1196
- imports.wbg.__wbg_push_a5b05aedc7234f9f = function(arg0, arg1) {
1197
- const ret = getObject(arg0).push(getObject(arg1));
1198
- return ret;
1199
- };
1200
- imports.wbg.__wbg_fromCodePoint_cedd7612a2ff688f = function() { return handleError(function (arg0) {
1201
- const ret = String.fromCodePoint(arg0 >>> 0);
1202
- return addHeapObject(ret);
1203
- }, arguments) };
1204
- imports.wbg.__wbg_buffer_12d079cc21e14bdb = function(arg0) {
1205
- const ret = getObject(arg0).buffer;
1206
- return addHeapObject(ret);
1207
- };
1208
- imports.wbg.__wbg_newwithbyteoffsetandlength_aa4a17c33a06e5cb = function(arg0, arg1, arg2) {
1209
- const ret = new Uint8Array(getObject(arg0), arg1 >>> 0, arg2 >>> 0);
1210
- return addHeapObject(ret);
1211
- };
1212
- imports.wbg.__wbg_new_63b92bc8671ed464 = function(arg0) {
1213
- const ret = new Uint8Array(getObject(arg0));
1214
- return addHeapObject(ret);
1215
- };
1216
- imports.wbg.__wbg_set_1f9b04f170055d33 = function() { return handleError(function (arg0, arg1, arg2) {
1217
- const ret = Reflect.set(getObject(arg0), getObject(arg1), getObject(arg2));
1218
- return ret;
1219
- }, arguments) };
1220
- imports.wbg.__wbindgen_throw = function(arg0, arg1) {
1221
- throw new Error(getStringFromWasm0(arg0, arg1));
1222
- };
1223
- imports.wbg.__wbindgen_memory = function() {
1224
- const ret = wasm.memory;
1225
- return addHeapObject(ret);
1226
- };
978
+ function __wbg_get_imports() {
979
+ const imports = {};
980
+ imports.wbg = {};
981
+ imports.wbg.__wbg_buffer_61b7ce01341d7f88 = function(arg0) {
982
+ const ret = arg0.buffer;
983
+ return ret;
984
+ };
985
+ imports.wbg.__wbg_fromCodePoint_ef89154c4db48bdf = function() { return handleError(function (arg0) {
986
+ const ret = String.fromCodePoint(arg0 >>> 0);
987
+ return ret;
988
+ }, arguments) };
989
+ imports.wbg.__wbg_from_d68eaa96dba25449 = function(arg0) {
990
+ const ret = Array.from(arg0);
991
+ return ret;
992
+ };
993
+ imports.wbg.__wbg_get_9aa3dff3f0266054 = function(arg0, arg1) {
994
+ const ret = arg0[arg1 >>> 0];
995
+ return ret;
996
+ };
997
+ imports.wbg.__wbg_length_d65cf0786bfc5739 = function(arg0) {
998
+ const ret = arg0.length;
999
+ return ret;
1000
+ };
1001
+ imports.wbg.__wbg_new_254fa9eac11932ae = function() {
1002
+ const ret = new Array();
1003
+ return ret;
1004
+ };
1005
+ imports.wbg.__wbg_new_3ff5b33b1ce712df = function(arg0) {
1006
+ const ret = new Uint8Array(arg0);
1007
+ return ret;
1008
+ };
1009
+ imports.wbg.__wbg_new_688846f374351c92 = function() {
1010
+ const ret = new Object();
1011
+ return ret;
1012
+ };
1013
+ imports.wbg.__wbg_newwithbyteoffsetandlength_ba35896968751d91 = function(arg0, arg1, arg2) {
1014
+ const ret = new Uint8Array(arg0, arg1 >>> 0, arg2 >>> 0);
1015
+ return ret;
1016
+ };
1017
+ imports.wbg.__wbg_push_6edad0df4b546b2c = function(arg0, arg1) {
1018
+ const ret = arg0.push(arg1);
1019
+ return ret;
1020
+ };
1021
+ imports.wbg.__wbg_set_1d80752d0d5f0b21 = function(arg0, arg1, arg2) {
1022
+ arg0[arg1 >>> 0] = arg2;
1023
+ };
1024
+ imports.wbg.__wbg_set_3f1d0b984ed272ed = function(arg0, arg1, arg2) {
1025
+ arg0[arg1] = arg2;
1026
+ };
1027
+ imports.wbg.__wbg_set_4e647025551483bd = function() { return handleError(function (arg0, arg1, arg2) {
1028
+ const ret = Reflect.set(arg0, arg1, arg2);
1029
+ return ret;
1030
+ }, arguments) };
1031
+ imports.wbg.__wbindgen_bigint_from_u64 = function(arg0) {
1032
+ const ret = BigInt.asUintN(64, arg0);
1033
+ return ret;
1034
+ };
1035
+ imports.wbg.__wbindgen_error_new = function(arg0, arg1) {
1036
+ const ret = new Error(getStringFromWasm0(arg0, arg1));
1037
+ return ret;
1038
+ };
1039
+ imports.wbg.__wbindgen_init_externref_table = function() {
1040
+ const table = wasm.__wbindgen_export_2;
1041
+ const offset = table.grow(4);
1042
+ table.set(0, undefined);
1043
+ table.set(offset + 0, undefined);
1044
+ table.set(offset + 1, null);
1045
+ table.set(offset + 2, true);
1046
+ table.set(offset + 3, false);
1047
+ ;
1048
+ };
1049
+ imports.wbg.__wbindgen_memory = function() {
1050
+ const ret = wasm.memory;
1051
+ return ret;
1052
+ };
1053
+ imports.wbg.__wbindgen_number_new = function(arg0) {
1054
+ const ret = arg0;
1055
+ return ret;
1056
+ };
1057
+ imports.wbg.__wbindgen_string_get = function(arg0, arg1) {
1058
+ const obj = arg1;
1059
+ const ret = typeof(obj) === 'string' ? obj : undefined;
1060
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1061
+ var len1 = WASM_VECTOR_LEN;
1062
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
1063
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
1064
+ };
1065
+ imports.wbg.__wbindgen_string_new = function(arg0, arg1) {
1066
+ const ret = getStringFromWasm0(arg0, arg1);
1067
+ return ret;
1068
+ };
1069
+ imports.wbg.__wbindgen_throw = function(arg0, arg1) {
1070
+ throw new Error(getStringFromWasm0(arg0, arg1));
1071
+ };
1072
+
1073
+ return imports;
1074
+ }
1227
1075
 
1228
- return imports;
1229
- }
1076
+ function __wbg_init_memory(imports, memory) {
1230
1077
 
1231
- function __wbg_init_memory(imports, maybe_memory) {
1078
+ }
1232
1079
 
1233
- }
1080
+ function __wbg_finalize_init(instance, module) {
1081
+ wasm = instance.exports;
1082
+ __wbg_init.__wbindgen_wasm_module = module;
1083
+ cachedDataViewMemory0 = null;
1084
+ cachedUint8ArrayMemory0 = null;
1234
1085
 
1235
- function __wbg_finalize_init(instance, module) {
1236
- wasm = instance.exports;
1237
- __wbg_init.__wbindgen_wasm_module = module;
1238
- cachedInt32Memory0 = null;
1239
- cachedUint32Memory0 = null;
1240
- cachedUint8Memory0 = null;
1241
1086
 
1087
+ wasm.__wbindgen_start();
1088
+ return wasm;
1089
+ }
1242
1090
 
1243
- return wasm;
1244
- }
1091
+ function initSync(module) {
1092
+ if (wasm !== undefined) return wasm;
1245
1093
 
1246
- function initSync(module) {
1247
- if (wasm !== undefined) return wasm;
1248
1094
 
1249
- const imports = __wbg_get_imports();
1095
+ if (typeof module !== 'undefined') {
1096
+ if (Object.getPrototypeOf(module) === Object.prototype) {
1097
+ ({module} = module)
1098
+ } else {
1099
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
1100
+ }
1101
+ }
1250
1102
 
1251
- __wbg_init_memory(imports);
1103
+ const imports = __wbg_get_imports();
1252
1104
 
1253
- if (!(module instanceof WebAssembly.Module)) {
1254
- module = new WebAssembly.Module(module);
1105
+ __wbg_init_memory(imports);
1106
+
1107
+ if (!(module instanceof WebAssembly.Module)) {
1108
+ module = new WebAssembly.Module(module);
1109
+ }
1110
+
1111
+ const instance = new WebAssembly.Instance(module, imports);
1112
+
1113
+ return __wbg_finalize_init(instance, module);
1255
1114
  }
1256
1115
 
1257
- const instance = new WebAssembly.Instance(module, imports);
1116
+ async function __wbg_init(module_or_path) {
1117
+ if (wasm !== undefined) return wasm;
1258
1118
 
1259
- return __wbg_finalize_init(instance, module);
1260
- }
1261
1119
 
1262
- async function __wbg_init(input) {
1263
- if (wasm !== undefined) return wasm;
1120
+ if (typeof module_or_path !== 'undefined') {
1121
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
1122
+ ({module_or_path} = module_or_path)
1123
+ } else {
1124
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
1125
+ }
1126
+ }
1264
1127
 
1265
- if (typeof input === 'undefined' && typeof script_src !== 'undefined') {
1266
- input = script_src.replace(/standalone\.js$/, 'rregex.wasm');
1267
- }
1268
- const imports = __wbg_get_imports();
1128
+ if (typeof module_or_path === 'undefined' && typeof script_src !== 'undefined') {
1129
+ module_or_path = script_src.replace(/standalone\.js$/, 'rregex.wasm');
1130
+ }
1131
+ const imports = __wbg_get_imports();
1269
1132
 
1270
- if (typeof input === 'string' || (typeof Request === 'function' && input instanceof Request) || (typeof URL === 'function' && input instanceof URL)) {
1271
- input = fetch(input);
1272
- }
1133
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
1134
+ module_or_path = fetch(module_or_path);
1135
+ }
1273
1136
 
1274
- __wbg_init_memory(imports);
1137
+ __wbg_init_memory(imports);
1275
1138
 
1276
- const { instance, module } = await __wbg_load(await input, imports);
1139
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
1277
1140
 
1278
- return __wbg_finalize_init(instance, module);
1279
- }
1141
+ return __wbg_finalize_init(instance, module);
1142
+ }
1280
1143
 
1281
- wasm_bindgen = Object.assign(__wbg_init, { initSync }, __exports);
1144
+ wasm_bindgen = Object.assign(__wbg_init, { initSync }, __exports);
1282
1145
 
1283
1146
  })();