rregex 1.9.0 → 1.9.2

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