rregex 1.13.3 → 2.0.0

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