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