@isopodlabs/utilities 1.5.5 → 1.5.6

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/dist/regexp.js ADDED
@@ -0,0 +1,659 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.endAnchor = exports.startAnchor = exports.nonWordBoundary = exports.wordBoundary = exports.octal = exports.hex = exports.alnum = exports.alpha = exports.upper = exports.lower = exports.whitespace = exports.word = exports.digit = exports.any = exports.characterClass = void 0;
4
+ exports.range = range;
5
+ exports.chars = chars;
6
+ exports.union = union;
7
+ exports.text = text;
8
+ exports.concatenation = concatenation;
9
+ exports.alternation = alternation;
10
+ exports.noncapture = noncapture;
11
+ exports.lookAhead = lookAhead;
12
+ exports.negLookAhead = negLookAhead;
13
+ exports.lookBehind = lookBehind;
14
+ exports.negLookBehind = negLookBehind;
15
+ exports.capture = capture;
16
+ exports.repeatFrom = repeatFrom;
17
+ exports.repeat = repeat;
18
+ exports.zeroOrMore = zeroOrMore;
19
+ exports.oneOrMore = oneOrMore;
20
+ exports.optional = optional;
21
+ exports.boundary = boundary;
22
+ exports.reference = reference;
23
+ exports.anchored = anchored;
24
+ exports.parse = parse;
25
+ exports.toRegExpString = toRegExpString;
26
+ exports.parseGlob = parseGlob;
27
+ exports.anchoredRe = anchoredRe;
28
+ exports.globToRe = globToRe;
29
+ exports.globToReMulti = globToReMulti;
30
+ const bits_1 = require("./bits");
31
+ /*
32
+ Characters
33
+ [xyz],[a-c] Character class
34
+ [^xyz],[^a-c] Negated character class
35
+ . Wildcard: Matches any single character except line terminators: \n, \r, \u2028 or \u2029
36
+ \d Digit character class escape: Matches any digit (Arabic numeral). Equivalent to [0-9]
37
+ \D Non-digit character class escape: Matches any character that is not a digit (Arabic numeral)
38
+ \w Word character class escape: Matches any alphanumeric character from the basic Latin alphabet, including the underscore. Equivalent to [A-Za-z0-9_]
39
+ \W Non-word character class escape: Matches any character that is not a word character from the basic Latin alphabet. Equivalent to [^A-Za-z0-9_]
40
+ \s White space character class escape: Matches a single white space character, including space, tab, form feed, line feed, and other Unicode spaces. Equivalent to [\f\n\r\t\v\u0020\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]
41
+ \S Non-white space character class escape
42
+ \t Matches a horizontal tab.
43
+ \r Matches a carriage return.
44
+ \n Matches a linefeed.
45
+ \v Matches a vertical tab.
46
+ \f Matches a form-feed.
47
+ [\b] Matches a backspace.
48
+ \0 Matches a NUL character.
49
+ \cX Matches a control character using caret notation, where "X" is a letter from A–Z
50
+ \xhh Matches the character with the code hh (two hexadecimal digits).
51
+ \uhhhh Matches a UTF-16 code-unit with the value hhhh (four hexadecimal digits).
52
+ \u{hhhh} or \u{hhhhh} (Only when the u flag is set.) Matches the character with the Unicode value U+hhhh or U+hhhhh (hexadecimal digits).
53
+ \p{UnicodeProperty}, \P{UnicodeProperty} Unicode character class escape: Matches a character based on its Unicode character properties
54
+ \ Indicates that the following character should be treated specially, or "escaped"
55
+
56
+ x|y Alternation: Matches either "x" or "y"
57
+
58
+ Boundary-type assertions
59
+ ^ Input boundary beginning assertion
60
+ $ Input boundary end assertion
61
+ \b Word boundary assertion
62
+ \B Non-word-boundary assertion
63
+
64
+ Other Assertions
65
+ x(?=y) Lookahead assertion
66
+ x(?!y) Negative lookahead assertion
67
+ (?<=y)x Lookbehind assertion
68
+ (?<!y)x Negative lookbehind assertion
69
+
70
+ Groups and backreferences
71
+ (x) Capturing group
72
+ (?<Name>x) Named capturing group
73
+ (?:x) Non-capturing group
74
+ (?flags:x), (?:flags-flags:x) Modifier (flags can be i, m, s)
75
+ \<int> Backreference
76
+ \k<Name> Named backreference
77
+
78
+ Quantifiers
79
+ x* Matches the preceding item "x" 0 or more times
80
+ x+ Matches the preceding item "x" 1 or more times. Equivalent to {1,}
81
+ x? Matches the preceding item "x" 0 or 1 times. For example, /e?le?/ matches the "el" in "angel" and the "le" in "angle."
82
+ x{<int>} Matches exactly "n" occurrences of the preceding item "x"
83
+ x{<int>,} Matches at least "n" occurrences of the preceding item "x"
84
+ x{n,m} Matches at least "n" and at most "m" occurrences of the preceding item "x"
85
+
86
+ Non greedy quantifiers
87
+ x*?
88
+ x+?
89
+ x??
90
+ x{n}?
91
+ x{n,}?
92
+ x{n,m}?
93
+
94
+ */
95
+ const posixClasses = {
96
+ alnum: '\\p{L}\\p{Nl}\\p{Nd}',
97
+ alpha: '\\p{L}\\p{Nl}',
98
+ ascii: '\\x00-\\x7f',
99
+ blank: '\\p{Zs}\\t',
100
+ cntrl: '\\p{Cc}',
101
+ digit: '\\p{Nd}',
102
+ graph: '^\\p{Z}\\p{C}',
103
+ lower: '\\p{Ll}',
104
+ print: '\\p{C}',
105
+ punct: '\\p{P}',
106
+ space: '\\p{Z}\\t\\r\\n\\v\\f',
107
+ upper: '\\p{Lu}',
108
+ word: '\\p{L}\\p{Nl}\\p{Nd}\\p{Pc}',
109
+ xdigit: 'A-Fa-f0-9',
110
+ };
111
+ class characterClass extends bits_1.SparseBits {
112
+ type = 'class';
113
+ setChar(char) {
114
+ this.set(char.charCodeAt(0));
115
+ }
116
+ test(char) {
117
+ return this.has(char.charCodeAt(0));
118
+ }
119
+ setString(c) {
120
+ for (let i = 0; i < c.length; i++)
121
+ this.set(c.charCodeAt(i));
122
+ return this;
123
+ }
124
+ clearString(c) {
125
+ for (let i = 0; i < c.length; i++)
126
+ this.clear(c.charCodeAt(i));
127
+ return this;
128
+ }
129
+ toString() {
130
+ let s = this.undef ? '^' : '';
131
+ for (const i in this.bits) {
132
+ const b = this.bits[i] ^ this.undef;
133
+ const c0 = +i * 32;
134
+ for (let j = 0; j < 32; j++) {
135
+ if (b & (1 << j)) {
136
+ const c1 = c0 + j;
137
+ while (j < 32 && (b & (1 << j)))
138
+ j++;
139
+ const c2 = c0 + j - 1;
140
+ s += String.fromCharCode(c1).replace(/[-\\\]]/g, '\\$&');
141
+ if (c1 !== c2)
142
+ s += '-' + String.fromCharCode(c2).replace(/[-\\\]]/g, '\\$&');
143
+ }
144
+ }
145
+ }
146
+ return s;
147
+ }
148
+ static fromString(value) {
149
+ return new characterClass(false).setString(value);
150
+ }
151
+ }
152
+ exports.characterClass = characterClass;
153
+ ;
154
+ // characterClass helpers
155
+ function range(from, to) {
156
+ return new characterClass(false).setRange(from.charCodeAt(0), to.charCodeAt(0) + 1);
157
+ }
158
+ function chars(chars) {
159
+ return new characterClass(false).setString(chars);
160
+ }
161
+ function union(...classes) {
162
+ const result = new characterClass(false);
163
+ for (const cls of classes)
164
+ result.union(cls);
165
+ return result;
166
+ }
167
+ // Common character class constants and ranges
168
+ exports.any = new characterClass(true); //.clearString('\n\r\u2028\u2029');
169
+ exports.digit = range('0', '9'); //digit
170
+ exports.word = range('a', 'z').union(range('A', 'Z')).union(range('0', '9')).union(chars('_')); //word
171
+ exports.whitespace = chars(' \t\r\n\f\v'); //whitespace
172
+ exports.lower = range('a', 'z');
173
+ exports.upper = range('A', 'Z');
174
+ exports.alpha = exports.lower.union(exports.upper);
175
+ exports.alnum = exports.alpha.union(exports.digit);
176
+ exports.hex = exports.digit.union(chars('abcdefABCDEF'));
177
+ exports.octal = range('0', '7');
178
+ function text(c) {
179
+ return c;
180
+ }
181
+ function concatenation(parts) {
182
+ return parts.length === 1 ? parts[0] : parts;
183
+ }
184
+ function alternation(parts) {
185
+ return parts.length === 1 ? parts[0] : { type: 'alt', parts };
186
+ }
187
+ ;
188
+ function noncapture(part, options) {
189
+ return { type: 'noncapture', part, options };
190
+ }
191
+ function lookAhead(part) { return noncapture(part, 'ahead'); }
192
+ function negLookAhead(part) { return noncapture(part, 'neg_ahead'); }
193
+ function lookBehind(part) { return noncapture(part, 'behind'); }
194
+ function negLookBehind(part) { return noncapture(part, 'neg_behind'); }
195
+ function capture(part, name) {
196
+ return { type: 'capture', part, name };
197
+ }
198
+ function repeatFrom(part, min, max = -1, greedy = true) {
199
+ return { type: 'quantified', part, min, max, greedy };
200
+ }
201
+ function repeat(part, n, greedy = true) {
202
+ return { type: 'quantified', part, min: n, max: n, greedy };
203
+ }
204
+ function zeroOrMore(part, greedy = true) { return repeatFrom(part, 0, -1, greedy); }
205
+ function oneOrMore(part, greedy = true) { return repeatFrom(part, 1, -1, greedy); }
206
+ function optional(part, greedy = true) { return repeatFrom(part, 0, 1, greedy); }
207
+ function boundary(type) {
208
+ return { type };
209
+ }
210
+ exports.wordBoundary = boundary('wordbound');
211
+ exports.nonWordBoundary = boundary('nowordbound');
212
+ exports.startAnchor = boundary('inputboundstart');
213
+ exports.endAnchor = boundary('inputboundend');
214
+ function reference(value) {
215
+ return { type: 'reference', value };
216
+ }
217
+ function anchored(part) {
218
+ return [exports.startAnchor, part, exports.endAnchor];
219
+ }
220
+ /*
221
+ function is0<T extends part0['type']>(part: part, type: T): part is Extract<part0, { type: T }> {
222
+ return typeof part !== 'string' && !Array.isArray(part) && part.type === type;
223
+ }
224
+ */
225
+ function is(part, type) {
226
+ return typeof part === 'string' ? type === 'text'
227
+ : Array.isArray(part) ? type === 'concat'
228
+ : part.type === type;
229
+ }
230
+ function parse(re, unicode = true) {
231
+ const stack = [];
232
+ let curr = [];
233
+ let i = 0;
234
+ function skipTo(c) {
235
+ const start = i;
236
+ while (i < re.length && re[i] !== c)
237
+ i++;
238
+ if (re[i] !== c)
239
+ throw new Error(`Missing '${c}'`);
240
+ return re.substring(start, i++);
241
+ }
242
+ function int() {
243
+ const start = i;
244
+ while (re[i] >= '0' && re[i] <= '9')
245
+ i++;
246
+ return parseInt(re.substring(start, i));
247
+ }
248
+ function backslashed() {
249
+ const c = re[i++];
250
+ switch (c) {
251
+ default: return c.charCodeAt(0);
252
+ case 'd': return exports.digit; //digit
253
+ case 'D': return exports.digit.not(); //non-digit
254
+ case 'w': return exports.word; //word
255
+ case 'W': return exports.word.not(); //non-word
256
+ case 's': return exports.whitespace; //whitespace
257
+ case 'S': return exports.whitespace.not(); //non-whitespace
258
+ case 'b': return 8; //backspace
259
+ case 't': return 9; //tab
260
+ case 'n': return 10; //newline
261
+ case 'v': return 11; //vertical tab
262
+ case 'f': return 12; //form feed
263
+ case 'r': return 13; //carriage return
264
+ case 'c': return re.charCodeAt(i++) & 31; //control character
265
+ case '0': {
266
+ const start = i - 1;
267
+ while (re[i] >= '0' && re[i] <= '7' && i - start < 4)
268
+ i++;
269
+ return parseInt(re.substring(start, i), 8);
270
+ }
271
+ case 'x':
272
+ if (i + 2 > re.length)
273
+ throw new Error('bad \\x escape');
274
+ i += 2;
275
+ return parseInt(re.substring(i - 2, i), 16);
276
+ case 'u':
277
+ if (unicode && re[i] === '{') {
278
+ i++; // skip '{'
279
+ return parseInt(skipTo('}'), 16);
280
+ }
281
+ if (i + 4 > re.length)
282
+ throw new Error('bad \\u escape');
283
+ i += 4;
284
+ return parseInt(re.substring(i - 4, i), 16);
285
+ case 'p':
286
+ case 'P':
287
+ if (!unicode || re[i] !== '{')
288
+ throw new Error('\\p and \\P can only be used with unicode enabled, and must be followed by {property}');
289
+ i++; // skip '{'
290
+ return { type: c === 'P' ? 'notunicode' : 'unicode', property: skipTo('}') };
291
+ }
292
+ }
293
+ function character() {
294
+ const code = unicode ? re.codePointAt(i++) : re.charCodeAt(i++);
295
+ if (code > 0xffff) {
296
+ ++i;
297
+ return code;
298
+ }
299
+ return code === 92 ? backslashed() : code;
300
+ }
301
+ function addQuantified(min, max) {
302
+ const greedy = re[i] !== '?';
303
+ if (!greedy)
304
+ i++;
305
+ const top = curr.pop();
306
+ if (!top)
307
+ throw new Error('nothing to quantify');
308
+ if (typeof top === 'string' && top.length > 1) {
309
+ curr.push(top.slice(0, -1));
310
+ curr.push(repeatFrom(top.slice(-1), min, max, greedy));
311
+ }
312
+ else {
313
+ curr.push(repeatFrom(top, min, max, greedy));
314
+ }
315
+ }
316
+ function addText(c) {
317
+ if (typeof curr.at(-1) === 'string') {
318
+ curr[curr.length - 1] += c;
319
+ }
320
+ else {
321
+ curr.push(c);
322
+ }
323
+ }
324
+ function closeAlt() {
325
+ let top = stack.pop();
326
+ if (top?.type === 'alt') {
327
+ top.parts.push(concatenation(curr));
328
+ curr = [top];
329
+ top = stack.pop();
330
+ }
331
+ return top;
332
+ }
333
+ const specialChars = /[\\^$*+?{()|[.]/;
334
+ while (i < re.length) {
335
+ const remaining = re.substring(i);
336
+ const next = remaining.search(specialChars);
337
+ if (next === -1) {
338
+ addText(remaining);
339
+ break;
340
+ }
341
+ if (next > 0)
342
+ addText(remaining.substring(0, next));
343
+ i += next;
344
+ switch (re[i++]) {
345
+ case '\\':
346
+ if (re[i] === 'b') {
347
+ i++;
348
+ curr.push(exports.wordBoundary);
349
+ }
350
+ else if (re[i] === 'B') {
351
+ i++;
352
+ curr.push(exports.nonWordBoundary);
353
+ }
354
+ else if (re[i] >= '1' && re[i] <= '9') {
355
+ const n = int();
356
+ curr.push({ type: 'reference', value: n });
357
+ }
358
+ else if (re[i] === 'k' && re[i + 1] === '<') {
359
+ i += 2;
360
+ const name = skipTo('>');
361
+ curr.push({ type: 'reference', value: name });
362
+ }
363
+ else {
364
+ const b = backslashed();
365
+ if (typeof b === 'number')
366
+ addText(String.fromCodePoint(b));
367
+ else
368
+ curr.push(b);
369
+ }
370
+ break;
371
+ case '.':
372
+ curr.push(exports.any);
373
+ break;
374
+ //Boundary-type assertions
375
+ case '^':
376
+ curr.push(exports.startAnchor);
377
+ break;
378
+ case '$':
379
+ curr.push(exports.endAnchor);
380
+ break;
381
+ //Quantifiers
382
+ case '*':
383
+ addQuantified(0, -1);
384
+ break;
385
+ case '+':
386
+ addQuantified(1, -1);
387
+ break;
388
+ case '?':
389
+ addQuantified(0, 1);
390
+ break;
391
+ case '{': {
392
+ const min = int();
393
+ let max = min;
394
+ if (re[i] === ',') {
395
+ ++i; // skip ','
396
+ max = re[i] !== '}' ? int() : -1;
397
+ }
398
+ ++i; // skip '}'
399
+ addQuantified(min, max);
400
+ break;
401
+ }
402
+ //Alternation
403
+ case '|': {
404
+ const top = stack.at(-1);
405
+ if (top?.type === 'alt') {
406
+ top.parts.push(concatenation(curr));
407
+ }
408
+ else {
409
+ stack.push({ type: 'alt', parts: [concatenation(curr)] });
410
+ }
411
+ curr = [];
412
+ break;
413
+ }
414
+ //Groups
415
+ case '(':
416
+ let group;
417
+ const dummy = ''; //text(''); // placeholder
418
+ if (re[i] === '?') {
419
+ i++;
420
+ switch (re[i++]) {
421
+ case ':':
422
+ group = noncapture(dummy);
423
+ break;
424
+ case '=':
425
+ group = noncapture(dummy, 'ahead');
426
+ break;
427
+ case '!':
428
+ group = noncapture(dummy, 'neg_ahead');
429
+ break;
430
+ case '<':
431
+ if (re[i] === '=') {
432
+ i++;
433
+ group = noncapture(dummy, 'behind');
434
+ }
435
+ else if (re[i] === '!') {
436
+ i++;
437
+ group = noncapture(dummy, 'neg_behind');
438
+ }
439
+ else {
440
+ group = capture(dummy, skipTo('>'));
441
+ }
442
+ break;
443
+ default: {
444
+ let set = true;
445
+ const flags = {};
446
+ --i; // go back to first flag character
447
+ while (i < re.length) {
448
+ const f = re[i++];
449
+ if (f === ':')
450
+ break;
451
+ if (f === '-')
452
+ set = false;
453
+ else if (f === 'i' || f === 'm' || f === 's')
454
+ flags[f] = set;
455
+ }
456
+ group = noncapture(dummy, flags);
457
+ break;
458
+ }
459
+ }
460
+ }
461
+ else {
462
+ group = capture(dummy, '');
463
+ }
464
+ stack.push({ type: 'group', group: group, tos: curr });
465
+ curr = [];
466
+ break;
467
+ case ')': {
468
+ const top = closeAlt();
469
+ if (top?.type !== 'group')
470
+ throw new Error('unmatched )');
471
+ top.group.part = concatenation(curr);
472
+ curr = [...top.tos, top.group];
473
+ break;
474
+ }
475
+ //Character classes
476
+ case '[': {
477
+ const neg = re[i] === '^';
478
+ if (neg)
479
+ i++;
480
+ let cs = new characterClass(false);
481
+ if (re[i] === ']' || re[i] === '-')
482
+ cs.set(re.charCodeAt(i++));
483
+ while (i < re.length && re[i] !== ']') {
484
+ const from = character();
485
+ if (typeof from === 'number') {
486
+ if (re[i] === '-' && i + 1 < re.length && re[i + 1] !== ']') {
487
+ ++i;
488
+ const to = character();
489
+ if (typeof to !== 'number' || from > to)
490
+ throw new Error('bad character class');
491
+ cs.setRange(from, to + 1);
492
+ }
493
+ else {
494
+ cs.set(from);
495
+ }
496
+ }
497
+ else if (is(from, 'class')) {
498
+ cs.selfUnion(from);
499
+ }
500
+ }
501
+ i++; // skip ']'
502
+ curr.push(neg ? cs.selfNot() : cs);
503
+ break;
504
+ }
505
+ }
506
+ }
507
+ const top = closeAlt();
508
+ if (top)
509
+ throw new Error('unmatched (');
510
+ return concatenation(curr);
511
+ }
512
+ function list(parts, join) {
513
+ return parts.map(p => {
514
+ const s = toRegExpString(p);
515
+ return is(p, 'alt') ? `(?:${s})` : s;
516
+ }).join(join);
517
+ }
518
+ function toRegExpString(part) {
519
+ if (typeof part === 'string')
520
+ return part.replace(/[\\^$*+?.()|[\]{}]/g, '\\$&');
521
+ if (Array.isArray(part))
522
+ return list(part, '');
523
+ switch (part.type) {
524
+ case 'alt':
525
+ return list(part.parts, '|');
526
+ case 'quantified':
527
+ return toRegExpString(part.part) + (part.min === 0 && part.max === -1 ? '*'
528
+ : part.min === 1 && part.max === -1 ? '+'
529
+ : part.min === 0 && part.max === 1 ? '?'
530
+ : part.max === -1 ? `{${part.min},}`
531
+ : part.min === part.max ? `{${part.min}}`
532
+ : `{${part.min},${part.max}}`) + (part.greedy ? '' : '?');
533
+ case 'noncapture': {
534
+ let header = '';
535
+ const opts = part.options;
536
+ if (opts) {
537
+ if (typeof opts === 'string') {
538
+ header = {
539
+ ahead: '=',
540
+ behind: '<=',
541
+ neg_ahead: '!',
542
+ neg_behind: '<!'
543
+ }[opts];
544
+ }
545
+ else if ((opts.i ?? opts.m ?? opts.s) !== undefined) {
546
+ let posflags = (opts.i ? 'i' : '') + (opts.m ? 'm' : '') + (opts.s ? 's' : '');
547
+ let negflags = (opts.i === false ? 'i' : '') + (opts.m === false ? 'm' : '') + (opts.s === false ? 's' : '');
548
+ header = `${posflags}${negflags ? '-' : ''}${negflags}:`;
549
+ }
550
+ }
551
+ return `(?${header}${toRegExpString(part.part)})`;
552
+ }
553
+ case 'capture':
554
+ return `(${part.name ? `?<${part.name}>` : ''}${toRegExpString(part.part)})`;
555
+ case 'class':
556
+ return `[${part.toString()}]`;
557
+ case 'unicode':
558
+ return `\\p{${part.property}}`;
559
+ case 'notunicode':
560
+ return `\\P{${part.property}}`;
561
+ case 'wordbound':
562
+ return '\\b';
563
+ case 'nowordbound':
564
+ return '\\B';
565
+ case 'inputboundstart':
566
+ return '^';
567
+ case 'inputboundend':
568
+ return '$';
569
+ case 'reference':
570
+ return typeof part.value === 'number' ? `\\${part.value}` : `\\k<${part.value}>`;
571
+ }
572
+ }
573
+ function parseGlob(glob) {
574
+ let result = '';
575
+ let depth = 0;
576
+ for (let i = 0; i < glob.length; ++i) {
577
+ let c = glob[i];
578
+ switch (c) {
579
+ case '\\':
580
+ c = glob[++i];
581
+ if ('*?+.,^$()|[]a-zA-Z'.includes(c))
582
+ result += '\\';
583
+ break;
584
+ case '*':
585
+ if (glob[i + 1] === '*') {
586
+ result += '.*';
587
+ ++i;
588
+ }
589
+ else {
590
+ result += '[^/]*';
591
+ }
592
+ continue;
593
+ case '?':
594
+ c = '.';
595
+ break;
596
+ case '+':
597
+ case '.':
598
+ case '^':
599
+ case '$':
600
+ case '(':
601
+ case ')':
602
+ case '|':
603
+ result += `\\`;
604
+ break;
605
+ case '[': {
606
+ const end = glob.indexOf(']', i + 1);
607
+ if (end > i) {
608
+ const next = glob[i + 1];
609
+ if (next === ':' && glob[end - 1] === ':') {
610
+ const p = posixClasses[glob.slice(i + 2, end - 1)];
611
+ if (p) {
612
+ result += `[${p}]`;
613
+ i = end;
614
+ continue;
615
+ }
616
+ else {
617
+ console.log(`Warning: Unknown POSIX class ${glob.slice(i + 2, end - 1)} in glob pattern ${glob}`);
618
+ }
619
+ }
620
+ const neg = next === '!' || next === '^';
621
+ result += `[${neg ? '^' : ''}${glob.slice(neg ? i + 2 : i + 1, end)}]`;
622
+ i = end;
623
+ continue;
624
+ }
625
+ result += '\\';
626
+ break;
627
+ }
628
+ case '{':
629
+ ++depth;
630
+ c = '(';
631
+ break;
632
+ case '}':
633
+ if (depth > 0) {
634
+ --depth;
635
+ c = ')';
636
+ }
637
+ break;
638
+ case ',':
639
+ if (depth > 0)
640
+ c = '|';
641
+ break;
642
+ }
643
+ result += c;
644
+ }
645
+ if (depth > 0) {
646
+ console.log(`Warning: Unmatched { in glob pattern ${glob}`);
647
+ result += ')'.repeat(depth);
648
+ }
649
+ return result;
650
+ }
651
+ function anchoredRe(re) {
652
+ return new RegExp(`^${re}$`);
653
+ }
654
+ function globToRe(glob) {
655
+ return anchoredRe(parseGlob(glob));
656
+ }
657
+ function globToReMulti(globs) {
658
+ return anchoredRe(globs.map(parseGlob).join('|'));
659
+ }
package/dist/string.d.ts CHANGED
@@ -26,7 +26,3 @@ export declare class StringParser {
26
26
  match(re: RegExp): string | undefined;
27
27
  exec(re: RegExp): RegExpExecArray | undefined;
28
28
  }
29
- export declare function parseGlob(glob: string): string;
30
- export declare function anchoredRe(re: string): RegExp;
31
- export declare function globToRe(glob: string): RegExp;
32
- export declare function globToReMulti(globs: string[]): RegExp;