@rimbu/deep 2.0.0 → 2.0.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.
Files changed (56) hide show
  1. package/README.md +37 -27
  2. package/dist/bun/deep.mts +2 -2
  3. package/dist/bun/match.mts +27 -25
  4. package/dist/bun/patch.mts +10 -9
  5. package/dist/bun/path.mts +94 -95
  6. package/dist/bun/protected.mts +18 -17
  7. package/dist/bun/selector.mts +22 -20
  8. package/dist/bun/tuple.mts +1 -1
  9. package/dist/cjs/deep.cjs +197 -576
  10. package/dist/cjs/deep.cjs.map +1 -0
  11. package/dist/cjs/deep.d.cts +284 -0
  12. package/dist/cjs/index.cjs +18 -662
  13. package/dist/cjs/index.cjs.map +1 -0
  14. package/dist/cjs/index.d.cts +18 -0
  15. package/dist/cjs/internal.cjs +8 -582
  16. package/dist/cjs/internal.cjs.map +1 -0
  17. package/dist/cjs/internal.d.cts +7 -0
  18. package/dist/cjs/match.cjs +250 -343
  19. package/dist/cjs/match.cjs.map +1 -0
  20. package/dist/cjs/match.d.cts +140 -0
  21. package/dist/cjs/patch.cjs +120 -93
  22. package/dist/cjs/patch.cjs.map +1 -0
  23. package/dist/cjs/patch.d.cts +89 -0
  24. package/dist/cjs/path.cjs +114 -573
  25. package/dist/cjs/path.cjs.map +1 -0
  26. package/dist/cjs/path.d.cts +199 -0
  27. package/dist/cjs/protected.cjs +2 -17
  28. package/dist/cjs/protected.cjs.map +1 -0
  29. package/dist/cjs/selector.cjs +32 -574
  30. package/dist/cjs/selector.cjs.map +1 -0
  31. package/dist/cjs/selector.d.cts +47 -0
  32. package/dist/cjs/tuple.cjs +162 -71
  33. package/dist/cjs/tuple.cjs.map +1 -0
  34. package/dist/esm/match.mjs.map +1 -1
  35. package/dist/esm/patch.mjs.map +1 -1
  36. package/dist/{types → esm}/path.d.mts +4 -1
  37. package/dist/esm/path.mjs.map +1 -1
  38. package/dist/esm/protected.d.mts +17 -0
  39. package/dist/esm/selector.mjs.map +1 -1
  40. package/dist/esm/tuple.d.mts +142 -0
  41. package/package.json +20 -14
  42. package/src/deep.mts +2 -2
  43. package/src/match.mts +27 -25
  44. package/src/patch.mts +10 -9
  45. package/src/path.mts +94 -95
  46. package/src/protected.mts +18 -17
  47. package/src/selector.mts +22 -20
  48. package/src/tuple.mts +1 -1
  49. /package/dist/{types/protected.d.mts → cjs/protected.d.cts} +0 -0
  50. /package/dist/{types/tuple.d.mts → cjs/tuple.d.cts} +0 -0
  51. /package/dist/{types → esm}/deep.d.mts +0 -0
  52. /package/dist/{types → esm}/index.d.mts +0 -0
  53. /package/dist/{types → esm}/internal.d.mts +0 -0
  54. /package/dist/{types → esm}/match.d.mts +0 -0
  55. /package/dist/{types → esm}/patch.d.mts +0 -0
  56. /package/dist/{types → esm}/selector.d.mts +0 -0
@@ -1,376 +1,283 @@
1
1
  "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/match.mts
21
- var match_exports = {};
22
- __export(match_exports, {
23
- match: () => match
24
- });
25
- module.exports = __toCommonJS(match_exports);
26
- var import_base = require("@rimbu/base");
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.match = match;
4
+ var tslib_1 = require("tslib");
5
+ var base_1 = require("@rimbu/base");
6
+ /**
7
+ * Returns true if the given `value` object matches the given `matcher`, false otherwise.
8
+ * @typeparam T - the input value type
9
+ * @typeparam C - utility type
10
+ * @param source - the value to match (should be a plain object)
11
+ * @param matcher - a matcher object or a function taking the matcher API and returning a match object
12
+ * @param failureLog - (optional) a string array that can be passed to collect reasons why the match failed
13
+ * @example
14
+ * ```ts
15
+ * const input = { a: 1, b: { c: true, d: 'a' } }
16
+ * match(input, { a: 1 }) // => true
17
+ * match(input, { a: 2 }) // => false
18
+ * match(input, { a: (v) => v > 10 }) // => false
19
+ * match(input, { b: { c: true }}) // => true
20
+ * match(input, (['every', { a: (v) => v > 0 }, { b: { c: true } }]) // => true
21
+ * match(input, { b: { c: (v, parent, root) => v && parent.d.length > 0 && root.a > 0 } })
22
+ * // => true
23
+ * ```
24
+ */
27
25
  function match(source, matcher, failureLog) {
28
- return matchEntry(source, source, source, matcher, failureLog);
26
+ return matchEntry(source, source, source, matcher, failureLog);
29
27
  }
