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