@formvk/path 0.0.0-stage → 1.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/dist/index.js ADDED
@@ -0,0 +1,1334 @@
1
+ // src/shared.ts
2
+ var toString = Object.prototype.toString;
3
+ function isType$1(type) {
4
+ return (obj) => toString.call(obj) === `[object ${type}]`;
5
+ }
6
+ var isFn = isType$1("Function");
7
+ var isArr = Array.isArray || isType$1("Array");
8
+ var isStr = isType$1("String");
9
+ var isNum = isType$1("Number");
10
+ function isObj(val) {
11
+ return typeof val === "object";
12
+ }
13
+ var isRegExp = isType$1("RegExp");
14
+ function isNumberLike(t) {
15
+ return isNum(t) || /^(\d+)(\.\d+)?$/.test(t);
16
+ }
17
+ var isArray = isArr;
18
+ var keyList = Object.keys;
19
+ var hasProp = Object.prototype.hasOwnProperty;
20
+ function toArr(val) {
21
+ return Array.isArray(val) ? val : val !== void 0 ? [val] : [];
22
+ }
23
+ function isEqual(a, b) {
24
+ if (a === b) return true;
25
+ if (a && b && typeof a === "object" && typeof b === "object") {
26
+ const arrA = isArray(a);
27
+ const arrB = isArray(b);
28
+ let i;
29
+ let length;
30
+ let key;
31
+ if (arrA && arrB) {
32
+ length = a.length;
33
+ if (length !== b.length) return false;
34
+ for (i = length; i-- !== 0;) if (!isEqual(a[i], b[i])) return false;
35
+ return true;
36
+ }
37
+ if (arrA !== arrB) return false;
38
+ const keys = keyList(a);
39
+ length = keys.length;
40
+ if (length !== keyList(b).length) return false;
41
+ for (i = length; i-- !== 0;) if (!hasProp.call(b, keys[i])) return false;
42
+ for (i = length; i-- !== 0;) {
43
+ key = keys[i];
44
+ if (!isEqual(a[key], b[key])) return false;
45
+ }
46
+ return true;
47
+ }
48
+ return a !== a && b !== b;
49
+ }
50
+ function isSegmentEqual(a, b) {
51
+ a = typeof a === "symbol" ? a : `${a}`;
52
+ b = typeof b === "symbol" ? b : `${b}`;
53
+ return a === b;
54
+ }
55
+ // src/types.ts
56
+ function isType(type) {
57
+ return (obj) => {
58
+ return obj && obj.type === type;
59
+ };
60
+ }
61
+ var isIdentifier = isType("Identifier");
62
+ var isIgnoreExpression = isType("IgnoreExpression");
63
+ var isDotOperator = isType("DotOperator");
64
+ var isWildcardOperator = isType("WildcardOperator");
65
+ var isExpandOperator = isType("ExpandOperator");
66
+ var isGroupExpression = isType("GroupExpression");
67
+ var isRangeExpression = isType("RangeExpression");
68
+ var isDestructorExpression = isType("DestructorExpression");
69
+ var isObjectPattern = isType("ObjectPattern");
70
+ var isArrayPattern = isType("ArrayPattern");
71
+ // src/destructor.ts
72
+ var DestructorCache = /* @__PURE__ */ new Map();
73
+ function isValid$1(val) {
74
+ return val !== void 0 && val !== null;
75
+ }
76
+ function getDestructor(source) {
77
+ return DestructorCache.get(source);
78
+ }
79
+ function setDestructor(source, rules) {
80
+ DestructorCache.set(source, rules);
81
+ }
82
+ function parseDestructorRules(node) {
83
+ const rules = [];
84
+ if (isObjectPattern(node)) {
85
+ let index = 0;
86
+ node.properties.forEach((child) => {
87
+ rules[index] = { path: [] };
88
+ rules[index].key = child.key.value;
89
+ rules[index].path.push(child.key.value);
90
+ if (isIdentifier(child.value)) rules[index].key = child.value.value;
91
+ const basePath = rules[index].path;
92
+ const childRules = parseDestructorRules(child.value);
93
+ let k = index;
94
+ childRules.forEach((rule) => {
95
+ if (rules[k]) {
96
+ rules[k].key = rule.key;
97
+ rules[k].path = basePath.concat(rule.path);
98
+ } else rules[k] = {
99
+ key: rule.key,
100
+ path: basePath.concat(rule.path)
101
+ };
102
+ k++;
103
+ });
104
+ if (k > index) index = k;
105
+ else index++;
106
+ });
107
+ return rules;
108
+ } else if (isArrayPattern(node)) {
109
+ let index = 0;
110
+ node.elements.forEach((child, key) => {
111
+ rules[index] = { path: [] };
112
+ rules[index].key = key;
113
+ rules[index].path.push(key);
114
+ if (isIdentifier(child)) rules[index].key = child.value;
115
+ const basePath = rules[index].path;
116
+ const childRules = parseDestructorRules(child);
117
+ let k = index;
118
+ childRules.forEach((rule) => {
119
+ if (rules[k]) {
120
+ rules[k].key = rule.key;
121
+ rules[k].path = basePath.concat(rule.path);
122
+ } else rules[k] = {
123
+ key: rule.key,
124
+ path: basePath.concat(rule.path)
125
+ };
126
+ k++;
127
+ });
128
+ if (k > index) index = k;
129
+ else index++;
130
+ });
131
+ return rules;
132
+ }
133
+ if (isDestructorExpression(node)) return parseDestructorRules(node.value);
134
+ return rules;
135
+ }
136
+ function setInByDestructor(source, rules, value, mutators) {
137
+ rules.forEach(({ key, path }) => {
138
+ mutators.setIn([key], source, mutators.getIn(path, value));
139
+ });
140
+ }
141
+ function getInByDestructor(source, rules, mutators) {
142
+ let response = {};
143
+ if (rules.length) {
144
+ if (isNum(rules[0].path[0])) response = [];
145
+ }
146
+ source = isValid$1(source) ? source : {};
147
+ rules.forEach(({ key, path }) => {
148
+ mutators.setIn(path, response, source[key]);
149
+ });
150
+ return response;
151
+ }
152
+ function deleteInByDestructor(source, rules, mutators) {
153
+ rules.forEach(({ key }) => {
154
+ mutators.deleteIn?.([key], source);
155
+ });
156
+ }
157
+ function existInByDestructor(source, rules, start, mutators) {
158
+ return rules.every(({ key }) => {
159
+ return mutators.existIn?.([key], source, start);
160
+ });
161
+ }
162
+ // src/matcher.ts
163
+ var Matcher = class {
164
+ tree;
165
+ stack;
166
+ record;
167
+ excluding;
168
+ wildcards;
169
+ path = [];
170
+ constructor(tree, record) {
171
+ this.tree = tree;
172
+ this.stack = [];
173
+ this.excluding = false;
174
+ this.wildcards = [];
175
+ this.record = record;
176
+ }
177
+ next(node, pos) {
178
+ if (node.after) return this.matchNode(node.after, pos);
179
+ if (isWildcardOperator(node) && !node.filter) {
180
+ if (this.excluding) return false;
181
+ else {
182
+ if (pos === 0 || node.optional) return true;
183
+ return !!this.take(pos);
184
+ }
185
+ }
186
+ if (pos === this.path.length - 1) return !!this.take(pos);
187
+ else {
188
+ const wildcard = this.wildcards.pop();
189
+ if (wildcard && wildcard.after) return this.next(wildcard, pos);
190
+ }
191
+ return false;
192
+ }
193
+ shot() {
194
+ if (this.record && this.record.score >= 0) this.record.score++;
195
+ }
196
+ take(pos) {
197
+ return String(this.path[pos] ?? "");
198
+ }
199
+ matchExcludeIdentifier(matched, node, pos) {
200
+ const isLastToken = pos === this.path.length - 1;
201
+ const isContainToken = pos < this.path.length;
202
+ if (!node.after) this.excluding = false;
203
+ if (matched) {
204
+ if (node.after) return this.next(node, pos);
205
+ if (isLastToken) return false;
206
+ }
207
+ if (isLastToken) return true;
208
+ return isContainToken;
209
+ }
210
+ matchIdentifier(node, pos) {
211
+ const current = this.take(pos);
212
+ let matched = false;
213
+ if (isExpandOperator(node.after)) {
214
+ if (current.indexOf(node.value) === 0) {
215
+ this.shot();
216
+ matched = true;
217
+ }
218
+ if (this.excluding) return this.matchExcludeIdentifier(matched, node.after, pos);
219
+ else return matched && this.next(node.after, pos);
220
+ } else if (current === node.value) {
221
+ this.shot();
222
+ matched = true;
223
+ }
224
+ if (this.excluding) return this.matchExcludeIdentifier(matched, node, pos);
225
+ else return matched && this.next(node, pos);
226
+ }
227
+ matchIgnoreExpression(node, pos) {
228
+ return isEqual(node.value, this.take(pos)) && this.next(node, pos);
229
+ }
230
+ matchDestructorExpression(node, pos) {
231
+ return isEqual(node.source, this.take(pos)) && this.next(node, pos);
232
+ }
233
+ matchExpandOperator(node, pos) {
234
+ return this.next(node, pos);
235
+ }
236
+ matchWildcardOperator(node, pos) {
237
+ let matched = false;
238
+ if (node.filter) {
239
+ this.stack.push(node);
240
+ matched = this.matchNode(node.filter, pos);
241
+ this.stack.pop();
242
+ } else matched = this.next(node, pos);
243
+ return matched;
244
+ }
245
+ matchGroupExpression(node, pos) {
246
+ let excluding = false;
247
+ if (node.isExclude) excluding = !this.excluding;
248
+ return toArr(node.value)[excluding ? "every" : "some"]((item) => {
249
+ this.wildcards = this.stack.slice();
250
+ this.excluding = excluding;
251
+ return this.matchNode(item, pos);
252
+ });
253
+ }
254
+ matchRangeExpression(node, pos) {
255
+ const current = Number(this.take(pos));
256
+ if (node.start) {
257
+ if (node.end) return current >= Number(node.start.value) && current <= Number(node.end.value);
258
+ else return current >= Number(node.start.value);
259
+ } else if (node.end) return current <= Number(node.end.value);
260
+ else {
261
+ this.wildcards = this.stack.slice();
262
+ return this.next(node, pos);
263
+ }
264
+ }
265
+ matchNode(node, pos = 0) {
266
+ if (isDotOperator(node)) return this.next(node, pos + 1);
267
+ else if (isIdentifier(node)) return this.matchIdentifier(node, pos);
268
+ else if (isIgnoreExpression(node)) return this.matchIgnoreExpression(node, pos);
269
+ else if (isDestructorExpression(node)) return this.matchDestructorExpression(node, pos);
270
+ else if (isExpandOperator(node)) return this.matchExpandOperator(node, pos);
271
+ else if (isWildcardOperator(node)) return this.matchWildcardOperator(node, pos);
272
+ else if (isGroupExpression(node)) return this.matchGroupExpression(node, pos);
273
+ else if (isRangeExpression(node)) return this.matchRangeExpression(node, pos);
274
+ return false;
275
+ }
276
+ match(path) {
277
+ this.path = path;
278
+ return {
279
+ matched: this.matchNode(this.tree),
280
+ record: this.record
281
+ };
282
+ }
283
+ static matchSegments(source, target, record) {
284
+ if (source.length !== target.length) return {
285
+ matched: false,
286
+ record
287
+ };
288
+ function match(pos = 0) {
289
+ const current = isSegmentEqual(source[pos], target[pos]);
290
+ if (record?.score >= 0) record.score++;
291
+ return current && (pos < source.length - 1 ? match(pos + 1) : true);
292
+ }
293
+ return {
294
+ matched: match(),
295
+ record
296
+ };
297
+ }
298
+ };
299
+ // src/contexts.ts
300
+ function ContextType(flag, props) {
301
+ return {
302
+ flag,
303
+ ...props
304
+ };
305
+ }
306
+ var bracketContext = ContextType("[]");
307
+ var bracketArrayContext = ContextType("[\\d]");
308
+ var bracketDContext = ContextType("[[]]");
309
+ var parenContext = ContextType("()");
310
+ var braceContext = ContextType("{}");
311
+ var destructorContext = ContextType("{x}");
312
+ // src/tokens.ts
313
+ function TokenType(flag, props) {
314
+ return {
315
+ flag,
316
+ ...props
317
+ };
318
+ }
319
+ var nameTok = TokenType("name", { expectNext(next) {
320
+ if (this.includesContext(destructorContext)) return next === nameTok || next === commaTok || next === bracketRTok || next === braceRTok || next === colonTok;
321
+ return next === dotTok || next === commaTok || next === eofTok || next === bracketRTok || next === parenRTok || next === colonTok || next === expandTok || next === bracketLTok;
322
+ } });
323
+ var starTok = TokenType("*", { expectNext(next) {
324
+ return next === dotTok || next === parenLTok || next === bracketLTok || next === eofTok || next === commaTok || next === parenRTok;
325
+ } });
326
+ var dbStarTok = TokenType("**", { expectNext(next) {
327
+ return next === dotTok || next === bracketLTok || next === eofTok || next === commaTok || next === parenRTok;
328
+ } });
329
+ var dotTok = TokenType(".", {
330
+ expectNext(next) {
331
+ return next === dotTok || next === nameTok || next === bracketDLTok || next === starTok || next === dbStarTok || next === bracketLTok || next === braceLTok || next === eofTok;
332
+ },
333
+ expectPrev(prev) {
334
+ return prev === dotTok || prev === nameTok || prev === bracketDRTok || prev === starTok || prev === parenRTok || prev === bracketRTok || prev === expandTok || prev === braceRTok;
335
+ }
336
+ });
337
+ var bangTok = TokenType("!", { expectNext(next) {
338
+ return next === nameTok || next === bracketDLTok;
339
+ } });
340
+ var colonTok = TokenType(":", { expectNext(next) {
341
+ if (this.includesContext(destructorContext)) return next === nameTok || next === braceLTok || next === bracketLTok;
342
+ return next === nameTok || next === bracketDLTok || next === bracketRTok;
343
+ } });
344
+ var braceLTok = TokenType("{", {
345
+ expectNext(next) {
346
+ return next === nameTok;
347
+ },
348
+ expectPrev(prev) {
349
+ if (this.includesContext(destructorContext)) return prev === colonTok || prev === commaTok || prev === bracketLTok;
350
+ return prev === dotTok || prev === colonTok || prev === parenLTok;
351
+ },
352
+ updateContext() {
353
+ this.state.context.push(braceContext);
354
+ }
355
+ });
356
+ var braceRTok = TokenType("}", {
357
+ expectNext(next) {
358
+ if (this.includesContext(destructorContext)) return next === commaTok || next === braceRTok || next === eofTok || next === bracketRTok;
359
+ return next === dotTok || next === eofTok || next === commaTok;
360
+ },
361
+ expectPrev(prev) {
362
+ return prev === nameTok || prev === braceRTok || prev === bracketRTok;
363
+ },
364
+ updateContext() {
365
+ this.state.context.pop();
366
+ }
367
+ });
368
+ var bracketLTok = TokenType("[", {
369
+ expectNext(next) {
370
+ if (this.includesContext(destructorContext)) return next === nameTok || next === bracketLTok || next === braceLTok || next === bracketRTok;
371
+ return next === nameTok || next === bracketDLTok || next === colonTok || next === bracketLTok || next === ignoreTok || next === bracketRTok;
372
+ },
373
+ expectPrev(prev) {
374
+ if (this.includesContext(destructorContext)) return prev === colonTok || prev === commaTok || prev === bracketLTok;
375
+ return prev === starTok || prev === bracketLTok || prev === dotTok || prev === nameTok || prev === parenLTok || prev == commaTok;
376
+ },
377
+ updateContext() {
378
+ this.state.context.push(bracketContext);
379
+ }
380
+ });
381
+ var bracketRTok = TokenType("]", {
382
+ expectNext(next) {
383
+ if (this.includesContext(destructorContext)) return next === commaTok || next === braceRTok || next === bracketRTok || next === eofTok;
384
+ return next === dotTok || next === eofTok || next === commaTok || next === parenRTok || next === bracketRTok;
385
+ },
386
+ updateContext() {
387
+ if (this.includesContext(bracketArrayContext)) return;
388
+ if (!this.includesContext(bracketContext)) throw this.unExpect();
389
+ this.state.context.pop();
390
+ }
391
+ });
392
+ var bracketDLTok = TokenType("[[", { updateContext() {
393
+ this.state.context.push(bracketDContext);
394
+ } });
395
+ var bracketDRTok = TokenType("]]", { updateContext() {
396
+ if (this.curContext() !== bracketDContext) throw this.unExpect();
397
+ this.state.context.pop();
398
+ } });
399
+ var parenLTok = TokenType("(", {
400
+ expectNext(next) {
401
+ return next === nameTok || next === bracketDLTok || next === braceLTok || next === bangTok || next === bracketLTok;
402
+ },
403
+ expectPrev(prev) {
404
+ return prev === starTok;
405
+ },
406
+ updateContext() {
407
+ this.state.context.push(parenContext);
408
+ }
409
+ });
410
+ var parenRTok = TokenType(")", {
411
+ expectNext(next) {
412
+ return next === dotTok || next === eofTok || next === commaTok || next === parenRTok;
413
+ },
414
+ updateContext() {
415
+ if (this.curContext() !== parenContext) throw this.unExpect();
416
+ this.state.context.pop();
417
+ }
418
+ });
419
+ var commaTok = TokenType(",", { expectNext(next) {
420
+ return next === nameTok || next === bracketDLTok || next === bracketLTok || next === braceLTok;
421
+ } });
422
+ var ignoreTok = TokenType("ignore", {
423
+ expectNext(next) {
424
+ return next === bracketDRTok;
425
+ },
426
+ expectPrev(prev) {
427
+ return prev == bracketDLTok;
428
+ }
429
+ });
430
+ var expandTok = TokenType("expandTok", { expectNext(next) {
431
+ return next === dotTok || next === eofTok || next === commaTok || next === parenRTok;
432
+ } });
433
+ var eofTok = TokenType("eof");
434
+ // src/tokenizer.ts
435
+ var nonASCIIWhitespace = /[\u1680\u180e\u2000-\u200a\u202f\u205f\u3000\ufeff]/;
436
+ function fullCharCodeAtPos(input, pos) {
437
+ return input.codePointAt(pos);
438
+ }
439
+ function isRewordCode(code) {
440
+ return code === 42 || code === 46 || code === 33 || code === 91 || code === 93 || code === 40 || code === 41 || code === 44 || code === 58 || code === 126 || code === 123 || code === 125;
441
+ }
442
+ function getError(message, props) {
443
+ const err = new Error(message);
444
+ Object.assign(err, props);
445
+ return err;
446
+ }
447
+ function slice(string, start, end) {
448
+ let str = "";
449
+ for (let i = start; i < end; i++) {
450
+ const ch = string.charAt(i);
451
+ if (ch !== "\\") str += ch;
452
+ }
453
+ return str;
454
+ }
455
+ var Tokenizer = class {
456
+ input;
457
+ state;
458
+ type_;
459
+ constructor(input) {
460
+ this.input = input;
461
+ this.state = {
462
+ context: [],
463
+ pos: 0
464
+ };
465
+ }
466
+ curContext() {
467
+ return this.state.context[this.state.context.length - 1];
468
+ }
469
+ includesContext(context) {
470
+ for (let len = this.state.context.length - 1; len >= 0; len--) if (this.state.context[len] === context) return true;
471
+ return false;
472
+ }
473
+ unExpect(type) {
474
+ type = type || this.state.type;
475
+ return getError(`UnExpect token "${type.flag}" in ${this.state.pos} char.`, { pos: this.state.pos });
476
+ }
477
+ expectNext(type, next) {
478
+ if (type && type.expectNext) {
479
+ if (next && !type.expectNext.call(this, next)) throw getError(`UnExpect token "${next.flag}" token should not be behind "${type.flag}" token.(${this.state.pos}th char)`, { pos: this.state.pos });
480
+ }
481
+ }
482
+ expectPrev(type, prev) {
483
+ if (type && type.expectPrev) {
484
+ if (prev && !type.expectPrev.call(this, prev)) throw getError(`Unexpect token "${type.flag}" should not be behind "${prev.flag}"(${this.state.pos}th char).`, { pos: this.state.pos });
485
+ }
486
+ }
487
+ match(type) {
488
+ return this.state.type === type;
489
+ }
490
+ skipSpace() {
491
+ if (this.curContext() === bracketDContext) return;
492
+ loop: while (this.state.pos < this.input.length) {
493
+ const ch = this.input.charCodeAt(this.state.pos);
494
+ switch (ch) {
495
+ case 32:
496
+ case 160:
497
+ ++this.state.pos;
498
+ break;
499
+ case 13: if (this.input.charCodeAt(this.state.pos + 1) === 10) ++this.state.pos;
500
+ case 10:
501
+ case 8232:
502
+ case 8233:
503
+ ++this.state.pos;
504
+ break;
505
+ default: if (ch > 8 && ch < 14 || ch >= 5760 && nonASCIIWhitespace.test(String.fromCharCode(ch))) ++this.state.pos;
506
+ else break loop;
507
+ }
508
+ }
509
+ }
510
+ next() {
511
+ this.type_ = this.state.type;
512
+ if (this.input.length <= this.state.pos) return this.finishToken(eofTok);
513
+ this.skipSpace();
514
+ this.readToken(this.getCode(), this.state.pos > 0 ? this.getCode(this.state.pos - 1) : -Infinity);
515
+ }
516
+ getCode(pos = this.state.pos) {
517
+ return fullCharCodeAtPos(this.input, pos);
518
+ }
519
+ eat(type) {
520
+ if (this.match(type)) {
521
+ this.next();
522
+ return true;
523
+ } else return false;
524
+ }
525
+ readKeyWord() {
526
+ const startPos = this.state.pos;
527
+ let string = "";
528
+ while (true) {
529
+ const code = this.getCode();
530
+ const prevCode = this.getCode(this.state.pos - 1);
531
+ if (this.input.length === this.state.pos) {
532
+ string = slice(this.input, startPos, this.state.pos + 1);
533
+ break;
534
+ }
535
+ if (!isRewordCode(code) || prevCode === 92) {
536
+ if (code === 32 || code === 160 || code === 10 || code === 8232 || code === 8233) {
537
+ string = slice(this.input, startPos, this.state.pos);
538
+ break;
539
+ }
540
+ if (code === 13 && this.input.charCodeAt(this.state.pos + 1) === 10) {
541
+ string = slice(this.input, startPos, this.state.pos);
542
+ break;
543
+ }
544
+ if (code > 8 && code < 14 || code >= 5760 && nonASCIIWhitespace.test(String.fromCharCode(code))) {
545
+ string = slice(this.input, startPos, this.state.pos);
546
+ break;
547
+ }
548
+ this.state.pos++;
549
+ } else {
550
+ string = slice(this.input, startPos, this.state.pos);
551
+ break;
552
+ }
553
+ }
554
+ this.finishToken(nameTok, string);
555
+ }
556
+ readIgnoreString() {
557
+ const startPos = this.state.pos;
558
+ let prevCode;
559
+ let string = "";
560
+ while (true) {
561
+ const code = this.getCode();
562
+ if (this.state.pos >= this.input.length) break;
563
+ if ((code === 91 || code === 93) && prevCode === 92) {
564
+ this.state.pos++;
565
+ prevCode = void 0;
566
+ } else if (code == 93 && prevCode === 93) {
567
+ string = this.input.slice(startPos, this.state.pos - 1).replace(/\\([\\[\]])/g, "$1");
568
+ this.state.pos++;
569
+ break;
570
+ } else {
571
+ this.state.pos++;
572
+ prevCode = code;
573
+ }
574
+ }
575
+ this.finishToken(ignoreTok, string);
576
+ this.finishToken(bracketDRTok);
577
+ }
578
+ finishToken(type, value) {
579
+ const preType = this.state.type;
580
+ this.state.type = type;
581
+ if (value !== void 0) this.state.value = value;
582
+ this.expectNext(preType, type);
583
+ this.expectPrev(type, preType);
584
+ if (type.updateContext) type.updateContext.call(this, preType);
585
+ }
586
+ readToken(code, prevCode) {
587
+ if (prevCode === 92) return this.readKeyWord();
588
+ if (this.input.length <= this.state.pos) this.finishToken(eofTok);
589
+ else if (this.curContext() === bracketDContext) this.readIgnoreString();
590
+ else if (code === 123) {
591
+ this.state.pos++;
592
+ this.finishToken(braceLTok);
593
+ } else if (code === 125) {
594
+ this.state.pos++;
595
+ this.finishToken(braceRTok);
596
+ } else if (code === 42) {
597
+ this.state.pos++;
598
+ if (this.getCode() === 42) {
599
+ this.state.pos++;
600
+ return this.finishToken(dbStarTok);
601
+ }
602
+ this.finishToken(starTok);
603
+ } else if (code === 33) {
604
+ this.state.pos++;
605
+ this.finishToken(bangTok);
606
+ } else if (code === 46) {
607
+ this.state.pos++;
608
+ this.finishToken(dotTok);
609
+ } else if (code === 91) {
610
+ this.state.pos++;
611
+ if (this.getCode() === 91) {
612
+ this.state.pos++;
613
+ return this.finishToken(bracketDLTok);
614
+ }
615
+ this.finishToken(bracketLTok);
616
+ } else if (code === 126) {
617
+ this.state.pos++;
618
+ this.finishToken(expandTok);
619
+ } else if (code === 93) {
620
+ this.state.pos++;
621
+ this.finishToken(bracketRTok);
622
+ } else if (code === 40) {
623
+ this.state.pos++;
624
+ this.finishToken(parenLTok);
625
+ } else if (code === 41) {
626
+ this.state.pos++;
627
+ this.finishToken(parenRTok);
628
+ } else if (code === 44) {
629
+ this.state.pos++;
630
+ this.finishToken(commaTok);
631
+ } else if (code === 58) {
632
+ this.state.pos++;
633
+ this.finishToken(colonTok);
634
+ } else this.readKeyWord();
635
+ }
636
+ };
637
+ // src/parser.ts
638
+ function createTreeBySegments(segments = [], afterNode) {
639
+ const segLen = segments.length;
640
+ function build(start = 0) {
641
+ const after = start < segLen - 1 ? build(start + 1) : afterNode;
642
+ const dot = after && {
643
+ type: "DotOperator",
644
+ after
645
+ };
646
+ return {
647
+ type: "Identifier",
648
+ value: segments[start],
649
+ after: dot
650
+ };
651
+ }
652
+ return build();
653
+ }
654
+ function calculate(a, b, operator) {
655
+ if (isNumberLike(a) && isNumberLike(b)) {
656
+ if (operator === "+") return String(Number(a) + Number(b));
657
+ if (operator === "-") return String(Number(a) - Number(b));
658
+ if (operator === "*") return String(Number(a) * Number(b));
659
+ if (operator === "/") return String(Number(a) / Number(b));
660
+ } else {
661
+ if (operator === "+") return String(a) + String(b);
662
+ if (operator === "-") return "NaN";
663
+ if (operator === "*") return "NaN";
664
+ if (operator === "/") return "NaN";
665
+ }
666
+ return String(Number(b));
667
+ }
668
+ var Parser = class extends Tokenizer {
669
+ isMatchPattern = false;
670
+ isWildMatchPattern = false;
671
+ haveExcludePattern = false;
672
+ haveRelativePattern = false;
673
+ base;
674
+ relative;
675
+ data;
676
+ constructor(input, base) {
677
+ super(input);
678
+ this.base = base;
679
+ }
680
+ parse() {
681
+ let node;
682
+ this.data = { segments: [] };
683
+ if (!this.eat(eofTok)) {
684
+ this.next();
685
+ node = this.parseAtom(this.state.type);
686
+ }
687
+ this.data.tree = node;
688
+ return node;
689
+ }
690
+ append(parent, node) {
691
+ if (parent && node) parent.after = node;
692
+ }
693
+ parseAtom(type) {
694
+ switch (type) {
695
+ case braceLTok:
696
+ case bracketLTok:
697
+ if (this.includesContext(destructorContext)) {
698
+ if (type === braceLTok) return this.parseObjectPattern();
699
+ else return this.parseArrayPattern();
700
+ }
701
+ return this.parseDestructorExpression();
702
+ case nameTok: return this.parseIdentifier();
703
+ case expandTok: return this.parseExpandOperator();
704
+ case dbStarTok:
705
+ case starTok: return this.parseWildcardOperator();
706
+ case bracketDLTok: return this.parseIgnoreExpression();
707
+ case dotTok: return this.parseDotOperator();
708
+ }
709
+ }
710
+ pushSegments(key) {
711
+ this.data.segments.push(key);
712
+ }
713
+ parseIdentifier() {
714
+ const node = {
715
+ type: "Identifier",
716
+ value: this.state.value
717
+ };
718
+ const hasNotInDestructor = !this.includesContext(destructorContext) && !this.isMatchPattern && !this.isWildMatchPattern;
719
+ this.next();
720
+ if (this.includesContext(bracketArrayContext)) {
721
+ if (this.state.type !== bracketRTok) throw this.unExpect();
722
+ else {
723
+ this.state.context.pop();
724
+ this.next();
725
+ }
726
+ } else if (hasNotInDestructor) this.pushSegments(node.value);
727
+ if (this.state.type === bracketLTok) {
728
+ this.next();
729
+ if (this.state.type !== nameTok) throw this.unExpect();
730
+ this.state.context.push(bracketArrayContext);
731
+ let isNumberKey = false;
732
+ if (/^\d+$/.test(this.state.value)) isNumberKey = true;
733
+ const value = this.state.value;
734
+ this.pushSegments(isNumberKey ? Number(value) : value);
735
+ const after = this.parseAtom(this.state.type);
736
+ if (isNumberKey) after.arrayIndex = true;
737
+ this.append(node, after);
738
+ } else this.append(node, this.parseAtom(this.state.type));
739
+ return node;
740
+ }
741
+ parseExpandOperator() {
742
+ const node = { type: "ExpandOperator" };
743
+ this.isMatchPattern = true;
744
+ this.isWildMatchPattern = true;
745
+ this.data.segments = [];
746
+ this.next();
747
+ this.append(node, this.parseAtom(this.state.type));
748
+ return node;
749
+ }
750
+ parseWildcardOperator() {
751
+ const node = { type: "WildcardOperator" };
752
+ if (this.state.type === dbStarTok) node.optional = true;
753
+ this.isMatchPattern = true;
754
+ this.isWildMatchPattern = true;
755
+ this.data.segments = [];
756
+ this.next();
757
+ if (this.state.type === parenLTok) node.filter = this.parseGroupExpression(node);
758
+ else if (this.state.type === bracketLTok) node.filter = this.parseRangeExpression(node);
759
+ this.append(node, this.parseAtom(this.state.type));
760
+ return node;
761
+ }
762
+ parseDestructorExpression() {
763
+ const node = { type: "DestructorExpression" };
764
+ this.state.context.push(destructorContext);
765
+ const startPos = this.state.pos - 1;
766
+ node.value = this.state.type === braceLTok ? this.parseObjectPattern() : this.parseArrayPattern();
767
+ const endPos = this.state.pos;
768
+ this.state.context.pop();
769
+ node.source = this.input.substring(startPos, endPos).replace(/\[\s*([\\+\-\\*\\/])?\s*([^,\]\s]*)\s*\]/, (match, operator, target) => {
770
+ if (this.relative !== void 0) {
771
+ if (operator) {
772
+ if (target) return calculate(this.relative, target, operator);
773
+ else return calculate(this.relative, 1, operator);
774
+ } else if (target) return calculate(this.relative, target, "+");
775
+ else return String(this.relative);
776
+ }
777
+ return match;
778
+ }).replace(/\s*\.\s*/g, "").replace(/\s*/g, "");
779
+ if (this.relative === void 0) setDestructor(node.source, parseDestructorRules(node));
780
+ this.relative = void 0;
781
+ this.pushSegments(node.source);
782
+ this.next();
783
+ this.append(node, this.parseAtom(this.state.type));
784
+ return node;
785
+ }
786
+ parseArrayPattern() {
787
+ const node = {
788
+ type: "ArrayPattern",
789
+ elements: []
790
+ };
791
+ this.next();
792
+ node.elements = this.parseArrayPatternElements();
793
+ return node;
794
+ }
795
+ parseArrayPatternElements() {
796
+ const nodes = [];
797
+ while (this.state.type !== bracketRTok && this.state.type !== eofTok) {
798
+ nodes.push(this.parseAtom(this.state.type));
799
+ if (this.state.type === bracketRTok) {
800
+ if (this.includesContext(destructorContext)) this.next();
801
+ return nodes;
802
+ }
803
+ this.next();
804
+ }
805
+ return nodes;
806
+ }
807
+ parseObjectPattern() {
808
+ const node = {
809
+ type: "ObjectPattern",
810
+ properties: []
811
+ };
812
+ this.next();
813
+ node.properties = this.parseObjectProperties();
814
+ return node;
815
+ }
816
+ parseObjectProperties() {
817
+ const nodes = [];
818
+ while (this.state.type !== braceRTok && this.state.type !== eofTok) {
819
+ const node = {
820
+ type: "ObjectPatternProperty",
821
+ key: this.parseAtom(this.state.type)
822
+ };
823
+ nodes.push(node);
824
+ if (this.state.type === colonTok) {
825
+ this.next();
826
+ node.value = this.parseAtom(this.state.type);
827
+ }
828
+ if (this.state.type === braceRTok) {
829
+ if (this.includesContext(destructorContext)) this.next();
830
+ return nodes;
831
+ }
832
+ this.next();
833
+ }
834
+ return nodes;
835
+ }
836
+ parseDotOperator() {
837
+ const node = { type: "DotOperator" };
838
+ if (!this.type_ && this.base) {
839
+ if (this.base.isMatchPattern) throw new Error("Base path must be an absolute path.");
840
+ this.data.segments = this.base.toArr();
841
+ while (this.state.type === dotTok) {
842
+ this.relative = this.data.segments.pop();
843
+ this.haveRelativePattern = true;
844
+ this.next();
845
+ }
846
+ return createTreeBySegments(this.data.segments.slice(), this.parseAtom(this.state.type));
847
+ } else this.next();
848
+ this.append(node, this.parseAtom(this.state.type));
849
+ return node;
850
+ }
851
+ parseIgnoreExpression() {
852
+ this.next();
853
+ const value = String(this.state.value).replace(/\s*/g, "");
854
+ const node = {
855
+ type: "IgnoreExpression",
856
+ value
857
+ };
858
+ this.pushSegments(value);
859
+ this.next();
860
+ this.append(node, this.parseAtom(this.state.type));
861
+ this.next();
862
+ return node;
863
+ }
864
+ parseGroupExpression(parent) {
865
+ const node = {
866
+ type: "GroupExpression",
867
+ value: []
868
+ };
869
+ this.isMatchPattern = true;
870
+ this.data.segments = [];
871
+ this.next();
872
+ loop: while (true) switch (this.state.type) {
873
+ case commaTok:
874
+ this.next();
875
+ break;
876
+ case bangTok:
877
+ node.isExclude = true;
878
+ this.haveExcludePattern = true;
879
+ this.next();
880
+ break;
881
+ case eofTok: break loop;
882
+ case parenRTok: break loop;
883
+ default: node.value.push(this.parseAtom(this.state.type));
884
+ }
885
+ this.next();
886
+ this.append(parent, this.parseAtom(this.state.type));
887
+ return node;
888
+ }
889
+ parseRangeExpression(parent) {
890
+ const node = { type: "RangeExpression" };
891
+ this.next();
892
+ this.isMatchPattern = true;
893
+ this.data.segments = [];
894
+ let start = false, hasColon = false;
895
+ loop: while (true) switch (this.state.type) {
896
+ case colonTok:
897
+ hasColon = true;
898
+ start = true;
899
+ this.next();
900
+ break;
901
+ case bracketRTok:
902
+ if (!hasColon && !node.end) node.end = node.start;
903
+ break loop;
904
+ case commaTok: throw this.unExpect();
905
+ case eofTok: break loop;
906
+ default: if (!start) node.start = this.parseAtom(this.state.type);
907
+ else node.end = this.parseAtom(this.state.type);
908
+ }
909
+ this.next();
910
+ this.append(parent, this.parseAtom(this.state.type));
911
+ return node;
912
+ }
913
+ };
914
+ // src/index.ts
915
+ var pathCache = /* @__PURE__ */ new Map();
916
+ var isMatcher = Symbol("PATH_MATCHER");
917
+ function isMatcherFunction(val) {
918
+ return isFn(val) && val[isMatcher] === true;
919
+ }
920
+ function isValid(val) {
921
+ return val !== void 0 && val !== null;
922
+ }
923
+ function isSimplePath(val) {
924
+ return val.indexOf("*") === -1 && val.indexOf("~") === -1 && val.indexOf("[") === -1 && val.indexOf("]") === -1 && val.indexOf(",") === -1 && val.indexOf(":") === -1 && val.indexOf(" ") === -1 && val[0] !== ".";
925
+ }
926
+ function isAssignable(val) {
927
+ return typeof val === "object" || typeof val === "function";
928
+ }
929
+ function isNumberIndex(val) {
930
+ return isStr(val) ? /^\d+$/.test(val) : isNum(val);
931
+ }
932
+ function getIn(segments, source) {
933
+ for (let i = 0; i < segments.length; i++) {
934
+ const index = segments[i];
935
+ const rules = getDestructor(index);
936
+ if (!rules) {
937
+ if (!isValid(source)) return;
938
+ source = source[index];
939
+ } else {
940
+ source = getInByDestructor(source, rules, {
941
+ setIn,
942
+ getIn
943
+ });
944
+ break;
945
+ }
946
+ }
947
+ return source;
948
+ }
949
+ function setIn(segments, source, value) {
950
+ for (let i = 0; i < segments.length; i++) {
951
+ const index = segments[i];
952
+ const rules = getDestructor(index);
953
+ if (!rules) {
954
+ if (!isValid(source) || !isAssignable(source)) return;
955
+ if (isArr(source) && !isNumberIndex(index)) return;
956
+ if (!isValid(source[index])) {
957
+ if (value === void 0) {
958
+ if (source[index] === null) source[index] = value;
959
+ return;
960
+ }
961
+ if (i < segments.length - 1) source[index] = isNum(segments[i + 1]) ? [] : {};
962
+ }
963
+ if (i === segments.length - 1) source[index] = value;
964
+ source = source[index];
965
+ } else {
966
+ setInByDestructor(source, rules, value, {
967
+ setIn,
968
+ getIn
969
+ });
970
+ break;
971
+ }
972
+ }
973
+ }
974
+ function deleteIn(segments, source) {
975
+ for (let i = 0; i < segments.length; i++) {
976
+ const index = segments[i];
977
+ const rules = getDestructor(index);
978
+ if (!rules) {
979
+ if (i === segments.length - 1 && isValid(source)) {
980
+ delete source[index];
981
+ return;
982
+ }
983
+ if (!isValid(source) || !isAssignable(source)) return;
984
+ source = source[index];
985
+ if (!isObj(source)) return;
986
+ } else {
987
+ deleteInByDestructor(source, rules, {
988
+ setIn,
989
+ getIn,
990
+ deleteIn
991
+ });
992
+ break;
993
+ }
994
+ }
995
+ }
996
+ var hasOwnProperty = Object.prototype.hasOwnProperty;
997
+ function existIn(segments, source, start) {
998
+ if (start instanceof Path) start = start.length;
999
+ for (let i = start; i < segments.length; i++) {
1000
+ const index = segments[i];
1001
+ const rules = getDestructor(index);
1002
+ if (!rules) {
1003
+ if (i === segments.length - 1) return hasOwnProperty.call(source, index);
1004
+ if (!isValid(source) || !isAssignable(source)) return false;
1005
+ source = source[index];
1006
+ if (!isObj(source)) return false;
1007
+ } else return existInByDestructor(source, rules, start, {
1008
+ setIn,
1009
+ getIn,
1010
+ deleteIn,
1011
+ existIn
1012
+ });
1013
+ }
1014
+ }
1015
+ function parse(pattern, base) {
1016
+ if (pattern instanceof Path) return {
1017
+ entire: pattern.entire,
1018
+ segments: pattern.segments.slice(),
1019
+ isRegExp: false,
1020
+ haveRelativePattern: pattern.haveRelativePattern,
1021
+ isWildMatchPattern: pattern.isWildMatchPattern,
1022
+ isMatchPattern: pattern.isMatchPattern,
1023
+ haveExcludePattern: pattern.haveExcludePattern,
1024
+ tree: pattern.tree
1025
+ };
1026
+ else if (isStr(pattern)) {
1027
+ if (!pattern) return {
1028
+ entire: "",
1029
+ segments: [],
1030
+ isRegExp: false,
1031
+ isWildMatchPattern: false,
1032
+ haveRelativePattern: false,
1033
+ haveExcludePattern: false,
1034
+ isMatchPattern: false
1035
+ };
1036
+ if (isSimplePath(pattern)) return {
1037
+ entire: pattern,
1038
+ segments: pattern.split("."),
1039
+ isRegExp: false,
1040
+ haveRelativePattern: false,
1041
+ isWildMatchPattern: false,
1042
+ haveExcludePattern: false,
1043
+ isMatchPattern: false
1044
+ };
1045
+ const parser = new Parser(pattern, Path.parse(base));
1046
+ const tree = parser.parse();
1047
+ if (!parser.isMatchPattern) {
1048
+ const segments = parser.data.segments;
1049
+ return {
1050
+ entire: segments.join("."),
1051
+ segments,
1052
+ tree,
1053
+ isRegExp: false,
1054
+ haveRelativePattern: parser.haveRelativePattern,
1055
+ isWildMatchPattern: false,
1056
+ haveExcludePattern: false,
1057
+ isMatchPattern: false
1058
+ };
1059
+ } else return {
1060
+ entire: pattern,
1061
+ segments: [],
1062
+ isRegExp: false,
1063
+ haveRelativePattern: false,
1064
+ isWildMatchPattern: parser.isWildMatchPattern,
1065
+ haveExcludePattern: parser.haveExcludePattern,
1066
+ isMatchPattern: true,
1067
+ tree
1068
+ };
1069
+ } else if (isMatcherFunction(pattern)) return parse(pattern.path);
1070
+ else if (isArr(pattern)) return {
1071
+ entire: pattern.join("."),
1072
+ segments: pattern.reduce((buf, key) => {
1073
+ return buf.concat(parseString(key));
1074
+ }, []),
1075
+ isRegExp: false,
1076
+ haveRelativePattern: false,
1077
+ isWildMatchPattern: false,
1078
+ haveExcludePattern: false,
1079
+ isMatchPattern: false
1080
+ };
1081
+ else if (isRegExp(pattern)) return {
1082
+ entire: pattern,
1083
+ segments: [],
1084
+ isRegExp: true,
1085
+ haveRelativePattern: false,
1086
+ isWildMatchPattern: false,
1087
+ haveExcludePattern: false,
1088
+ isMatchPattern: true
1089
+ };
1090
+ else return {
1091
+ entire: "",
1092
+ isRegExp: false,
1093
+ segments: pattern !== void 0 ? [pattern] : [],
1094
+ haveRelativePattern: false,
1095
+ isWildMatchPattern: false,
1096
+ haveExcludePattern: false,
1097
+ isMatchPattern: false
1098
+ };
1099
+ }
1100
+ function parseString(source) {
1101
+ if (isStr(source)) {
1102
+ source = source.replace(/\s*/g, "");
1103
+ try {
1104
+ const { segments, isMatchPattern } = parse(source);
1105
+ return !isMatchPattern ? segments : source;
1106
+ } catch (e) {
1107
+ return source;
1108
+ }
1109
+ } else if (source instanceof Path) return source.segments;
1110
+ return source;
1111
+ }
1112
+ var Path = class Path {
1113
+ entire;
1114
+ segments;
1115
+ isMatchPattern;
1116
+ isWildMatchPattern;
1117
+ isRegExp;
1118
+ haveRelativePattern;
1119
+ haveExcludePattern;
1120
+ matchScore = 0;
1121
+ tree;
1122
+ matchCache;
1123
+ includesCache;
1124
+ constructor(input, base) {
1125
+ const { tree, segments, entire, isRegExp, isMatchPattern, isWildMatchPattern, haveRelativePattern, haveExcludePattern } = parse(input, base);
1126
+ this.entire = entire;
1127
+ this.segments = segments;
1128
+ this.isMatchPattern = isMatchPattern;
1129
+ this.isWildMatchPattern = isWildMatchPattern;
1130
+ this.haveRelativePattern = haveRelativePattern;
1131
+ this.isRegExp = isRegExp;
1132
+ this.haveExcludePattern = haveExcludePattern;
1133
+ this.tree = tree;
1134
+ this.matchCache = /* @__PURE__ */ new Map();
1135
+ this.includesCache = /* @__PURE__ */ new Map();
1136
+ }
1137
+ toString() {
1138
+ return this.entire?.toString();
1139
+ }
1140
+ toArr() {
1141
+ return this.segments?.slice();
1142
+ }
1143
+ get length() {
1144
+ return this.segments.length;
1145
+ }
1146
+ concat = (...args) => {
1147
+ if (this.isMatchPattern || this.isRegExp) throw new Error(`${this.entire} cannot be concat`);
1148
+ const path = new Path("");
1149
+ path.segments = this.segments.concat(...args.map((s) => parseString(s)));
1150
+ path.entire = path.segments.join(".");
1151
+ return path;
1152
+ };
1153
+ slice = (start, end) => {
1154
+ if (this.isMatchPattern || this.isRegExp) throw new Error(`${this.entire} cannot be slice`);
1155
+ const path = new Path("");
1156
+ path.segments = this.segments.slice(start, end);
1157
+ path.entire = path.segments.join(".");
1158
+ return path;
1159
+ };
1160
+ push = (...items) => {
1161
+ return this.concat(...items);
1162
+ };
1163
+ pop = () => {
1164
+ if (this.isMatchPattern || this.isRegExp) throw new Error(`${this.entire} cannot be pop`);
1165
+ return new Path(this.segments.slice(0, this.segments.length - 1));
1166
+ };
1167
+ splice = (start, deleteCount, ...items) => {
1168
+ if (this.isMatchPattern || this.isRegExp) throw new Error(`${this.entire} cannot be splice`);
1169
+ items = items.reduce((buf, item) => buf.concat(parseString(item)), []);
1170
+ const segments_ = this.segments.slice();
1171
+ segments_.splice(start, deleteCount, ...items);
1172
+ return new Path(segments_);
1173
+ };
1174
+ forEach = (callback) => {
1175
+ if (this.isMatchPattern || this.isRegExp) throw new Error(`${this.entire} cannot be each`);
1176
+ this.segments.forEach(callback);
1177
+ };
1178
+ map = (callback) => {
1179
+ if (this.isMatchPattern || this.isRegExp) throw new Error(`${this.entire} cannot be map`);
1180
+ return this.segments.map(callback);
1181
+ };
1182
+ reduce = (callback, initial) => {
1183
+ if (this.isMatchPattern || this.isRegExp) throw new Error(`${this.entire} cannot be reduce`);
1184
+ return this.segments.reduce(callback, initial);
1185
+ };
1186
+ parent = () => {
1187
+ return this.slice(0, this.length - 1);
1188
+ };
1189
+ includes = (pattern) => {
1190
+ const { entire, segments, isMatchPattern } = Path.parse(pattern);
1191
+ const cache = this.includesCache.get(entire);
1192
+ if (cache !== void 0) return cache;
1193
+ const cacheWith = (value) => {
1194
+ this.includesCache.set(entire, value);
1195
+ return value;
1196
+ };
1197
+ if (this.isMatchPattern) {
1198
+ if (!isMatchPattern) return cacheWith(this.match(segments));
1199
+ else throw new Error(`${this.entire} cannot be used to match ${entire}`);
1200
+ }
1201
+ if (isMatchPattern) throw new Error(`${this.entire} cannot be used to match ${entire}`);
1202
+ if (segments.length > this.segments.length) return cacheWith(false);
1203
+ for (let i = 0; i < segments.length; i++) if (!isEqual(String(segments[i]), String(this.segments[i]))) return cacheWith(false);
1204
+ return cacheWith(true);
1205
+ };
1206
+ transform = (regexp, callback) => {
1207
+ if (!isFn(callback)) return "";
1208
+ if (this.isMatchPattern) throw new Error(`${this.entire} cannot be transformed`);
1209
+ const reg = new RegExp(regexp);
1210
+ return callback(...this.segments.filter((key) => reg.test(key)));
1211
+ };
1212
+ match = (pattern) => {
1213
+ const path = Path.parse(pattern);
1214
+ const cache = this.matchCache.get(path.entire);
1215
+ if (cache !== void 0) {
1216
+ if (cache.record && cache.record.score !== void 0) this.matchScore = cache.record.score;
1217
+ return cache.matched;
1218
+ }
1219
+ const cacheWith = (value) => {
1220
+ this.matchCache.set(path.entire, value);
1221
+ return value;
1222
+ };
1223
+ if (path.isMatchPattern) {
1224
+ if (this.isMatchPattern) throw new Error(`${path.entire} cannot match ${this.entire}`);
1225
+ else {
1226
+ this.matchScore = 0;
1227
+ return cacheWith(path.match(this.segments));
1228
+ }
1229
+ } else if (this.isMatchPattern) {
1230
+ if (this.isRegExp) try {
1231
+ return this.entire.test(String(path.entire));
1232
+ } finally {
1233
+ this.entire.lastIndex = 0;
1234
+ }
1235
+ const record = { score: 0 };
1236
+ const result = cacheWith(new Matcher(this.tree, record).match(path.segments));
1237
+ this.matchScore = record.score;
1238
+ return result.matched;
1239
+ } else {
1240
+ const record = { score: 0 };
1241
+ const result = cacheWith(Matcher.matchSegments(this.segments, path.segments, record));
1242
+ this.matchScore = record.score;
1243
+ return result.matched;
1244
+ }
1245
+ };
1246
+ matchAliasGroup = (name, alias) => {
1247
+ const namePath = Path.parse(name);
1248
+ const aliasPath = Path.parse(alias);
1249
+ const nameMatched = this.match(namePath);
1250
+ const nameMatchedScore = this.matchScore;
1251
+ const aliasMatched = this.match(aliasPath);
1252
+ const aliasMatchedScore = this.matchScore;
1253
+ if (this.haveExcludePattern) {
1254
+ if (nameMatchedScore >= aliasMatchedScore) return nameMatched;
1255
+ else return aliasMatched;
1256
+ } else return nameMatched || aliasMatched;
1257
+ };
1258
+ existIn = (source, start = 0) => {
1259
+ return existIn(this.segments, source, start);
1260
+ };
1261
+ getIn = (source) => {
1262
+ return getIn(this.segments, source);
1263
+ };
1264
+ setIn = (source, value) => {
1265
+ setIn(this.segments, source, value);
1266
+ return source;
1267
+ };
1268
+ deleteIn = (source) => {
1269
+ deleteIn(this.segments, source);
1270
+ return source;
1271
+ };
1272
+ ensureIn = (source, defaults) => {
1273
+ const results = this.getIn(source);
1274
+ if (results === void 0) {
1275
+ this.setIn(source, defaults);
1276
+ return this.getIn(source);
1277
+ }
1278
+ return results;
1279
+ };
1280
+ static match(pattern) {
1281
+ const path = Path.parse(pattern);
1282
+ const matcher = ((target) => {
1283
+ return path.match(target);
1284
+ });
1285
+ matcher[isMatcher] = true;
1286
+ matcher.path = path;
1287
+ return matcher;
1288
+ }
1289
+ static isPathPattern(target) {
1290
+ return !!(isStr(target) || isArr(target) || isRegExp(target) || isMatcherFunction(target));
1291
+ }
1292
+ static transform(pattern, regexp, callback) {
1293
+ return Path.parse(pattern).transform(regexp, callback);
1294
+ }
1295
+ static parse(path = "", base) {
1296
+ if (path instanceof Path) {
1297
+ const found = pathCache.get(path.entire);
1298
+ if (found) return found;
1299
+ else {
1300
+ pathCache.set(path.entire, path);
1301
+ return path;
1302
+ }
1303
+ } else if (isMatcherFunction(path)) return Path.parse(path.path);
1304
+ else {
1305
+ const key_ = base ? Path.parse(base) : "";
1306
+ const key = `${path}:${key_}`;
1307
+ const found = pathCache.get(key);
1308
+ if (found) return found;
1309
+ else {
1310
+ path = new Path(path, base);
1311
+ pathCache.set(key, path);
1312
+ return path;
1313
+ }
1314
+ }
1315
+ }
1316
+ static getIn = (source, pattern) => {
1317
+ return Path.parse(pattern).getIn(source);
1318
+ };
1319
+ static setIn = (source, pattern, value) => {
1320
+ return Path.parse(pattern).setIn(source, value);
1321
+ };
1322
+ static deleteIn = (source, pattern) => {
1323
+ return Path.parse(pattern).deleteIn(source);
1324
+ };
1325
+ static existIn = (source, pattern, start) => {
1326
+ return Path.parse(pattern).existIn(source, start);
1327
+ };
1328
+ static ensureIn = (source, pattern, defaultValue) => {
1329
+ return Path.parse(pattern).ensureIn(source, defaultValue);
1330
+ };
1331
+ };
1332
+ export { Path };
1333
+
1334
+ //# sourceMappingURL=index.js.map