@ls-stack/utils 3.24.1 → 3.25.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.
Files changed (56) hide show
  1. package/docs/_media/modules.md +1 -0
  2. package/docs/arrayUtils/-internal-.md +1 -1
  3. package/docs/arrayUtils/README.md +12 -12
  4. package/docs/consoleFmt.md +2 -2
  5. package/docs/exhaustiveMatch/-internal-.md +1 -1
  6. package/docs/exhaustiveMatch/README.md +1 -1
  7. package/docs/filterObjectOrArrayKeys.md +80 -0
  8. package/docs/modules.md +1 -0
  9. package/docs/objUtils.md +7 -7
  10. package/docs/parallelAsyncCalls/-internal-.md +3 -3
  11. package/docs/parallelAsyncCalls/README.md +1 -1
  12. package/docs/retryOnError/README.md +1 -1
  13. package/docs/runShellCmd/README.md +9 -9
  14. package/docs/safeJson.md +2 -2
  15. package/docs/saferTyping.md +7 -7
  16. package/docs/stringUtils/README.md +6 -6
  17. package/docs/testUtils.md +40 -6
  18. package/docs/time.md +1 -1
  19. package/docs/tsResult/README.md +17 -11
  20. package/docs/typingFnUtils/-internal-.md +1 -1
  21. package/docs/typingFnUtils/README.md +8 -10
  22. package/lib/arrayUtils.d.cts +6 -1
  23. package/lib/arrayUtils.d.ts +6 -1
  24. package/lib/{chunk-JAPKLFIK.js → chunk-QLD7KG5I.js} +34 -20
  25. package/lib/chunk-XXYTMSFH.js +240 -0
  26. package/lib/filterObjectOrArrayKeys.cjs +275 -0
  27. package/lib/filterObjectOrArrayKeys.d.cts +42 -0
  28. package/lib/filterObjectOrArrayKeys.d.ts +42 -0
  29. package/lib/filterObjectOrArrayKeys.js +7 -0
  30. package/lib/objUtils.d.cts +4 -1
  31. package/lib/objUtils.d.ts +4 -1
  32. package/lib/parallelAsyncCalls.cjs +4 -1
  33. package/lib/parallelAsyncCalls.d.cts +4 -1
  34. package/lib/parallelAsyncCalls.d.ts +4 -1
  35. package/lib/parallelAsyncCalls.js +4 -1
  36. package/lib/retryOnError.d.cts +2 -0
  37. package/lib/retryOnError.d.ts +2 -0
  38. package/lib/runShellCmd.d.cts +17 -0
  39. package/lib/runShellCmd.d.ts +17 -0
  40. package/lib/safeJson.d.cts +8 -2
  41. package/lib/safeJson.d.ts +8 -2
  42. package/lib/saferTyping.d.cts +3 -0
  43. package/lib/saferTyping.d.ts +3 -0
  44. package/lib/stringUtils.d.cts +1 -0
  45. package/lib/stringUtils.d.ts +1 -0
  46. package/lib/testUtils.cjs +273 -144
  47. package/lib/testUtils.d.cts +40 -12
  48. package/lib/testUtils.d.ts +40 -12
  49. package/lib/testUtils.js +10 -125
  50. package/lib/tsResult.d.cts +31 -7
  51. package/lib/tsResult.d.ts +31 -7
  52. package/lib/typingFnUtils.d.cts +20 -6
  53. package/lib/typingFnUtils.d.ts +20 -6
  54. package/lib/yamlStringify.cjs +34 -20
  55. package/lib/yamlStringify.js +1 -1
  56. package/package.json +5 -1
package/docs/testUtils.md CHANGED
@@ -11,10 +11,38 @@
11
11
  ### compactSnapshot()
12
12
 
13
13
  ```ts
14
- function compactSnapshot(value, __namedParameters): string;
14
+ function compactSnapshot(value, options): string;
15
15
  ```
16
16
 