28
+ /**
29
+ * Match a generic match entry against the given source.
30
+ */
30
31
  function matchEntry(source, parent, root, matcher, failureLog) {
31
- if (Object.is(source, matcher)) {
32
- return true;
33
- }
34
- if (matcher === null || matcher === void 0) {
35
- failureLog?.push(
36
- `value ${JSON.stringify(source)} did not match matcher ${matcher}`
37
- );
38
- return false;
39
- }
40
- if (typeof source === "function") {
41
- const result = Object.is(source, matcher);
42
- if (!result) {
43
- failureLog?.push(
44
- `both value and matcher are functions, but they do not have the same reference`
45
- );
32
+ if (Object.is(source, matcher)) {
33
+ // value and target are exactly the same, always will be true
34
+ return true;
46
35
  }
47
- return result;
48
- }
49
- if (typeof matcher === "function") {
50
- const matcherResult = matcher(source, parent, root);
51
- if (typeof matcherResult === "boolean") {
52
- if (!matcherResult) {
53
- failureLog?.push(
54
- `function matcher returned false for value ${JSON.stringify(source)}`
55
- );
56
- }
57
- return matcherResult;
58
- }
59
- return matchEntry(source, parent, root, matcherResult, failureLog);
60
- }
61
- if ((0, import_base.isPlainObj)(source)) {
62
- return matchPlainObj(source, parent, root, matcher, failureLog);
63
- }
64
- if (Array.isArray(source)) {
65
- return matchArr(source, parent, root, matcher, failureLog);
66
- }
67
- failureLog?.push(
68
- `value ${JSON.stringify(
69
- source
70
- )} does not match given matcher ${JSON.stringify(matcher)}`
71
- );
72
- return false;
73
- }
74
- function matchArr(source, parent, root, matcher, failureLog) {
75
- if (Array.isArray(matcher)) {
76
- const length = source.length;
77
- if (length !== matcher.length) {
78
- failureLog?.push(
79
- `array lengths are not equal: value length ${source.length} !== matcher length ${matcher.length}`
80
- );
81
- return false;
82
- }
83
- let index = -1;
84
- while (++index < length) {
85
- if (!matchEntry(source[index], source, root, matcher[index], failureLog)) {
86
- failureLog?.push(
87
- `index ${index} does not match with value ${JSON.stringify(
88
- source[index]
89
- )} and matcher ${matcher[index]}`
90
- );
36
+ if (matcher === null || matcher === undefined) {
37
+ // these matchers can only be direct matches, and previously it was determined that
38
+ // they are not equal
39
+ failureLog === null || failureLog === void 0 ? void 0 : failureLog.push("value ".concat(JSON.stringify(source), " did not match matcher ").concat(matcher));
91
40
  return false;
92
- }
93
41
  }
94
- return true;
95
- }
96
- if (typeof matcher === "object" && null !== matcher) {
97
- if (`every` in matcher) {
98
- return matchCompound(
99
- source,
100
- parent,
101
- root,
102
- ["every", ...matcher.every],
103
- failureLog
104
- );
105
- }
106
- if (`some` in matcher) {
107
- return matchCompound(
108
- source,
109
- parent,
110
- root,
111
- ["some", ...matcher.some],
112
- failureLog
113
- );
114
- }
115
- if (`none` in matcher) {
116
- return matchCompound(
117
- source,
118
- parent,
119
- root,
120
- ["none", ...matcher.none],
121
- failureLog
122
- );
123
- }
124
- if (`single` in matcher) {
125
- return matchCompound(
126
- source,
127
- parent,
128
- root,
129
- ["single", ...matcher.single],
130
- failureLog
131
- );
42
+ if (typeof source === 'function') {
43
+ // function source values can only be directly matched
44
+ var result = Object.is(source, matcher);
45
+ if (!result) {
46
+ failureLog === null || failureLog === void 0 ? void 0 : failureLog.push("both value and matcher are functions, but they do not have the same reference");
47
+ }
48
+ return result;
132
49
  }
133
- if (`someItem` in matcher) {
134
- return matchTraversal(
135
- source,
136
- root,
137
- "someItem",
138
- matcher.someItem,
139
- failureLog
140
- );
50
+ if (typeof matcher === 'function') {
51
+ // resolve match function first
52
+ var matcherResult = matcher(source, parent, root);
53
+ if (typeof matcherResult === 'boolean') {
54
+ // function resulted in a direct match result
55
+ if (!matcherResult) {
56
+ failureLog === null || failureLog === void 0 ? void 0 : failureLog.push("function matcher returned false for value ".concat(JSON.stringify(source)));
57
+ }
58
+ return matcherResult;
59
+ }
60
+ // function resulted in a value that needs to be further matched
61
+ return matchEntry(source, parent, root, matcherResult, failureLog);
141
62
  }
142
- if (`everyItem` in matcher) {
143
- return matchTraversal(
144
- source,
145
- root,
146
- "everyItem",
147
- matcher.everyItem,
148
- failureLog
149
- );
63
+ if ((0, base_1.isPlainObj)(source)) {
64
+ // source ia a plain object, can be partially matched
65
+ return matchPlainObj(source, parent, root, matcher, failureLog);
150
66
  }
151
- if (`noneItem` in matcher) {
152
- return matchTraversal(
153
- source,
154
- root,
155
- "noneItem",
156
- matcher.noneItem,
157
- failureLog
158
- );
67
+ if (Array.isArray(source)) {
68
+ // source is an array
69
+ return matchArr(source, parent, root, matcher, failureLog);
159
70
  }
160
- if (`singleItem` in matcher) {
161
- return matchTraversal(
162
- source,
163
- root,
164
- "singleItem",
165
- matcher.singleItem,
166
- failureLog
167
- );
71
+ // already determined above that the source and matcher are not equal
72
+ failureLog === null || failureLog === void 0 ? void 0 : failureLog.push("value ".concat(JSON.stringify(source), " does not match given matcher ").concat(JSON.stringify(matcher)));
73
+ return false;
74
+ }
75
+ /**
76
+ * Match an array matcher against the given source.
77
+ */
78
+ function matchArr(source, parent, root, matcher, failureLog) {
79
+ if (Array.isArray(matcher)) {
80
+ // directly compare array contents
81
+ var length = source.length;
82
+ if (length !== matcher.length) {
83
+ // if lengths not equal, arrays are not equal
84
+ failureLog === null || failureLog === void 0 ? void 0 : failureLog.push("array lengths are not equal: value length ".concat(source.length, " !== matcher length ").concat(matcher.length));
85
+ return false;
86
+ }
87
+ // loop over arrays, matching every value
88
+ var index = -1;
89
+ while (++index < length) {
90
+ if (!matchEntry(source[index], source, root, matcher[index], failureLog)) {
91
+ // item did not match, return false
92
+ failureLog === null || failureLog === void 0 ? void 0 : failureLog.push("index ".concat(index, " does not match with value ").concat(JSON.stringify(source[index]), " and matcher ").concat(matcher[index]));
93
+ return false;
94
+ }
95
+ }
96
+ // all items are equal
97
+ return true;
168
98
  }
169
- }
170
- for (const index in matcher) {
171
- const matcherAtIndex = matcher[index];
172
- if (!(index in source)) {
173
- failureLog?.push(
174
- `index ${index} does not exist in source ${JSON.stringify(
175
- source
176
- )} but should match matcher ${JSON.stringify(matcherAtIndex)}`
177
- );
178
- return false;
99
+ // matcher is plain object
100
+ if (typeof matcher === 'object' && null !== matcher) {
101
+ if ("every" in matcher) {
102
+ return matchCompound(source, parent, root, tslib_1.__spreadArray(['every'], tslib_1.__read(matcher.every), false), failureLog);
103
+ }
104
+ if ("some" in matcher) {
105
+ return matchCompound(source, parent, root, tslib_1.__spreadArray(['some'], tslib_1.__read(matcher.some), false), failureLog);
106
+ }
107
+ if ("none" in matcher) {
108
+ return matchCompound(source, parent, root, tslib_1.__spreadArray(['none'], tslib_1.__read(matcher.none), false), failureLog);
109
+ }
110
+ if ("single" in matcher) {
111
+ return matchCompound(source, parent, root, tslib_1.__spreadArray(['single'], tslib_1.__read(matcher.single), false), failureLog);
112
+ }
113
+ if ("someItem" in matcher) {
114
+ return matchTraversal(source, root, 'someItem', matcher.someItem, failureLog);
115
+ }
116
+ if ("everyItem" in matcher) {
117
+ return matchTraversal(source, root, 'everyItem', matcher.everyItem, failureLog);
118
+ }
119
+ if ("noneItem" in matcher) {
120
+ return matchTraversal(source, root, 'noneItem', matcher.noneItem, failureLog);
121
+ }
122
+ if ("singleItem" in matcher) {
123
+ return matchTraversal(source, root, 'singleItem', matcher.singleItem, failureLog);
124
+ }
179
125
  }
180
- const result = matchEntry(
181
- source[index],
182
- source,
183
- root,
184
- matcherAtIndex,
185
- failureLog
186
- );
187
- if (!result) {
188
- failureLog?.push(
189
- `index ${index} does not match with value ${JSON.stringify(
190
- source[index]
191
- )} and matcher ${JSON.stringify(matcherAtIndex)}`
192
- );
193
- return false;
126
+ // matcher is plain object with index keys
127
+ for (var index in matcher) {
128
+ var matcherAtIndex = matcher[index];
129
+ if (!(index in source)) {
130
+ // source does not have item at given index
131
+ failureLog === null || failureLog === void 0 ? void 0 : failureLog.push("index ".concat(index, " does not exist in source ").concat(JSON.stringify(source), " but should match matcher ").concat(JSON.stringify(matcherAtIndex)));
132
+ return false;
133
+ }
134
+ // match the source item at the given index
135
+ var result = matchEntry(source[index], source, root, matcherAtIndex, failureLog);
136
+ if (!result) {
137
+ // item did not match
138
+ failureLog === null || failureLog === void 0 ? void 0 : failureLog.push("index ".concat(index, " does not match with value ").concat(JSON.stringify(source[index]), " and matcher ").concat(JSON.stringify(matcherAtIndex)));
139
+ return false;
140
+ }
194
141
  }
195
- }
196
- return true;
142
+ // all items match
143
+ return true;
197
144
  }
145
+ /**
146
+ * Match an object matcher against the given source.
147
+ */
198
148
  function matchPlainObj(source, parent, root, matcher, failureLog) {
199
- if (Array.isArray(matcher)) {
200
- return matchCompound(source, parent, root, matcher, failureLog);
201
- }
202
- for (const key in matcher) {
203
- if (!(key in source)) {
204
- failureLog?.push(
205
- `key ${key} is specified in matcher but not present in value ${JSON.stringify(
206
- source
207
- )}`
208
- );
209
- return false;
149
+ if (Array.isArray(matcher)) {
150
+ // the matcher is of compound type
151
+ return matchCompound(source, parent, root, matcher, failureLog);
210
152
  }
211
- const result = matchEntry(
212
- source[key],
213
- source,
214
- root,
215
- matcher[key],
216
- failureLog
217
- );
218
- if (!result) {
219
- failureLog?.push(
220
- `key ${key} does not match in value ${JSON.stringify(
221
- source[key]
222
- )} with matcher ${JSON.stringify(matcher[key])}`
223
- );
224
- return false;
153
+ // partial object props matcher
154
+ for (var key in matcher) {
155
+ if (!(key in source)) {
156
+ // the source does not have the given key
157
+ failureLog === null || failureLog === void 0 ? void 0 : failureLog.push("key ".concat(key, " is specified in matcher but not present in value ").concat(JSON.stringify(source)));
158
+ return false;
159
+ }
160
+ // match the source value at the given key with the matcher at given key
161
+ var result = matchEntry(source[key], source, root, matcher[key], failureLog);
162
+ if (!result) {
163
+ failureLog === null || failureLog === void 0 ? void 0 : failureLog.push("key ".concat(key, " does not match in value ").concat(JSON.stringify(source[key]), " with matcher ").concat(JSON.stringify(matcher[key])));
164
+ return false;
165
+ }
225
166
  }
226
- }
227
- return true;
167
+ // all properties match
168
+ return true;
228
169
  }
170
+ /**
171
+ * Match a compound matcher against the given source.
172
+ */
229
173
  function matchCompound(source, parent, root, compound, failureLog) {
230
- const matchType = compound[0];
231
- const length = compound.length;
232
- let index = 0;
233
- switch (matchType) {
234
- case "every": {
235
- while (++index < length) {
236
- const result = matchEntry(
237
- source,
238
- parent,
239
- root,
240
- compound[index],
241
- failureLog
242
- );
243
- if (!result) {
244
- failureLog?.push(
245
- `in compound "every": match at index ${index} failed`
246
- );
247
- return false;
174
+ // first item indicates compound match type
175
+ var matchType = compound[0];
176
+ var length = compound.length;
177
+ // start at index 1
178
+ var index = 0;
179
+ switch (matchType) {
180
+ case 'every': {
181
+ while (++index < length) {
182
+ // if any item does not match, return false
183
+ var result = matchEntry(source, parent, root, compound[index], failureLog);
184
+ if (!result) {
185
+ failureLog === null || failureLog === void 0 ? void 0 : failureLog.push("in compound \"every\": match at index ".concat(index, " failed"));
186
+ return false;
187
+ }
188
+ }
189
+ return true;
248
190
  }
249
- }
250
- return true;
251
- }
252
- case "none": {
253
- while (++index < length) {
254
- const result = matchEntry(
255
- source,
256
- parent,
257
- root,
258
- compound[index],
259
- failureLog
260
- );
261
- if (result) {
262
- failureLog?.push(
263
- `in compound "none": match at index ${index} succeeded`
264
- );
265
- return false;
191
+ case 'none': {
192
+ // if any item matches, return false
193
+ while (++index < length) {
194
+ var result = matchEntry(source, parent, root, compound[index], failureLog);
195
+ if (result) {
196
+ failureLog === null || failureLog === void 0 ? void 0 : failureLog.push("in compound \"none\": match at index ".concat(index, " succeeded"));
197
+ return false;
198
+ }
199
+ }
200
+ return true;
266
201
  }
267
- }
268
- return true;
269
- }
270
- case "single": {
271
- let onePassed = false;
272
- while (++index < length) {
273
- const result = matchEntry(
274
- source,
275
- parent,
276
- root,
277
- compound[index],
278
- failureLog
279
- );
280
- if (result) {
281
- if (onePassed) {
282
- failureLog?.push(
283
- `in compound "single": multiple matches succeeded`
284
- );
285
- return false;
286
- }
287
- onePassed = true;
202
+ case 'single': {
203
+ // if not exactly one item matches, return false
204
+ var onePassed = false;
205
+ while (++index < length) {
206
+ var result = matchEntry(source, parent, root, compound[index], failureLog);
207
+ if (result) {
208
+ if (onePassed) {
209
+ failureLog === null || failureLog === void 0 ? void 0 : failureLog.push("in compound \"single\": multiple matches succeeded");
210
+ return false;
211
+ }
212
+ onePassed = true;
213
+ }
214
+ }
215
+ if (!onePassed) {
216
+ failureLog === null || failureLog === void 0 ? void 0 : failureLog.push("in compound \"single\": no matches succeeded");
217
+ }
218
+ return onePassed;
288
219
  }
289
- }
290
- if (!onePassed) {
291
- failureLog?.push(`in compound "single": no matches succeeded`);
292
- }
293
- return onePassed;
294
- }
295
- case "some": {
296
- while (++index < length) {
297
- const result = matchEntry(
298
- source,
299
- parent,
300
- root,
301
- compound[index],
302
- failureLog
303
- );
304
- if (result) {
305
- return true;
220
+ case 'some': {
221
+ // if any item matches, return true
222
+ while (++index < length) {
223
+ var result = matchEntry(source, parent, root, compound[index], failureLog);
224
+ if (result) {
225
+ return true;
226
+ }
227
+ }
228
+ failureLog === null || failureLog === void 0 ? void 0 : failureLog.push("in compound \"some\": no matches succeeded");
229
+ return false;
306
230
  }
307
- }
308
- failureLog?.push(`in compound "some": no matches succeeded`);
309
- return false;
310
231
  }
311
- }
312
232
  }
313
233
  function matchTraversal(source, root, matchType, matcher, failureLog) {
314
- let index = -1;
315
- const length = source.length;
316
- switch (matchType) {
317
- case "someItem": {
318
- while (++index < length) {
319
- if (matchEntry(source[index], source, root, matcher, failureLog)) {
320
- return true;
234
+ var index = -1;
235
+ var length = source.length;
236
+ switch (matchType) {
237
+ case 'someItem': {
238
+ while (++index < length) {
239
+ if (matchEntry(source[index], source, root, matcher, failureLog)) {
240
+ return true;
241
+ }
242
+ }
243
+ failureLog === null || failureLog === void 0 ? void 0 : failureLog.push("in array traversal \"someItem\": no items matched given matcher");
244
+ return false;
321
245
  }
322
- }
323
- failureLog?.push(
324
- `in array traversal "someItem": no items matched given matcher`
325
- );
326
- return false;
327
- }
328
- case "everyItem": {
329
- while (++index < length) {
330
- if (!matchEntry(source[index], source, root, matcher, failureLog)) {
331
- failureLog?.push(
332
- `in array traversal "everyItem": at least one item did not match given matcher`
333
- );
334
- return false;
246
+ case 'everyItem': {
247
+ while (++index < length) {
248
+ if (!matchEntry(source[index], source, root, matcher, failureLog)) {
249
+ failureLog === null || failureLog === void 0 ? void 0 : failureLog.push("in array traversal \"everyItem\": at least one item did not match given matcher");
250
+ return false;
251
+ }
252
+ }
253
+ return true;
335
254
  }
336
- }
337
- return true;
338
- }
339
- case "noneItem": {
340
- while (++index < length) {
341
- if (matchEntry(source[index], source, root, matcher, failureLog)) {
342
- failureLog?.push(
343
- `in array traversal "noneItem": at least one item matched given matcher`
344
- );
345
- return false;
255
+ case 'noneItem': {
256
+ while (++index < length) {
257
+ if (matchEntry(source[index], source, root, matcher, failureLog)) {
258
+ failureLog === null || failureLog === void 0 ? void 0 : failureLog.push("in array traversal \"noneItem\": at least one item matched given matcher");
259
+ return false;
260
+ }
261
+ }
262
+ return true;
346
263
  }
347
- }
348
- return true;
349
- }
350
- case "singleItem": {
351
- let singleMatched = false;
352
- while (++index < length) {
353
- if (matchEntry(source[index], source, root, matcher, failureLog)) {
354
- if (singleMatched) {
355
- failureLog?.push(
356
- `in array traversal "singleItem": more than one item matched given matcher`
357
- );
358
- return false;
359
- }
360
- singleMatched = true;
264
+ case 'singleItem': {
265
+ var singleMatched = false;
266
+ while (++index < length) {
267
+ if (matchEntry(source[index], source, root, matcher, failureLog)) {
268
+ if (singleMatched) {
269
+ failureLog === null || failureLog === void 0 ? void 0 : failureLog.push("in array traversal \"singleItem\": more than one item matched given matcher");
270
+ return false;
271
+ }
272
+ singleMatched = true;
273
+ }
274
+ }
275
+ if (!singleMatched) {
276
+ failureLog === null || failureLog === void 0 ? void 0 : failureLog.push("in array traversal \"singleItem\": no item matched given matcher");
277
+ return false;
278
+ }
279
+ return true;
361
280
  }
362
- }
363
- if (!singleMatched) {
364
- failureLog?.push(
365
- `in array traversal "singleItem": no item matched given matcher`
366
- );
367
- return false;
368
- }
369
- return true;
370
281
  }
371
- }
372
282
  }
373
- // Annotate the CommonJS export names for ESM import in node:
374
- 0 && (module.exports = {
375
- match
376
- });
283
+ //# sourceMappingURL=match.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"match.cjs","sourceRoot":"","sources":["../../_cjs_prepare/match.cts"],"names":[],"mappings":";;AAyMA,sBAMC;;AA/MD,oCAMqB;AAgLrB;;;;;;;;;;;;;;;;;;GAkBG;AACH,SAAgB,KAAK,CACnB,MAAS,EACT,OAAoB,EACpB,UAA6B;IAE7B,OAAO,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAc,EAAE,UAAU,CAAC,CAAC;AACxE,CAAC;AAED;;GAEG;AACH,SAAS,UAAU,CACjB,MAAS,EACT,MAAS,EACT,IAAO,EACP,OAAgC,EAChC,UAA6B;IAE7B,IAAI,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC;QAC/B,6DAA6D;QAC7D,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,OAAO,KAAK,IAAI,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC9C,mFAAmF;QACnF,qBAAqB;QACrB,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,IA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