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