17
- Defined in: [packages/utils/src/testUtils.ts:487](https://github.com/lucasols/utils/blob/main/packages/utils/src/testUtils.ts#L487)
17
+ Defined in: [packages/utils/src/testUtils.ts:352](https://github.com/lucasols/utils/blob/main/packages/utils/src/testUtils.ts#L352)
18
+
19
+ Produces a more compact and readable snapshot of a value using yaml.
20
+ By default booleans are shown as `✅` and `❌`, use `showBooleansAs` to disable/configure this.
21
+
22
+ Filtering patterns in `rejectKeys` and `filterKeys`:
23
+ - `'prop'` - Only root-level properties named 'prop'
24
+ - `'**prop'` - Any property named exactly 'prop' at any level (root or nested)
25
+ - `'*.prop'` - Any nested property named 'prop' at second level (excludes root-level matches)
26
+ - `'test.*.prop'` - Any property named 'prop' at second level of 'test'
27
+ - `'test.*.test.**prop'` - Any property named 'prop' inside of 'test.*.test'
28
+ - `'prop.nested'` - Exact nested property paths like `obj.prop.nested`
29
+ - `'prop.**nested'` - All nested properties inside root `prop` with name `nested`
30
+ - `'prop[0]'` - The first item of the `prop` array
31
+ - `'prop[*]'` - All items of the `prop` array
32
+ - `'prop[0].nested'` - `nested` prop of the first item of the `prop` array
33
+ - `'prop[*].nested'` - `nested` prop of all items of the `prop` array
34
+ - `'prop[*]**nested'` - all `nested` props of all items of the `prop` array
35
+ - `'prop[0-2]'` - The first three items of the `prop` array
36
+ - `'prop[4-*]'` - All items of the `prop` array from the fourth index to the end
37
+ - `'prop[0-2].nested.**prop'` - Combining multiple nested patterns is supported
38
+ - Root array:
39
+ - `'[0]'` - The first item of the root array
40
+ - `'[*]'` - All items of the array
41
+ - `'[0].nested'` - `nested` prop of the first item of the array
42
+ - `'[*].nested'` - `nested` prop of all items of the array
43
+ - `'[*]**nested'` - all `nested` props of all items of the array
44
+ - `'[0-2]'` - The first three items of the array
45
+ - `'[4-*]'` - All items of the array from the fourth index to the end
18
46
 
19
47
  #### Parameters
20
48
 
@@ -22,14 +50,20 @@ Defined in: [packages/utils/src/testUtils.ts:487](https://github.com/lucasols/ut
22
50
 
23
51
  `unknown`
24
52
 
25
- ##### \_\_namedParameters
53
+ The value to snapshot.
54
+
55
+ ##### options
26
56
 
27
57
  [`YamlStringifyOptions`](yamlStringify.md#yamlstringifyoptions) & `object` = `{}`
28
58
 
59
+ The options for the snapshot.
60
+
29
61
  #### Returns
30
62
 
31
63
  `string`
32
64
 
65
+ The compact snapshot of the value.
66
+
33
67
  ***
34
68
 
35
69
  ### createLoggerStore()
@@ -38,7 +72,7 @@ Defined in: [packages/utils/src/testUtils.ts:487](https://github.com/lucasols/ut
38
72
  function createLoggerStore(__namedParameters): object;
39
73
  ```
40
74
 
41
- Defined in: [packages/utils/src/testUtils.ts:10](https://github.com/lucasols/utils/blob/main/packages/utils/src/testUtils.ts#L10)
75
+ Defined in: [packages/utils/src/testUtils.ts:11](https://github.com/lucasols/utils/blob/main/packages/utils/src/testUtils.ts#L11)
42
76
 
43
77
  #### Parameters
44
78
 
@@ -270,7 +304,7 @@ get snapshotFromLast(): string;
270
304
  function getResultFn<T>(fnGetter, wrapper?): T;
271
305
  ```
272
306
 
273
- Defined in: [packages/utils/src/testUtils.ts:276](https://github.com/lucasols/utils/blob/main/packages/utils/src/testUtils.ts#L276)
307
+ Defined in: [packages/utils/src/testUtils.ts:277](https://github.com/lucasols/utils/blob/main/packages/utils/src/testUtils.ts#L277)
274
308
 
275
309
  #### Type Parameters
276
310
 
@@ -300,7 +334,7 @@ Defined in: [packages/utils/src/testUtils.ts:276](https://github.com/lucasols/ut
300
334
  function waitController(): object;
301
335
  ```
302
336
 
303
- Defined in: [packages/utils/src/testUtils.ts:291](https://github.com/lucasols/utils/blob/main/packages/utils/src/testUtils.ts#L291)
337
+ Defined in: [packages/utils/src/testUtils.ts:292](https://github.com/lucasols/utils/blob/main/packages/utils/src/testUtils.ts#L292)
304
338
 
305
339
  #### Returns
306
340
 
package/docs/time.md CHANGED
@@ -243,7 +243,7 @@ Defined in: [packages/utils/src/time.ts:29](https://github.com/lucasols/utils/bl
243
243
 
244
244
  ##### format
245
245
 
246
- `"seconds"` | `"minutes"` | `"milliseconds"`
246
+ `"minutes"` | `"seconds"` | `"milliseconds"`
247
247
 
248
248
  ##### hoursMinLength
249
249
 
@@ -18,7 +18,7 @@
18
18
  type GetTypedResult<R> = TypedResult<R extends Result<infer T, any> ? T : never, R extends Result<any, infer E> ? E : never>;
19
19
  ```
20
20
 
21
- Defined in: [packages/utils/src/tsResult.ts:328](https://github.com/lucasols/utils/blob/main/packages/utils/src/tsResult.ts#L328)
21
+ Defined in: [packages/utils/src/tsResult.ts:355](https://github.com/lucasols/utils/blob/main/packages/utils/src/tsResult.ts#L355)
22
22
 
23
23
  #### Type Parameters
24
24
 
@@ -83,7 +83,7 @@ Use `t-result` library instead.
83
83
  type TypedResult<T, E> = object;
84
84
  ```
85
85
 
86
- Defined in: [packages/utils/src/tsResult.ts:318](https://github.com/lucasols/utils/blob/main/packages/utils/src/tsResult.ts#L318)
86
+ Defined in: [packages/utils/src/tsResult.ts:345](https://github.com/lucasols/utils/blob/main/packages/utils/src/tsResult.ts#L345)
87
87
 
88
88
  #### Deprecated
89
89
 
@@ -107,7 +107,7 @@ Use `t-result` library instead.
107
107
  _type: Result<T, E>;
108
108
  ```
109
109
 
110
- Defined in: [packages/utils/src/tsResult.ts:324](https://github.com/lucasols/utils/blob/main/packages/utils/src/tsResult.ts#L324)
110
+ Defined in: [packages/utils/src/tsResult.ts:351](https://github.com/lucasols/utils/blob/main/packages/utils/src/tsResult.ts#L351)
111
111
 
112
112
  ###### Deprecated
113
113
 
@@ -119,7 +119,7 @@ Use `t-result` library instead.
119
119
  err: (error) => Err<E>;
120
120
  ```
121
121
 
122
- Defined in: [packages/utils/src/tsResult.ts:322](https://github.com/lucasols/utils/blob/main/packages/utils/src/tsResult.ts#L322)
122
+ Defined in: [packages/utils/src/tsResult.ts:349](https://github.com/lucasols/utils/blob/main/packages/utils/src/tsResult.ts#L349)
123
123
 
124
124
  ###### Parameters
125
125
 
@@ -141,7 +141,7 @@ Use `t-result` library instead.
141
141
  ok: (value) => Ok<T>;
142
142
  ```
143
143
 
144
- Defined in: [packages/utils/src/tsResult.ts:320](https://github.com/lucasols/utils/blob/main/packages/utils/src/tsResult.ts#L320)
144
+ Defined in: [packages/utils/src/tsResult.ts:347](https://github.com/lucasols/utils/blob/main/packages/utils/src/tsResult.ts#L347)
145
145
 
146
146
  ###### Parameters
147
147
 
@@ -477,7 +477,7 @@ Use `t-result` library instead.
477
477
  function err<E>(error): Err<E>;
478
478
  ```
479
479
 
480
- Defined in: [packages/utils/src/tsResult.ts:149](https://github.com/lucasols/utils/blob/main/packages/utils/src/tsResult.ts#L149)
480
+ Defined in: [packages/utils/src/tsResult.ts:158](https://github.com/lucasols/utils/blob/main/packages/utils/src/tsResult.ts#L158)
481
481
 
482
482
  #### Type Parameters
483
483
 
@@ -503,6 +503,8 @@ Use `t-result` library instead.
503
503
 
504
504
  ### ~~ok()~~
505
505
 
506
+ #### Param
507
+
506
508
  #### Deprecated
507
509
 
508
510
  Use `t-result` library instead.
@@ -519,6 +521,8 @@ Defined in: [packages/utils/src/tsResult.ts:124](https://github.com/lucasols/uti
519
521
 
520
522
  [`Ok`](-internal-.md#ok)\<`void`\>
521
523
 
524
+ ##### Param
525
+
522
526
  ##### Deprecated
523
527
 
524
528
  Use `t-result` library instead.
@@ -533,7 +537,7 @@ Use `t-result` library instead.
533
537
  function ok<T>(value): Ok<T>;
534
538
  ```
535
539
 
536
- Defined in: [packages/utils/src/tsResult.ts:126](https://github.com/lucasols/utils/blob/main/packages/utils/src/tsResult.ts#L126)
540
+ Defined in: [packages/utils/src/tsResult.ts:129](https://github.com/lucasols/utils/blob/main/packages/utils/src/tsResult.ts#L129)
537
541
 
538
542
  ##### Type Parameters
539
543
 
@@ -551,6 +555,8 @@ Defined in: [packages/utils/src/tsResult.ts:126](https://github.com/lucasols/uti
551
555
 
552
556
  [`Ok`](-internal-.md#ok)\<`T`\>
553
557
 
558
+ ##### Param
559
+
554
560
  ##### Deprecated
555
561
 
556
562
  Use `t-result` library instead.
@@ -569,7 +575,7 @@ Use `t-result` library instead.
569
575
  function resultify<T, E>(fn, errorNormalizer?): Result<T, E>;
570
576
  ```
571
577
 
572
- Defined in: [packages/utils/src/tsResult.ts:238](https://github.com/lucasols/utils/blob/main/packages/utils/src/tsResult.ts#L238)
578
+ Defined in: [packages/utils/src/tsResult.ts:254](https://github.com/lucasols/utils/blob/main/packages/utils/src/tsResult.ts#L254)
573
579
 
574
580
  ##### Type Parameters
575
581
 
@@ -605,7 +611,7 @@ Use `t-result` library instead.
605
611
  function resultify<T, E>(fn, errorNormalizer?): Promise<Result<Awaited<T>, E>>;
606
612
  ```
607
613
 
608
- Defined in: [packages/utils/src/tsResult.ts:243](https://github.com/lucasols/utils/blob/main/packages/utils/src/tsResult.ts#L243)
614
+ Defined in: [packages/utils/src/tsResult.ts:263](https://github.com/lucasols/utils/blob/main/packages/utils/src/tsResult.ts#L263)
609
615
 
610
616
  ##### Type Parameters
611
617
 
@@ -641,7 +647,7 @@ Use `t-result` library instead.
641
647
  function resultify<T, E>(fn, errorNormalizer?): Promise<Result<T, E>>;
642
648
  ```
643
649
 
644
- Defined in: [packages/utils/src/tsResult.ts:248](https://github.com/lucasols/utils/blob/main/packages/utils/src/tsResult.ts#L248)
650
+ Defined in: [packages/utils/src/tsResult.ts:272](https://github.com/lucasols/utils/blob/main/packages/utils/src/tsResult.ts#L272)
645
651
 
646
652
  ##### Type Parameters
647
653
 
@@ -679,7 +685,7 @@ Use `t-result` library instead.
679
685
  function unknownToError(error): Error;
680
686
  ```
681
687
 
682
- Defined in: [packages/utils/src/tsResult.ts:296](https://github.com/lucasols/utils/blob/main/packages/utils/src/tsResult.ts#L296)
688
+ Defined in: [packages/utils/src/tsResult.ts:323](https://github.com/lucasols/utils/blob/main/packages/utils/src/tsResult.ts#L323)
683
689
 
684
690
  #### Parameters
685
691
 
@@ -14,7 +14,7 @@
14
14
  type UnionDiff<T, U> = [T] extends [U] ? [U] extends [T] ? null : object : [U] extends [T] ? object : object;
15
15
  ```
16
16
 
17
- Defined in: [packages/utils/src/typingFnUtils.ts:77](https://github.com/lucasols/utils/blob/main/packages/utils/src/typingFnUtils.ts#L77)
17
+ Defined in: [packages/utils/src/typingFnUtils.ts:92](https://github.com/lucasols/utils/blob/main/packages/utils/src/typingFnUtils.ts#L92)
18
18
 
19
19
  #### Type Parameters
20
20
 
@@ -18,7 +18,7 @@
18
18
  const isSubTypeOf: <BaseType, SubType>() => unknown = typeOnRightExtendsLeftType;
19
19
  ```
20
20
 
21
- Defined in: [packages/utils/src/typingFnUtils.ts:65](https://github.com/lucasols/utils/blob/main/packages/utils/src/typingFnUtils.ts#L65)
21
+ Defined in: [packages/utils/src/typingFnUtils.ts:78](https://github.com/lucasols/utils/blob/main/packages/utils/src/typingFnUtils.ts#L78)
22
22
 
23
23
  Type helper to check if a type is a subtype of another type.
24
24
 
@@ -80,7 +80,7 @@ Defined in: [packages/utils/src/typingFnUtils.ts:3](https://github.com/lucasols/
80
80
  function asType<T>(value): T;
81
81
  ```
82
82
 
83
- Defined in: [packages/utils/src/typingFnUtils.ts:28](https://github.com/lucasols/utils/blob/main/packages/utils/src/typingFnUtils.ts#L28)
83
+ Defined in: [packages/utils/src/typingFnUtils.ts:37](https://github.com/lucasols/utils/blob/main/packages/utils/src/typingFnUtils.ts#L37)
84
84
 
85
85
  a safe way to cast types, use to substitute the `as Type`
86
86
 
@@ -108,7 +108,7 @@ a safe way to cast types, use to substitute the `as Type`
108
108
  function isObjKey<T>(key, obj): key is keyof T;
109
109
  ```
110
110
 
111
- Defined in: [packages/utils/src/typingFnUtils.ts:70](https://github.com/lucasols/utils/blob/main/packages/utils/src/typingFnUtils.ts#L70)
111
+ Defined in: [packages/utils/src/typingFnUtils.ts:85](https://github.com/lucasols/utils/blob/main/packages/utils/src/typingFnUtils.ts#L85)
112
112
 
113
113
  Type helper to narrow a string to a key of an object.
114
114
 
@@ -140,7 +140,7 @@ Type helper to narrow a string to a key of an object.
140
140
  function narrowStringToUnion<T>(key, union): undefined | T;
141
141
  ```
142
142
 
143
- Defined in: [packages/utils/src/typingFnUtils.ts:33](https://github.com/lucasols/utils/blob/main/packages/utils/src/typingFnUtils.ts#L33)
143
+ Defined in: [packages/utils/src/typingFnUtils.ts:46](https://github.com/lucasols/utils/blob/main/packages/utils/src/typingFnUtils.ts#L46)
144
144
 
145
145
  narrow a string to a union of strings
146
146
 
@@ -172,7 +172,7 @@ narrow a string to a union of strings
172
172
  function typedObjectEntries<T>(obj): NonNullable<{ [K in string | number | symbol]: [K, T[K]] }[keyof T]>[];
173
173
  ```
174
174
 
175
- Defined in: [packages/utils/src/typingFnUtils.ts:10](https://github.com/lucasols/utils/blob/main/packages/utils/src/typingFnUtils.ts#L10)
175
+ Defined in: [packages/utils/src/typingFnUtils.ts:13](https://github.com/lucasols/utils/blob/main/packages/utils/src/typingFnUtils.ts#L13)
176
176
 
177
177
  a wrapper to Object.entries with a better typing inference
178
178
 
@@ -200,7 +200,7 @@ a wrapper to Object.entries with a better typing inference
200
200
  function typedObjectKeys<T>(obj): keyof T[];
201
201
  ```
202
202
 
203
- Defined in: [packages/utils/src/typingFnUtils.ts:21](https://github.com/lucasols/utils/blob/main/packages/utils/src/typingFnUtils.ts#L21)
203
+ Defined in: [packages/utils/src/typingFnUtils.ts:27](https://github.com/lucasols/utils/blob/main/packages/utils/src/typingFnUtils.ts#L27)
204
204
 
205
205
  a wrapper to Object.keys with a better typing inference
206
206
 
@@ -228,7 +228,7 @@ keyof `T`[]
228
228
  function typeOnRightExtendsLeftType<BaseType, SubType>(): unknown;
229
229
  ```
230
230
 
231
- Defined in: [packages/utils/src/typingFnUtils.ts:57](https://github.com/lucasols/utils/blob/main/packages/utils/src/typingFnUtils.ts#L57)
231
+ Defined in: [packages/utils/src/typingFnUtils.ts:70](https://github.com/lucasols/utils/blob/main/packages/utils/src/typingFnUtils.ts#L70)
232
232
 
233
233
  Type helper to check if a type is a subtype of another type.
234
234
 
@@ -260,7 +260,7 @@ Returns undefined, only used for type checking
260
260
  function unionsAreTheSame<T, U>(_diff): void;
261
261
  ```
262
262
 
263
- Defined in: [packages/utils/src/typingFnUtils.ts:93](https://github.com/lucasols/utils/blob/main/packages/utils/src/typingFnUtils.ts#L93)
263
+ Defined in: [packages/utils/src/typingFnUtils.ts:107](https://github.com/lucasols/utils/blob/main/packages/utils/src/typingFnUtils.ts#L107)
264
264
 
265
265
  Type helper to compare two union types and determine their relationship.
266
266
 
@@ -289,5 +289,3 @@ null if unions are identical, or an object describing the errors
289
289
  #### Returns
290
290
 
291
291
  `void`
292
-
293
- void - This function is only used for type checking
@@ -4,6 +4,8 @@
4
4
  * In the `mapFilter` function return `false` to reject the item, or any other
5
5
  * value to map it.
6
6
  *
7
+ * @param array
8
+ * @param mapFilter
7
9
  * @example
8
10
  * // Filter reject and turn value into `value mapped`
9
11
  * const items = ['value', 'value', 'reject', 'reject'];
@@ -26,6 +28,9 @@ type SortOrder = 'desc' | 'asc';
26
28
  *
27
29
  * Use `Infinity` as as wildcard to absolute max and min values
28
30
  *
31
+ * @param arr
32
+ * @param sortByValue
33
+ * @param props
29
34
  * @example
30
35
  * const items = [1, 3, 2, 4];
31
36
  *
@@ -36,7 +41,7 @@ type SortOrder = 'desc' | 'asc';
36
41
  *
37
42
  * // return a array to sort by multiple values
38
43
  * const sortedItems = sortBy(items, (item) => [item.a, item.b]);
39
- **/
44
+ */
40
45
  declare function sortBy<T>(arr: T[], sortByValue: (item: T) => (number | string)[] | number | string, props?: {
41
46
  order?: SortOrder | SortOrder[];
42
47
  } | SortOrder | SortOrder[]): T[];
@@ -4,6 +4,8 @@
4
4
  * In the `mapFilter` function return `false` to reject the item, or any other
5
5
  * value to map it.
6
6
  *
7
+ * @param array
8
+ * @param mapFilter
7
9
  * @example
8
10
  * // Filter reject and turn value into `value mapped`
9
11
  * const items = ['value', 'value', 'reject', 'reject'];
@@ -26,6 +28,9 @@ type SortOrder = 'desc' | 'asc';
26
28
  *
27
29
  * Use `Infinity` as as wildcard to absolute max and min values
28
30
  *
31
+ * @param arr
32
+ * @param sortByValue
33
+ * @param props
29
34
  * @example
30
35
  * const items = [1, 3, 2, 4];
31
36
  *
@@ -36,7 +41,7 @@ type SortOrder = 'desc' | 'asc';
36
41
  *
37
42
  * // return a array to sort by multiple values
38
43
  * const sortedItems = sortBy(items, (item) => [item.a, item.b]);
39
- **/
44
+ */
40
45
  declare function sortBy<T>(arr: T[], sortByValue: (item: T) => (number | string)[] | number | string, props?: {
41
46
  order?: SortOrder | SortOrder[];
42
47
  } | SortOrder | SortOrder[]): T[];
@@ -18,12 +18,12 @@ function yamlStringify(obj, {
18
18
  addRootObjSpaces = "beforeAndAfter"
19
19
  } = {}) {
20
20
  if (isObject(obj) || Array.isArray(obj) || typeof obj === "function") {
21
- return `${stringifyValue(obj, "", maxLineLength, !!showUndefined, maxDepth, 0, collapseObjects, addRootObjSpaces)}
21
+ return `${stringifyValue(obj, "", maxLineLength, !!showUndefined, maxDepth, 0, collapseObjects, addRootObjSpaces, false)}
22
22
  `;
23
23
  }
24
24
  return JSON.stringify(obj) || "undefined";
25
25
  }
26
- function stringifyValue(value, indent, maxLineLength, showUndefined, maxDepth, depth, collapseObjects, addObjSpaces) {
26
+ function stringifyValue(value, indent, maxLineLength, showUndefined, maxDepth, depth, collapseObjects, addObjSpaces, isArrayItem) {
27
27
  let result = "";
28
28
  const childIndent = `${indent} `;
29
29
  if (isPlainObject(value)) {
@@ -42,7 +42,8 @@ function stringifyValue(value, indent, maxLineLength, showUndefined, maxDepth, d
42
42
  return typeof val === "number" || typeof val === "boolean" || val === null || val === void 0;
43
43
  }
44
44
  );
45
- if (isSimpleObject && entries.length > 0) {
45
+ const shouldCollapse = isArrayItem ? entries.length > 1 : entries.length > 0;
46
+ if (isSimpleObject && shouldCollapse) {
46
47
  let line = "{ ";
47
48
  line += entries.map(([key, val]) => {
48
49
  let valueStr;
@@ -89,20 +90,29 @@ function stringifyValue(value, indent, maxLineLength, showUndefined, maxDepth, d
89
90
  maxDepth,
90
91
  depth + 1,
91
92
  collapseObjects,
92
- addObjSpaces
93
+ addObjSpaces,
94
+ false
93
95
  );
94
- const willBeCollapsed = isObject(objVal) && (Object.keys(objVal).length === 0 || collapseObjects && depth + 1 > 0 && Object.entries(objVal).filter(([, val]) => val !== void 0 || showUndefined).every(([, val]) => {
95
- if (typeof val === "string") {
96
- return !val.includes("'") && !val.includes('"') && !val.includes("\\");
97
- }
98
- return typeof val === "number" || typeof val === "boolean" || val === null || val === void 0;
99
- }));
100
- const prevWasCollapsed = prevValue && isObject(prevValue) && (Object.keys(prevValue).length === 0 || collapseObjects && depth + 1 > 0 && Object.entries(prevValue).filter(([, val]) => val !== void 0 || showUndefined).every(([, val]) => {
101
- if (typeof val === "string") {
102
- return !val.includes("'") && !val.includes('"') && !val.includes("\\");
103
- }
104
- return typeof val === "number" || typeof val === "boolean" || val === null || val === void 0;
105
- }));
96
+ const willBeCollapsed = isObject(objVal) && (Object.keys(objVal).length === 0 || collapseObjects && depth + 1 > 0 && (() => {
97
+ const filteredEntries = Object.entries(objVal).filter(([, val]) => val !== void 0 || showUndefined);
98
+ const shouldCollapseThis = isArrayItem ? filteredEntries.length > 1 : filteredEntries.length > 0;
99
+ return shouldCollapseThis && filteredEntries.every(([, val]) => {
100
+ if (typeof val === "string") {
101
+ return !val.includes("'") && !val.includes('"') && !val.includes("\\");
102
+ }
103
+ return typeof val === "number" || typeof val === "boolean" || val === null || val === void 0;
104
+ });
105
+ })());
106
+ const prevWasCollapsed = prevValue && isObject(prevValue) && (Object.keys(prevValue).length === 0 || collapseObjects && depth + 1 > 0 && (() => {
107
+ const filteredEntries = Object.entries(prevValue).filter(([, val]) => val !== void 0 || showUndefined);
108
+ const shouldCollapseThis = isArrayItem ? filteredEntries.length > 1 : filteredEntries.length > 0;
109
+ return shouldCollapseThis && filteredEntries.every(([, val]) => {
110
+ if (typeof val === "string") {
111
+ return !val.includes("'") && !val.includes('"') && !val.includes("\\");
112
+ }
113
+ return typeof val === "number" || typeof val === "boolean" || val === null || val === void 0;
114
+ });
115
+ })());
106
116
  if (!afterSpaceWasAdded && indent === "" && isObject(objVal) && !willBeCollapsed && prevValue && !prevWasCollapsed && (addObjSpaces === "before" || addObjSpaces === "beforeAndAfter")) {
107
117
  result += "\n";
108
118
  }
@@ -165,7 +175,8 @@ function stringifyValue(value, indent, maxLineLength, showUndefined, maxDepth, d
165
175
  maxDepth,
166
176
  depth + 1,
167
177
  collapseObjects,
168
- addObjSpaces
178
+ addObjSpaces,
179
+ true
169
180
  );
170
181
  }).join(", ");
171
182
  line += "]";
@@ -189,7 +200,8 @@ function stringifyValue(value, indent, maxLineLength, showUndefined, maxDepth, d
189
200
  maxDepth,
190
201
  depth + 1,
191
202
  collapseObjects,
192
- addObjSpaces
203
+ addObjSpaces,
204
+ true
193
205
  );
194
206
  arrayString = arrayString.trimStart();
195
207
  result += arrayString;
@@ -202,7 +214,8 @@ function stringifyValue(value, indent, maxLineLength, showUndefined, maxDepth, d
202
214
  maxDepth,
203
215
  depth + 1,
204
216
  collapseObjects,
205
- addObjSpaces
217
+ addObjSpaces,
218
+ true
206
219
  );
207
220
  }
208
221
  result += "\n";
@@ -256,7 +269,8 @@ ${indent}${line}
256
269
  maxDepth,
257
270
  depth + 1,
258
271
  collapseObjects,
259
- addObjSpaces
272
+ addObjSpaces,
273
+ false
260
274
  );
261
275
  }
262
276
  return JSON.stringify(value);