@ls-stack/utils 3.24.0 → 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.
- package/docs/_media/modules.md +1 -0
- package/docs/arrayUtils/-internal-.md +1 -1
- package/docs/arrayUtils/README.md +12 -12
- package/docs/consoleFmt.md +2 -2
- package/docs/exhaustiveMatch/-internal-.md +1 -1
- package/docs/exhaustiveMatch/README.md +1 -1
- package/docs/filterObjectOrArrayKeys.md +80 -0
- package/docs/modules.md +1 -0
- package/docs/objUtils.md +7 -7
- package/docs/parallelAsyncCalls/-internal-.md +3 -3
- package/docs/parallelAsyncCalls/README.md +1 -1
- package/docs/retryOnError/README.md +1 -1
- package/docs/runShellCmd/README.md +9 -9
- package/docs/safeJson.md +2 -2
- package/docs/saferTyping.md +7 -7
- package/docs/stringUtils/README.md +6 -6
- package/docs/testUtils.md +40 -6
- package/docs/time.md +1 -1
- package/docs/tsResult/README.md +17 -11
- package/docs/typingFnUtils/-internal-.md +1 -1
- package/docs/typingFnUtils/README.md +8 -10
- package/lib/arrayUtils.d.cts +6 -1
- package/lib/arrayUtils.d.ts +6 -1
- package/lib/{chunk-JAPKLFIK.js → chunk-QLD7KG5I.js} +34 -20
- package/lib/chunk-XXYTMSFH.js +240 -0
- package/lib/filterObjectOrArrayKeys.cjs +275 -0
- package/lib/filterObjectOrArrayKeys.d.cts +42 -0
- package/lib/filterObjectOrArrayKeys.d.ts +42 -0
- package/lib/filterObjectOrArrayKeys.js +7 -0
- package/lib/objUtils.d.cts +4 -1
- package/lib/objUtils.d.ts +4 -1
- package/lib/parallelAsyncCalls.cjs +4 -1
- package/lib/parallelAsyncCalls.d.cts +4 -1
- package/lib/parallelAsyncCalls.d.ts +4 -1
- package/lib/parallelAsyncCalls.js +4 -1
- package/lib/retryOnError.d.cts +2 -0
- package/lib/retryOnError.d.ts +2 -0
- package/lib/runShellCmd.d.cts +17 -0
- package/lib/runShellCmd.d.ts +17 -0
- package/lib/safeJson.d.cts +8 -2
- package/lib/safeJson.d.ts +8 -2
- package/lib/saferTyping.d.cts +3 -0
- package/lib/saferTyping.d.ts +3 -0
- package/lib/stringUtils.d.cts +1 -0
- package/lib/stringUtils.d.ts +1 -0
- package/lib/testUtils.cjs +273 -106
- package/lib/testUtils.d.cts +81 -2
- package/lib/testUtils.d.ts +81 -2
- package/lib/testUtils.js +10 -87
- package/lib/tsResult.d.cts +31 -7
- package/lib/tsResult.d.ts +31 -7
- package/lib/typingFnUtils.d.cts +20 -6
- package/lib/typingFnUtils.d.ts +20 -6
- package/lib/yamlStringify.cjs +34 -20
- package/lib/yamlStringify.js +1 -1
- 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,
|
|
14
|
+
function compactSnapshot(value, options): string;
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
-
Defined in: [packages/utils/src/testUtils.ts:
|
|
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:439](https://github.com/lucasols/ut
|
|
|
22
50
|
|
|
23
51
|
`unknown`
|
|
24
52
|
|
|
25
|
-
|
|
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:439](https://github.com/lucasols/ut
|
|
|
38
72
|
function createLoggerStore(__namedParameters): object;
|
|
39
73
|
```
|
|
40
74
|
|
|
41
|
-
Defined in: [packages/utils/src/testUtils.ts:
|
|
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:
|
|
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:
|
|
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
package/docs/tsResult/README.md
CHANGED
|
@@ -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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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
|
package/lib/arrayUtils.d.cts
CHANGED
|
@@ -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[];
|
package/lib/arrayUtils.d.ts
CHANGED
|
@@ -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
|
-
|
|
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 &&
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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);
|