@ls-stack/utils 3.26.1 → 3.27.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/testUtils.cjs CHANGED
@@ -59,6 +59,30 @@ function filterAndMap(array, mapFilter) {
59
59
  }
60
60
  return result;
61
61
  }
62
+ function sortBy(arr, sortByValue, props = "asc") {
63
+ const order = Array.isArray(props) || typeof props === "string" ? props : props.order ?? "asc";
64
+ return [...arr].sort((a, b) => {
65
+ const _aPriority = sortByValue(a);
66
+ const _bPriority = sortByValue(b);
67
+ const aPriority = Array.isArray(_aPriority) ? _aPriority : [_aPriority];
68
+ const bPriority = Array.isArray(_bPriority) ? _bPriority : [_bPriority];
69
+ for (let i = 0; i < aPriority.length; i++) {
70
+ const levelOrder = typeof order === "string" ? order : order[i] ?? "asc";
71
+ const aP = aPriority[i] ?? 0;
72
+ const bP = bPriority[i] ?? 0;
73
+ if (aP === bP) {
74
+ continue;
75
+ }
76
+ if (bP === Infinity || aP === -Infinity || aP < bP) {
77
+ return levelOrder === "asc" ? -1 : 1;
78
+ }
79
+ if (aP === Infinity || bP === -Infinity || aP > bP) {
80
+ return levelOrder === "asc" ? 1 : -1;
81
+ }
82
+ }
83
+ return 0;
84
+ });
85
+ }
62
86
  function arrayWithPrevAndIndex(array) {
63
87
  return array.map((item, i) => ({
64
88
  item,
@@ -135,8 +159,57 @@ function deepEqual(foo, bar, maxDepth = 20) {
135
159
  function filterObjectOrArrayKeys(objOrArray, {
136
160
  filterKeys,
137
161
  rejectKeys,
138
- rejectEmptyObjectsInArray = true
162
+ rejectEmptyObjectsInArray = true,
163
+ sortKeys = "simpleValuesFirst",
164
+ sortPatterns
139
165
  }) {
166
+ function getNestedValue(obj, path) {
167
+ const parts = path.split(".");
168
+ let current = obj;
169
+ for (const part of parts) {
170
+ if (current == null || typeof current !== "object") {
171
+ return void 0;
172
+ }
173
+ current = current[part];
174
+ }
175
+ return current;
176
+ }
177
+ function evaluateCondition(item, condition) {
178
+ const value = getNestedValue(item, condition.property);
179
+ let valueStr = String(value);
180
+ if (condition.caseInsensitive) {
181
+ valueStr = valueStr.toLowerCase();
182
+ }
183
+ const processValue = (v) => condition.caseInsensitive ? v.toLowerCase() : v;
184
+ switch (condition.operator) {
185
+ case "=":
186
+ return condition.values.some((v) => valueStr === processValue(v));
187
+ case "!=":
188
+ return condition.values.every((v) => valueStr !== processValue(v));
189
+ case "*=":
190
+ return condition.values.some((v) => valueStr.includes(processValue(v)));
191
+ case "!*=":
192
+ return condition.values.every(
193
+ (v) => !valueStr.includes(processValue(v))
194
+ );
195
+ case "^=":
196
+ return condition.values.some(
197
+ (v) => valueStr.startsWith(processValue(v))
198
+ );
199
+ case "!^=":
200
+ return condition.values.every(
201
+ (v) => !valueStr.startsWith(processValue(v))
202
+ );
203
+ case "$=":
204
+ return condition.values.some((v) => valueStr.endsWith(processValue(v)));
205
+ case "!$=":
206
+ return condition.values.every(
207
+ (v) => !valueStr.endsWith(processValue(v))
208
+ );
209
+ default:
210
+ return false;
211
+ }
212
+ }
140
213
  const toArray = (v) => v === void 0 ? [] : Array.isArray(v) ? v : [v];
141
214
  const filterPatternsRaw = toArray(filterKeys);
142
215
  const rejectPatternsRaw = toArray(rejectKeys);
@@ -144,9 +217,46 @@ function filterObjectOrArrayKeys(objOrArray, {
144
217
  const hasRejects = rejectPatternsRaw.length > 0;
145
218
  const expandedFilterPatterns = filterPatternsRaw.flatMap(expandPatterns);
146
219
  const expandedRejectPatterns = rejectPatternsRaw.flatMap(expandPatterns);
147
- const filterPatterns = expandedFilterPatterns.map(parsePattern);
220
+ const { filterOnlyPatterns, combinedPatterns } = separateFilterPatterns(
221
+ expandedFilterPatterns
222
+ );
223
+ const filterPatterns = filterOnlyPatterns.map(parsePattern);
148
224
  const rejectPatterns = expandedRejectPatterns.map(parsePattern);
149
- function matchPath(path, pattern) {
225
+ const sortPatternsRaw = toArray(sortPatterns);
226
+ const expandedSortPatterns = sortPatternsRaw.flatMap(expandPatterns);
227
+ const sortPatternsParsed = expandedSortPatterns.map(parsePattern);
228
+ let dataToProcess = objOrArray;
229
+ if (combinedPatterns.length > 0) {
230
+ const groupedByFilter = /* @__PURE__ */ new Map();
231
+ for (const { filterPart, fieldPart } of combinedPatterns) {
232
+ if (!groupedByFilter.has(filterPart)) {
233
+ groupedByFilter.set(filterPart, []);
234
+ }
235
+ groupedByFilter.get(filterPart).push(fieldPart);
236
+ }
237
+ const combinedResult = Array.isArray(objOrArray) ? [] : {};
238
+ for (const [filterPart, fieldParts] of groupedByFilter) {
239
+ const filteredResult = filterObjectOrArrayKeys(objOrArray, {
240
+ filterKeys: [filterPart],
241
+ rejectKeys,
242
+ rejectEmptyObjectsInArray
243
+ });
244
+ const fieldSelectedResult = filterObjectOrArrayKeys(filteredResult, {
245
+ filterKeys: fieldParts,
246
+ rejectEmptyObjectsInArray
247
+ });
248
+ if (Array.isArray(combinedResult) && Array.isArray(fieldSelectedResult)) {
249
+ combinedResult.push(...fieldSelectedResult);
250
+ } else if (!Array.isArray(combinedResult) && !Array.isArray(fieldSelectedResult)) {
251
+ Object.assign(combinedResult, fieldSelectedResult);
252
+ }
253
+ }
254
+ if (filterOnlyPatterns.length === 0) {
255
+ return combinedResult;
256
+ }
257
+ dataToProcess = combinedResult;
258
+ }
259
+ function matchPath(path, pattern, value) {
150
260
  function rec(pi, pti) {
151
261
  if (pti >= pattern.length) return pi === path.length;
152
262
  const pt = pattern[pti];
@@ -187,12 +297,92 @@ function filterObjectOrArrayKeys(objOrArray, {
187
297
  if (okLower && okUpper) return rec(pi + 1, pti + 1);
188
298
  }
189
299
  return false;
300
+ case "INDEX_FILTER":
301
+ if (ct.type === "INDEX" && value !== void 0) {
302
+ const results = pt.conditions.map(
303
+ (cond) => evaluateCondition(value, cond)
304
+ );
305
+ const matches = pt.logic === "AND" ? results.every((r) => r) : results.some((r) => r);
306
+ if (matches) return rec(pi + 1, pti + 1);
307
+ }
308
+ return false;
190
309
  }
191
310
  }
192
311
  return rec(0, 0);
193
312
  }
194
- const matchesAnyFilter = (path) => filterPatterns.some((p) => matchPath(path, p));
195
- const matchesAnyReject = (path) => rejectPatterns.some((p) => matchPath(path, p));
313
+ const matchesAnyFilter = (path, value) => filterPatterns.some((p) => matchPath(path, p, value));
314
+ const matchesAnyReject = (path, value) => rejectPatterns.some((p) => matchPath(path, p, value));
315
+ function getSortPriority(path) {
316
+ for (let i = 0; i < sortPatternsParsed.length; i++) {
317
+ if (matchPath(path, sortPatternsParsed[i])) {
318
+ return i;
319
+ }
320
+ }
321
+ return sortPatternsParsed.length;
322
+ }
323
+ function applySortKeys(keys, obj, sortOrder) {
324
+ if (sortOrder === "asc") {
325
+ return [...keys].sort();
326
+ }
327
+ if (sortOrder === "desc") {
328
+ return [...keys].sort().reverse();
329
+ }
330
+ return sortBy(
331
+ sortBy(keys, (k) => k),
332
+ (key) => {
333
+ const value = obj[key];
334
+ if (value !== void 0 && value !== null) {
335
+ if (Array.isArray(value) && value.length === 0) return 0;
336
+ if (isPlainObject(value)) {
337
+ const objLength = Object.keys(value).length;
338
+ return 1.99 + objLength * -1e-3;
339
+ }
340
+ if (Array.isArray(value)) {
341
+ const allItemsArePrimitives = value.every(
342
+ (item) => typeof item === "string" || typeof item === "number" || typeof item === "boolean" || item === null || item === void 0
343
+ );
344
+ if (allItemsArePrimitives) {
345
+ return 1.9 + value.length * -1e-3;
346
+ } else {
347
+ return 1.5 + value.length * -0.01;
348
+ }
349
+ }
350
+ if (typeof value === "boolean") return 4;
351
+ if (typeof value === "number") return 3.5;
352
+ if (typeof value === "string" && value.length < 20) return 3;
353
+ return 2;
354
+ }
355
+ return 0;
356
+ },
357
+ "desc"
358
+ );
359
+ }
360
+ function sortKeysWithPatterns(keys_, obj, currentPath) {
361
+ if (!sortKeys && sortPatternsParsed.length === 0) {
362
+ return keys_;
363
+ }
364
+ let keysToSort = keys_;
365
+ if (sortKeys) {
366
+ keysToSort = applySortKeys(keysToSort, obj, sortKeys);
367
+ }
368
+ const sortedKeys = [...keysToSort].sort((a, b) => {
369
+ const pathA = currentPath.concat({ type: "KEY", name: a });
370
+ const pathB = currentPath.concat({ type: "KEY", name: b });
371
+ const priorityA = getSortPriority(pathA);
372
+ const priorityB = getSortPriority(pathB);
373
+ if (priorityA !== priorityB) {
374
+ return priorityA - priorityB;
375
+ }
376
+ if (sortKeys === "desc") {
377
+ return b.localeCompare(a);
378
+ }
379
+ if (sortKeys === "asc") {
380
+ return a.localeCompare(b);
381
+ }
382
+ return 0;
383
+ });
384
+ return sortedKeys;
385
+ }
196
386
  const build = (value, path, allowedByFilter, stack2, isRoot, parentIsArray) => {
197
387
  if (Array.isArray(value)) {
198
388
  if (stack2.has(value)) {
@@ -203,9 +393,9 @@ function filterObjectOrArrayKeys(objOrArray, {
203
393
  const includeAllChildren = allowedByFilter || !hasFilters;
204
394
  for (let index = 0; index < value.length; index += 1) {
205
395
  const childPath = path.concat({ type: "INDEX", index });
206
- if (hasRejects && matchesAnyReject(childPath)) continue;
207
396
  const child = value[index];
208
- const directInclude = hasFilters ? matchesAnyFilter(childPath) : true;
397
+ if (hasRejects && matchesAnyReject(childPath, child)) continue;
398
+ const directInclude = hasFilters ? matchesAnyFilter(childPath, child) : true;
209
399
  const childAllowed = includeAllChildren || directInclude;
210
400
  if (isPlainObject(child) || Array.isArray(child)) {
211
401
  const builtChild = build(
@@ -240,7 +430,8 @@ function filterObjectOrArrayKeys(objOrArray, {
240
430
  stack2.add(value);
241
431
  const result = {};
242
432
  const includeAllChildren = allowedByFilter || !hasFilters;
243
- for (const key of Object.keys(value)) {
433
+ const sortedKeys = sortKeysWithPatterns(Object.keys(value), value, path);
434
+ for (const key of sortedKeys) {
244
435
  const childPath = path.concat({ type: "KEY", name: key });
245
436
  if (hasRejects && matchesAnyReject(childPath)) continue;
246
437
  const val = value[key];
@@ -286,16 +477,123 @@ function filterObjectOrArrayKeys(objOrArray, {
286
477
  const initialAllowed = !hasFilters;
287
478
  const stack = /* @__PURE__ */ new WeakSet();
288
479
  const built = build(
289
- objOrArray,
480
+ dataToProcess,
290
481
  startPath,
291
482
  initialAllowed,
292
483
  stack,
293
484
  true,
294
485
  false
295
486
  );
296
- if (built === void 0) return Array.isArray(objOrArray) ? [] : {};
487
+ if (built === void 0) return Array.isArray(dataToProcess) ? [] : {};
297
488
  return built;
298
489
  }
490
+ function parseFilterConditions(filterContent) {
491
+ const conditions = [];
492
+ let logic = "AND";
493
+ const caseInsensitive = filterContent.startsWith("i");
494
+ const content = caseInsensitive ? filterContent.slice(1) : filterContent;
495
+ const hasAnd = content.includes("&&");
496
+ const hasOr = content.includes(" || ");
497
+ if (hasAnd && hasOr) {
498
+ throw new Error(
499
+ "Mixing && and || operators in the same filter is not supported. Use separate filter patterns instead."
500
+ );
501
+ }
502
+ const andGroups = content.split("&&").map((s) => s.trim());
503
+ for (const andGroup of andGroups) {
504
+ if (andGroup.includes(" || ")) {
505
+ logic = "OR";
506
+ const orConditions = andGroup.split(" || ").map((s) => s.trim());
507
+ for (const orCondition of orConditions) {
508
+ const parsed = parseSingleCondition(orCondition, caseInsensitive);
509
+ if (parsed) {
510
+ conditions.push(parsed);
511
+ }
512
+ }
513
+ } else {
514
+ const parsed = parseSingleCondition(andGroup, caseInsensitive);
515
+ if (parsed) {
516
+ conditions.push(parsed);
517
+ }
518
+ }
519
+ }
520
+ if (conditions.length === 0) {
521
+ return null;
522
+ }
523
+ return {
524
+ type: "INDEX_FILTER",
525
+ conditions,
526
+ logic
527
+ };
528
+ }
529
+ function parseSingleCondition(condition, caseInsensitive = false) {
530
+ const cleanCondition = condition.startsWith("%") ? condition.slice(1) : condition;
531
+ let operator = null;
532
+ let operatorIndex = -1;
533
+ let operatorLength = 0;
534
+ const operators = [
535
+ ["!*=", "!*="],
536
+ ["!^=", "!^="],
537
+ ["!$=", "!$="],
538
+ ["!=", "!="],
539
+ ["*=", "*="],
540
+ ["^=", "^="],
541
+ ["$=", "$="],
542
+ ["=", "="]
543
+ ];
544
+ for (const [op, opType] of operators) {
545
+ const index = cleanCondition.indexOf(op);
546
+ if (index !== -1) {
547
+ operator = opType;
548
+ operatorIndex = index;
549
+ operatorLength = op.length;
550
+ break;
551
+ }
552
+ }
553
+ if (operator === null || operatorIndex === -1) {
554
+ return null;
555
+ }
556
+ const property = cleanCondition.slice(0, operatorIndex).trim();
557
+ const valueStr = cleanCondition.slice(operatorIndex + operatorLength).trim();
558
+ const values = [];
559
+ if (valueStr.includes(" | ")) {
560
+ const parts = valueStr.split(" | ");
561
+ for (const part of parts) {
562
+ const trimmed = part.trim();
563
+ const value = trimmed.startsWith('"') && trimmed.endsWith('"') ? trimmed.slice(1, -1) : trimmed;
564
+ values.push(value);
565
+ }
566
+ } else {
567
+ const trimmed = valueStr.trim();
568
+ const value = trimmed.startsWith('"') && trimmed.endsWith('"') ? trimmed.slice(1, -1) : trimmed;
569
+ values.push(value);
570
+ }
571
+ return {
572
+ property,
573
+ operator,
574
+ values,
575
+ caseInsensitive
576
+ };
577
+ }
578
+ function separateFilterPatterns(patterns) {
579
+ const filterOnlyPatterns = [];
580
+ const combinedPatterns = [];
581
+ for (const pattern of patterns) {
582
+ const filterMatch = pattern.match(/^(.+\[[i%][^[\]]*\])\.(.+)$/);
583
+ if (filterMatch?.[1] && filterMatch[2]) {
584
+ const filterPart = filterMatch[1];
585
+ const fieldPart = filterMatch[2];
586
+ const baseArrayPath = filterPart.replace(/\[[i%][^[\]]*\]/, "[*]");
587
+ combinedPatterns.push({
588
+ filterPart,
589
+ fieldPart: `${baseArrayPath}.${fieldPart}`
590
+ });
591
+ } else {
592
+ filterOnlyPatterns.push(pattern);
593
+ }
594
+ }
595
+ return { filterOnlyPatterns, combinedPatterns };
596
+ }
299
597
  function expandPatterns(pattern) {
300
598
  function expandSingle(str) {
301
599
  const start = str.indexOf("(");
@@ -339,7 +637,20 @@ function parsePattern(pattern) {
339
637
  if (ch === "[") {
340
638
  const end = pattern.indexOf("]", i + 1);
341
639
  const inside = end === -1 ? pattern.slice(i + 1) : pattern.slice(i + 1, end);
342
- if (inside === "*") {
640
+ if (inside.startsWith("%") || inside.startsWith("i%")) {
641
+ let filterContent;
642
+ if (inside.startsWith("i%")) {
643
+ filterContent = `i${inside.slice(2)}`;
644
+ } else if (inside.startsWith("%")) {
645
+ filterContent = inside.slice(1);
646
+ } else {
647
+ filterContent = inside;
648
+ }
649
+ const filterToken = parseFilterConditions(filterContent);
650
+ if (filterToken) {
651
+ tokens.push(filterToken);
652
+ }
653
+ } else if (inside === "*") {
343
654
  tokens.push({ type: "INDEX_ANY" });
344
655
  } else if (inside.includes("-")) {
345
656
  const parts = inside.split("-");
@@ -1035,6 +1346,8 @@ function compactSnapshot(value, {
1035
1346
  showBooleansAs = true,
1036
1347
  rejectKeys,
1037
1348
  filterKeys,
1349
+ sortKeys,
1350
+ sortPatterns,
1038
1351
  ...options
1039
1352
  } = {}) {
1040
1353
  let processedValue = value;
@@ -1042,7 +1355,9 @@ function compactSnapshot(value, {
1042
1355
  if (isPlainObject(processedValue) || Array.isArray(processedValue)) {
1043
1356
  processedValue = filterObjectOrArrayKeys(processedValue, {
1044
1357
  rejectKeys,
1045
- filterKeys
1358
+ filterKeys,
1359
+ sortKeys,
1360
+ sortPatterns
1046
1361
  });
1047
1362
  }
1048
1363
  }
@@ -71,6 +71,13 @@ declare function waitController(): {
71
71
  * - `'[4-*]'` - All items of the array from the fourth index to the end
72
72
  * - Expanding the patterns with parentheses:
73
73
  * - `'prop.test.(prop1|prop2|prop3.prop4)'` - Will produce `prop.test.prop1`, `prop.test.prop2`, and `prop.test.prop3.prop4`
74
+ * - Array filtering by value:
75
+ * - `'users[%name="John"]'` - Filters the `users` with the `name` property equal to `John`
76
+ * - `'users[%name="John" | "Jane"]'` - Filters the `users` with the `name` property equal to `John` or `Jane`
77
+ * - `'users[%name="John" | "Jane" && %age=20]'` - AND and OR are supported by using `&&` and `||`, nesting logical operators is not supported yet
78
+ * - `'users[%config.name="John" | "Jane"]'` - Dot notation is supported
79
+ *
80
+ * Check more supported patterns in {@link filterObjectOrArrayKeys} docs.
74
81
  *
75
82
  * @param value - The value to snapshot.
76
83
  * @param options - The options for the snapshot.
@@ -81,9 +88,11 @@ declare function waitController(): {
81
88
  * @param options.rejectKeys - The keys to reject.
82
89
  * @param options.filterKeys - The keys to filter.
83
90
  * @param options.ignoreProps - The props to ignore.
91
+ * @param options.sortKeys - Sort all keys by a specific order (default: `simpleValuesFirst`).
92
+ * @param options.sortPatterns - Sort specific keys by pattern. Use to control the order of specific properties. The same patterns as `filterKeys` are supported.
84
93
  * @returns The compact snapshot of the value.
85
94
  */
86
- declare function compactSnapshot(value: unknown, { collapseObjects, maxLineLength, showUndefined, showBooleansAs, rejectKeys, filterKeys, ...options }?: YamlStringifyOptions & {
95
+ declare function compactSnapshot(value: unknown, { collapseObjects, maxLineLength, showUndefined, showBooleansAs, rejectKeys, filterKeys, sortKeys, sortPatterns, ...options }?: YamlStringifyOptions & {
87
96
  showBooleansAs?: boolean | {
88
97
  props?: Record<string, {
89
98
  trueText?: string;
@@ -93,47 +102,10 @@ declare function compactSnapshot(value: unknown, { collapseObjects, maxLineLengt
93
102
  trueText?: string;
94
103
  falseText?: string;
95
104
  };
96
- /**
97
- * Reject (exclude) keys from the snapshot using pattern matching.
98
- *
99
- * **Examples:**
100
- * ```typescript
101
- * // Reject root-level 'secret' only
102
- * rejectKeys: ['secret']
103
- *
104
- * // Reject nested 'password' properties only
105
- * rejectKeys: ['*.password']
106
- *
107
- * // Reject any 'apiKey' property at any level
108
- * rejectKeys: ['*apiKey']
109
- *
110
- * // Reject specific nested path
111
- * rejectKeys: ['user.settings.theme']
112
- * ```
113
- */
114
105
  rejectKeys?: string[] | string;
115
- /**
116
- * Filter (include only) keys that match the specified patterns.
117
- *
118
- * **Examples:**
119
- * ```typescript
120
- * // Include only root-level 'user'
121
- * filterKeys: ['user']
122
- *
123
- * // Include all 'name' properties at any level
124
- * filterKeys: ['*name']
125
- *
126
- * // Include only nested 'id' properties
127
- * filterKeys: ['*.id']
128
- *
129
- * // Include specific nested paths
130
- * filterKeys: ['user.profile.email', 'settings.theme']
131
- * ```
132
- *
133
- * **Note:** When filtering, parent paths are automatically included if needed
134
- * to preserve the structure for nested matches.
135
- */
136
106
  filterKeys?: string[] | string;
107
+ sortKeys?: 'asc' | 'desc' | 'simpleValuesFirst' | false;
108
+ sortPatterns?: string[];
137
109
  }): string;
138
110
 
139
111
  export { compactSnapshot, createLoggerStore, getResultFn, waitController };
@@ -71,6 +71,13 @@ declare function waitController(): {
71
71
  * - `'[4-*]'` - All items of the array from the fourth index to the end
72
72
  * - Expanding the patterns with parentheses:
73
73
  * - `'prop.test.(prop1|prop2|prop3.prop4)'` - Will produce `prop.test.prop1`, `prop.test.prop2`, and `prop.test.prop3.prop4`
74
+ * - Array filtering by value:
75
+ * - `'users[%name="John"]'` - Filters the `users` with the `name` property equal to `John`
76
+ * - `'users[%name="John" | "Jane"]'` - Filters the `users` with the `name` property equal to `John` or `Jane`
77
+ * - `'users[%name="John" | "Jane" && %age=20]'` - AND and OR are supported by using `&&` and `||`, nesting logical operators is not supported yet
78
+ * - `'users[%config.name="John" | "Jane"]'` - Dot notation is supported
79
+ *
80
+ * Check more supported patterns in {@link filterObjectOrArrayKeys} docs.
74
81
  *
75
82
  * @param value - The value to snapshot.
76
83
  * @param options - The options for the snapshot.
@@ -81,9 +88,11 @@ declare function waitController(): {
81
88
  * @param options.rejectKeys - The keys to reject.
82
89
  * @param options.filterKeys - The keys to filter.
83
90
  * @param options.ignoreProps - The props to ignore.
91
+ * @param options.sortKeys - Sort all keys by a specific order (default: `simpleValuesFirst`).
92
+ * @param options.sortPatterns - Sort specific keys by pattern. Use to control the order of specific properties. The same patterns as `filterKeys` are supported.
84
93
  * @returns The compact snapshot of the value.
85
94
  */
86
- declare function compactSnapshot(value: unknown, { collapseObjects, maxLineLength, showUndefined, showBooleansAs, rejectKeys, filterKeys, ...options }?: YamlStringifyOptions & {
95
+ declare function compactSnapshot(value: unknown, { collapseObjects, maxLineLength, showUndefined, showBooleansAs, rejectKeys, filterKeys, sortKeys, sortPatterns, ...options }?: YamlStringifyOptions & {
87
96
  showBooleansAs?: boolean | {
88
97
  props?: Record<string, {
89
98
  trueText?: string;
@@ -93,47 +102,10 @@ declare function compactSnapshot(value: unknown, { collapseObjects, maxLineLengt
93
102
  trueText?: string;
94
103
  falseText?: string;
95
104
  };
96
- /**
97
- * Reject (exclude) keys from the snapshot using pattern matching.
98
- *
99
- * **Examples:**
100
- * ```typescript
101
- * // Reject root-level 'secret' only
102
- * rejectKeys: ['secret']
103
- *
104
- * // Reject nested 'password' properties only
105
- * rejectKeys: ['*.password']
106
- *
107
- * // Reject any 'apiKey' property at any level
108
- * rejectKeys: ['*apiKey']
109
- *
110
- * // Reject specific nested path
111
- * rejectKeys: ['user.settings.theme']
112
- * ```
113
- */
114
105
  rejectKeys?: string[] | string;
115
- /**
116
- * Filter (include only) keys that match the specified patterns.
117
- *
118
- * **Examples:**
119
- * ```typescript
120
- * // Include only root-level 'user'
121
- * filterKeys: ['user']
122
- *
123
- * // Include all 'name' properties at any level
124
- * filterKeys: ['*name']
125
- *
126
- * // Include only nested 'id' properties
127
- * filterKeys: ['*.id']
128
- *
129
- * // Include specific nested paths
130
- * filterKeys: ['user.profile.email', 'settings.theme']
131
- * ```
132
- *
133
- * **Note:** When filtering, parent paths are automatically included if needed
134
- * to preserve the structure for nested matches.
135
- */
136
106
  filterKeys?: string[] | string;
107
+ sortKeys?: 'asc' | 'desc' | 'simpleValuesFirst' | false;
108
+ sortPatterns?: string[];
137
109
  }): string;
138
110
 
139
111
  export { compactSnapshot, createLoggerStore, getResultFn, waitController };
package/lib/testUtils.js CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  } from "./chunk-JQFUKJU5.js";
12
12
  import {
13
13
  filterObjectOrArrayKeys
14
- } from "./chunk-2WZGT4NA.js";
14
+ } from "./chunk-TUJEGBFW.js";
15
15
  import {
16
16
  defer
17
17
  } from "./chunk-DFXNVEH6.js";
@@ -263,6 +263,8 @@ function compactSnapshot(value, {
263
263
  showBooleansAs = true,
264
264
  rejectKeys,
265
265
  filterKeys,
266
+ sortKeys,
267
+ sortPatterns,
266
268
  ...options
267
269
  } = {}) {
268
270
  let processedValue = value;
@@ -270,7 +272,9 @@ function compactSnapshot(value, {
270
272
  if (isPlainObject(processedValue) || Array.isArray(processedValue)) {
271
273
  processedValue = filterObjectOrArrayKeys(processedValue, {
272
274
  rejectKeys,
273
- filterKeys
275
+ filterKeys,
276
+ sortKeys,
277
+ sortPatterns
274
278
  });
275
279
  }
276
280
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ls-stack/utils",
3
3
  "description": "Universal TypeScript utilities for browser and Node.js",
4
- "version": "3.26.1",
4
+ "version": "3.27.1",
5
5
  "license": "MIT",
6
6
  "files": [
7
7
  "lib",