@ls-stack/utils 3.40.0 → 3.41.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/arrayUtils.d.cts +70 -57
- package/dist/arrayUtils.d.ts +70 -57
- package/dist/assertions.d.cts +128 -117
- package/dist/assertions.d.ts +128 -117
- package/dist/asyncQueue.cjs +117 -112
- package/dist/asyncQueue.d.cts +217 -215
- package/dist/asyncQueue.d.ts +217 -215
- package/dist/asyncQueue.js +117 -112
- package/dist/awaitDebounce.d.cts +26 -23
- package/dist/awaitDebounce.d.ts +26 -23
- package/dist/cache.cjs +2 -1
- package/dist/cache.d.cts +15 -9
- package/dist/cache.d.ts +15 -9
- package/dist/cache.js +2 -1
- package/dist/{chunk-GHAQOUA6.js → chunk-23KPGKDT.js} +22 -1
- package/dist/{chunk-ADM37GSC.js → chunk-7L4KCZJJ.js} +12 -10
- package/dist/{chunk-KW55OTUG.js → chunk-B3KFV2MH.js} +2 -2
- package/dist/chunk-DTE2QMWE.js +48 -0
- package/dist/concurrentCalls.d.cts +8 -4
- package/dist/concurrentCalls.d.ts +8 -4
- package/dist/concurrentCalls.js +1 -1
- package/dist/debounce.d.cts +12 -20
- package/dist/debounce.d.ts +12 -20
- package/dist/dedent.d.cts +31 -31
- package/dist/dedent.d.ts +31 -31
- package/dist/deepEqual.d.cts +10 -9
- package/dist/deepEqual.d.ts +10 -9
- package/dist/filterObjectOrArrayKeys.d.cts +44 -19
- package/dist/filterObjectOrArrayKeys.d.ts +44 -19
- package/dist/getAutoIncrementId.d.cts +25 -23
- package/dist/getAutoIncrementId.d.ts +25 -23
- package/dist/getCompositeKey.d.cts +2 -1
- package/dist/getCompositeKey.d.ts +2 -1
- package/dist/getValueStableKey.d.cts +4 -3
- package/dist/getValueStableKey.d.ts +4 -3
- package/dist/mutationUtils.d.cts +2 -2
- package/dist/mutationUtils.d.ts +2 -2
- package/dist/objUtils.cjs +51 -2
- package/dist/objUtils.d.cts +8 -3
- package/dist/objUtils.d.ts +8 -3
- package/dist/objUtils.js +11 -3
- package/dist/parallelAsyncCalls.cjs +2 -1
- package/dist/parallelAsyncCalls.d.cts +5 -4
- package/dist/parallelAsyncCalls.d.ts +5 -4
- package/dist/parallelAsyncCalls.js +2 -1
- package/dist/retryOnError.d.cts +23 -20
- package/dist/retryOnError.d.ts +23 -20
- package/dist/runShellCmd.d.cts +40 -40
- package/dist/runShellCmd.d.ts +40 -40
- package/dist/safeJson.d.cts +6 -2
- package/dist/safeJson.d.ts +6 -2
- package/dist/saferTyping.d.cts +21 -14
- package/dist/saferTyping.d.ts +21 -14
- package/dist/shallowEqual.d.cts +1 -1
- package/dist/shallowEqual.d.ts +1 -1
- package/dist/stringUtils.cjs +2 -2
- package/dist/stringUtils.d.cts +6 -7
- package/dist/stringUtils.d.ts +6 -7
- package/dist/stringUtils.js +1 -1
- package/dist/testUtils.cjs +11 -9
- package/dist/testUtils.d.cts +32 -14
- package/dist/testUtils.d.ts +32 -14
- package/dist/testUtils.js +4 -3
- package/dist/throttle.d.cts +57 -48
- package/dist/throttle.d.ts +57 -48
- package/dist/timers.d.cts +68 -63
- package/dist/timers.d.ts +68 -63
- package/dist/tsResult.d.cts +7 -6
- package/dist/tsResult.d.ts +7 -6
- package/dist/typeGuards.d.cts +65 -64
- package/dist/typeGuards.d.ts +65 -64
- package/dist/typeUtils.d.cts +18 -4
- package/dist/typeUtils.d.ts +18 -4
- package/dist/typedStrings.d.cts +68 -57
- package/dist/typedStrings.d.ts +68 -57
- package/dist/typingFnUtils.d.cts +12 -6
- package/dist/typingFnUtils.d.ts +12 -6
- package/dist/typingFnUtils.js +12 -35
- package/dist/typingTestUtils.cjs +7 -1
- package/dist/typingTestUtils.d.cts +52 -11
- package/dist/typingTestUtils.d.ts +52 -11
- package/dist/typingTestUtils.js +7 -1
- package/dist/typingUtils.d.cts +4 -1
- package/dist/typingUtils.d.ts +4 -1
- package/dist/yamlStringify.cjs +11 -9
- package/dist/yamlStringify.js +2 -2
- package/package.json +5 -1
- package/docs/README.md +0 -72
- package/docs/_media/modules.md +0 -58
- package/docs/arrayUtils/-internal-.md +0 -179
- package/docs/arrayUtils/README.md +0 -550
- package/docs/assertions/-internal-.md +0 -63
- package/docs/assertions/README.md +0 -565
- package/docs/asyncQueue/-internal-.md +0 -297
- package/docs/asyncQueue/README.md +0 -1485
- package/docs/awaitDebounce.md +0 -66
- package/docs/cache/-internal-.md +0 -168
- package/docs/cache/README.md +0 -360
- package/docs/castValues.md +0 -47
- package/docs/concurrentCalls/-internal-.md +0 -490
- package/docs/concurrentCalls/README.md +0 -299
- package/docs/consoleFmt.md +0 -115
- package/docs/conversions.md +0 -27
- package/docs/createThrottleController/-internal-.md +0 -73
- package/docs/createThrottleController/README.md +0 -31
- package/docs/debounce.md +0 -188
- package/docs/dedent/-internal-.md +0 -17
- package/docs/dedent/README.md +0 -204
- package/docs/deepEqual.md +0 -94
- package/docs/enhancedMap.md +0 -358
- package/docs/exhaustiveMatch/-internal-.md +0 -39
- package/docs/exhaustiveMatch/README.md +0 -146
- package/docs/filterObjectOrArrayKeys.md +0 -109
- package/docs/getAutoIncrementId.md +0 -93
- package/docs/getCompositeKey.md +0 -39
- package/docs/getValueStableKey.md +0 -57
- package/docs/hash.md +0 -31
- package/docs/interpolate/-internal-.md +0 -61
- package/docs/interpolate/README.md +0 -62
- package/docs/keepPrevIfUnchanged.md +0 -43
- package/docs/levenshtein.md +0 -93
- package/docs/main.md +0 -21
- package/docs/mathUtils.md +0 -137
- package/docs/modules.md +0 -58
- package/docs/mutationUtils.md +0 -44
- package/docs/objUtils.md +0 -237
- package/docs/parallelAsyncCalls/-internal-.md +0 -347
- package/docs/parallelAsyncCalls/README.md +0 -45
- package/docs/promiseUtils/-internal-.md +0 -69
- package/docs/promiseUtils/README.md +0 -31
- package/docs/retryOnError/-internal-.md +0 -111
- package/docs/retryOnError/README.md +0 -168
- package/docs/runShellCmd/-internal-.md +0 -111
- package/docs/runShellCmd/README.md +0 -201
- package/docs/safeJson.md +0 -51
- package/docs/saferTyping.md +0 -228
- package/docs/serializeXML.md +0 -100
- package/docs/shallowEqual.md +0 -33
- package/docs/sleep.md +0 -27
- package/docs/stringUtils/-internal-.md +0 -17
- package/docs/stringUtils/README.md +0 -270
- package/docs/testUtils.md +0 -382
- package/docs/throttle/-internal-.md +0 -47
- package/docs/throttle/README.md +0 -178
- package/docs/time.md +0 -274
- package/docs/timers.md +0 -256
- package/docs/tsResult/-internal-.md +0 -327
- package/docs/tsResult/README.md +0 -702
- package/docs/typeGuards.md +0 -399
- package/docs/typeUtils/-internal-.md +0 -99
- package/docs/typeUtils/README.md +0 -195
- package/docs/typeUtils.typesTest.md +0 -7
- package/docs/typedStrings.md +0 -458
- package/docs/typingFnUtils/-internal-.md +0 -43
- package/docs/typingFnUtils/README.md +0 -317
- package/docs/typingTestUtils.md +0 -172
- package/docs/typingUtils.md +0 -135
- package/docs/yamlStringify.md +0 -83
package/dist/arrayUtils.d.cts
CHANGED
|
@@ -1,27 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Allow to filter and map with better typing ergonomics
|
|
3
3
|
*
|
|
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
|
|
9
7
|
* @example
|
|
10
|
-
*
|
|
11
|
-
*
|
|
8
|
+
* // Filter reject and turn value into `value mapped`
|
|
9
|
+
* const items = ['value', 'value', 'reject', 'reject'];
|
|
10
|
+
*
|
|
11
|
+
* const mappedItems = filterAndMap(items, (item) =>
|
|
12
|
+
* item === 'reject' ? false : `${item} mapped`,
|
|
13
|
+
* );
|
|
12
14
|
*
|
|
13
|
-
*
|
|
14
|
-
* item === 'reject'
|
|
15
|
-
* ? false
|
|
16
|
-
* : `${item} mapped`,
|
|
17
|
-
* );
|
|
15
|
+
* mappedItems; // ['value mapped', 'value mapped']
|
|
18
16
|
*
|
|
19
|
-
*
|
|
17
|
+
* @param array
|
|
18
|
+
* @param mapFilter
|
|
20
19
|
*/
|
|
21
20
|
declare function filterAndMap<T, R>(array: IterableIterator<T> | readonly T[], mapFilter: (item: T, index: number) => false | R): R[];
|
|
22
21
|
type FilterAndMapReturn<T> = false | T;
|
|
23
22
|
type SortOrder = 'desc' | 'asc';
|
|
24
|
-
type
|
|
23
|
+
type SortByValueFn<T> = (item: T) => (number | string)[] | number | string;
|
|
25
24
|
type SortByProps = {
|
|
26
25
|
order?: SortOrder | SortOrder[];
|
|
27
26
|
} | SortOrder | SortOrder[];
|
|
@@ -32,37 +31,42 @@ type SortByProps = {
|
|
|
32
31
|
*
|
|
33
32
|
* Use `Infinity` as as wildcard to absolute max and min values
|
|
34
33
|
*
|
|
35
|
-
* @param arr
|
|
36
|
-
* @param sortByValue
|
|
37
|
-
* @param props
|
|
38
34
|
* @example
|
|
39
|
-
*
|
|
35
|
+
* const items = [1, 3, 2, 4];
|
|
36
|
+
*
|
|
37
|
+
* const sortedItems = sortBy(items, (item) => item);
|
|
38
|
+
* // [1, 2, 3, 4]
|
|
40
39
|
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
40
|
+
* const items2 = [
|
|
41
|
+
* { a: 1, b: 2 },
|
|
42
|
+
* { a: 2, b: 1 },
|
|
43
|
+
* { a: 1, b: 1 },
|
|
44
|
+
* ];
|
|
43
45
|
*
|
|
44
|
-
*
|
|
46
|
+
* // return a array to sort by multiple values
|
|
47
|
+
* const sortedItems = sortBy(items, (item) => [item.a, item.b]);
|
|
45
48
|
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
49
|
+
* @param arr
|
|
50
|
+
* @param sortByValue
|
|
51
|
+
* @param props
|
|
48
52
|
*/
|
|
49
|
-
declare function sortBy<T>(arr: T[], sortByValue:
|
|
53
|
+
declare function sortBy<T>(arr: T[], sortByValue: SortByValueFn<T>, props?: SortByProps): T[];
|
|
50
54
|
/**
|
|
51
55
|
* Get the correct 0 based value for sync with other array in ascending order
|
|
52
56
|
*
|
|
53
|
-
* @param index
|
|
54
|
-
*
|
|
55
57
|
* @example
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
58
|
+
* ```ts
|
|
59
|
+
* const items = [1, 2, 3];
|
|
60
|
+
*
|
|
61
|
+
* const index = sortBy(
|
|
62
|
+
* items,
|
|
63
|
+
* (item) => getAscIndexOrder(
|
|
64
|
+
* followOrder.findIndex((order) => order === item)
|
|
65
|
+
* )
|
|
66
|
+
* );
|
|
67
|
+
* ```;
|
|
68
|
+
*
|
|
69
|
+
* @param index
|
|
66
70
|
*/
|
|
67
71
|
declare function getAscIndexOrder(index: number | undefined): number;
|
|
68
72
|
declare function arrayWithPrev<T>(array: T[]): [current: T, prev: T | null][];
|
|
@@ -82,50 +86,59 @@ type ArrayOps<T> = {
|
|
|
82
86
|
/**
|
|
83
87
|
* Filter and map an array
|
|
84
88
|
*
|
|
85
|
-
* @param mapFilter - A function that takes an item and returns a value or `false`
|
|
86
|
-
* to reject the item.
|
|
87
89
|
* @example
|
|
88
|
-
*
|
|
90
|
+
* const items = [1, 2, 3];
|
|
91
|
+
*
|
|
92
|
+
* const enhancedItems = arrayOps(items);
|
|
89
93
|
*
|
|
90
|
-
*
|
|
94
|
+
* enhancedItems.filterAndMap((item) => (item === 2 ? false : item));
|
|
91
95
|
*
|
|
92
|
-
*
|
|
96
|
+
* @param mapFilter - A function that takes an item and returns a value or
|
|
97
|
+
* `false` to reject the item.
|
|
93
98
|
*/
|
|
94
99
|
filterAndMap: <R>(mapFilter: (item: T, index: number) => false | R) => R[];
|
|
95
|
-
sortBy: (sortByValue:
|
|
100
|
+
sortBy: (sortByValue: SortByValueFn<T>, props: SortByProps) => T[];
|
|
96
101
|
rejectDuplicates: (getKey: (item: T) => unknown) => T[];
|
|
97
102
|
findAndMap: <R>(predicate: (value: T) => R | false) => R | undefined;
|
|
98
103
|
};
|
|
99
104
|
/**
|
|
100
|
-
* Finds the first item in an array where the predicate returns a non-false
|
|
105
|
+
* Finds the first item in an array where the predicate returns a non-false
|
|
106
|
+
* value and returns that mapped value.
|
|
101
107
|
*
|
|
102
|
-
* Combines find and map operations - applies the predicate to each item until
|
|
103
|
-
* a value that is not `false`, then returns that mapped value. If
|
|
108
|
+
* Combines find and map operations - applies the predicate to each item until
|
|
109
|
+
* one returns a value that is not `false`, then returns that mapped value. If
|
|
110
|
+
* no item matches, returns `undefined`.
|
|
104
111
|
*
|
|
105
|
-
* @param array - The array to search through
|
|
106
|
-
* @param predicate - Function that returns a mapped value or `false` to skip the item
|
|
107
|
-
* @returns The first mapped value that is not `false`, or `undefined` if no item matches
|
|
108
112
|
* @example
|
|
109
|
-
*
|
|
113
|
+
* const users = [
|
|
114
|
+
* { id: 1, name: 'Alice' },
|
|
115
|
+
* { id: 2, name: 'Bob' },
|
|
116
|
+
* ];
|
|
117
|
+
*
|
|
118
|
+
* const foundName = findAndMap(users, (user) =>
|
|
119
|
+
* user.id === 2 ? user.name.toUpperCase() : false,
|
|
120
|
+
* );
|
|
121
|
+
* // foundName is 'BOB'
|
|
110
122
|
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
123
|
+
* @param array - The array to search through
|
|
124
|
+
* @param predicate - Function that returns a mapped value or `false` to skip
|
|
125
|
+
* the item
|
|
126
|
+
* @returns The first mapped value that is not `false`, or `undefined` if no
|
|
127
|
+
* item matches
|
|
115
128
|
*/
|
|
116
129
|
declare function findAndMap<T, R>(array: T[], predicate: (value: T) => R | false): R | undefined;
|
|
117
130
|
/**
|
|
118
131
|
* Enhance an array with extra methods
|
|
119
132
|
*
|
|
120
|
-
* @param array
|
|
121
133
|
* @example
|
|
134
|
+
* const enhancedItems = arrayOps(array);
|
|
122
135
|
*
|
|
123
|
-
*
|
|
136
|
+
* enhancedItems.filterAndMap((item) => (item === 2 ? false : item));
|
|
137
|
+
* enhancedItems.sortBy((item) => item);
|
|
138
|
+
* enhancedItems.rejectDuplicates((item) => item);
|
|
124
139
|
*
|
|
125
|
-
*
|
|
126
|
-
* enhancedItems.sortBy((item) => item);
|
|
127
|
-
* enhancedItems.rejectDuplicates((item) => item);
|
|
140
|
+
* @param array
|
|
128
141
|
*/
|
|
129
142
|
declare function arrayOps<T>(array: T[]): ArrayOps<T>;
|
|
130
143
|
|
|
131
|
-
export { type FilterAndMapReturn, arrayOps, arrayWithPrev, arrayWithPrevAndIndex, filterAndMap, findAfterIndex, findAndMap, findBeforeIndex, getAscIndexOrder, hasDuplicates, isInArray, rejectArrayUndefinedValues, rejectDuplicates, sortBy, truncateArray };
|
|
144
|
+
export { type FilterAndMapReturn, type SortByProps, type SortByValueFn, arrayOps, arrayWithPrev, arrayWithPrevAndIndex, filterAndMap, findAfterIndex, findAndMap, findBeforeIndex, getAscIndexOrder, hasDuplicates, isInArray, rejectArrayUndefinedValues, rejectDuplicates, sortBy, truncateArray };
|
package/dist/arrayUtils.d.ts
CHANGED
|
@@ -1,27 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Allow to filter and map with better typing ergonomics
|
|
3
3
|
*
|
|
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
|
|
9
7
|
* @example
|
|
10
|
-
*
|
|
11
|
-
*
|
|
8
|
+
* // Filter reject and turn value into `value mapped`
|
|
9
|
+
* const items = ['value', 'value', 'reject', 'reject'];
|
|
10
|
+
*
|
|
11
|
+
* const mappedItems = filterAndMap(items, (item) =>
|
|
12
|
+
* item === 'reject' ? false : `${item} mapped`,
|
|
13
|
+
* );
|
|
12
14
|
*
|
|
13
|
-
*
|
|
14
|
-
* item === 'reject'
|
|
15
|
-
* ? false
|
|
16
|
-
* : `${item} mapped`,
|
|
17
|
-
* );
|
|
15
|
+
* mappedItems; // ['value mapped', 'value mapped']
|
|
18
16
|
*
|
|
19
|
-
*
|
|
17
|
+
* @param array
|
|
18
|
+
* @param mapFilter
|
|
20
19
|
*/
|
|
21
20
|
declare function filterAndMap<T, R>(array: IterableIterator<T> | readonly T[], mapFilter: (item: T, index: number) => false | R): R[];
|
|
22
21
|
type FilterAndMapReturn<T> = false | T;
|
|
23
22
|
type SortOrder = 'desc' | 'asc';
|
|
24
|
-
type
|
|
23
|
+
type SortByValueFn<T> = (item: T) => (number | string)[] | number | string;
|
|
25
24
|
type SortByProps = {
|
|
26
25
|
order?: SortOrder | SortOrder[];
|
|
27
26
|
} | SortOrder | SortOrder[];
|
|
@@ -32,37 +31,42 @@ type SortByProps = {
|
|
|
32
31
|
*
|
|
33
32
|
* Use `Infinity` as as wildcard to absolute max and min values
|
|
34
33
|
*
|
|
35
|
-
* @param arr
|
|
36
|
-
* @param sortByValue
|
|
37
|
-
* @param props
|
|
38
34
|
* @example
|
|
39
|
-
*
|
|
35
|
+
* const items = [1, 3, 2, 4];
|
|
36
|
+
*
|
|
37
|
+
* const sortedItems = sortBy(items, (item) => item);
|
|
38
|
+
* // [1, 2, 3, 4]
|
|
40
39
|
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
40
|
+
* const items2 = [
|
|
41
|
+
* { a: 1, b: 2 },
|
|
42
|
+
* { a: 2, b: 1 },
|
|
43
|
+
* { a: 1, b: 1 },
|
|
44
|
+
* ];
|
|
43
45
|
*
|
|
44
|
-
*
|
|
46
|
+
* // return a array to sort by multiple values
|
|
47
|
+
* const sortedItems = sortBy(items, (item) => [item.a, item.b]);
|
|
45
48
|
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
49
|
+
* @param arr
|
|
50
|
+
* @param sortByValue
|
|
51
|
+
* @param props
|
|
48
52
|
*/
|
|
49
|
-
declare function sortBy<T>(arr: T[], sortByValue:
|
|
53
|
+
declare function sortBy<T>(arr: T[], sortByValue: SortByValueFn<T>, props?: SortByProps): T[];
|
|
50
54
|
/**
|
|
51
55
|
* Get the correct 0 based value for sync with other array in ascending order
|
|
52
56
|
*
|
|
53
|
-
* @param index
|
|
54
|
-
*
|
|
55
57
|
* @example
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
58
|
+
* ```ts
|
|
59
|
+
* const items = [1, 2, 3];
|
|
60
|
+
*
|
|
61
|
+
* const index = sortBy(
|
|
62
|
+
* items,
|
|
63
|
+
* (item) => getAscIndexOrder(
|
|
64
|
+
* followOrder.findIndex((order) => order === item)
|
|
65
|
+
* )
|
|
66
|
+
* );
|
|
67
|
+
* ```;
|
|
68
|
+
*
|
|
69
|
+
* @param index
|
|
66
70
|
*/
|
|
67
71
|
declare function getAscIndexOrder(index: number | undefined): number;
|
|
68
72
|
declare function arrayWithPrev<T>(array: T[]): [current: T, prev: T | null][];
|
|
@@ -82,50 +86,59 @@ type ArrayOps<T> = {
|
|
|
82
86
|
/**
|
|
83
87
|
* Filter and map an array
|
|
84
88
|
*
|
|
85
|
-
* @param mapFilter - A function that takes an item and returns a value or `false`
|
|
86
|
-
* to reject the item.
|
|
87
89
|
* @example
|
|
88
|
-
*
|
|
90
|
+
* const items = [1, 2, 3];
|
|
91
|
+
*
|
|
92
|
+
* const enhancedItems = arrayOps(items);
|
|
89
93
|
*
|
|
90
|
-
*
|
|
94
|
+
* enhancedItems.filterAndMap((item) => (item === 2 ? false : item));
|
|
91
95
|
*
|
|
92
|
-
*
|
|
96
|
+
* @param mapFilter - A function that takes an item and returns a value or
|
|
97
|
+
* `false` to reject the item.
|
|
93
98
|
*/
|
|
94
99
|
filterAndMap: <R>(mapFilter: (item: T, index: number) => false | R) => R[];
|
|
95
|
-
sortBy: (sortByValue:
|
|
100
|
+
sortBy: (sortByValue: SortByValueFn<T>, props: SortByProps) => T[];
|
|
96
101
|
rejectDuplicates: (getKey: (item: T) => unknown) => T[];
|
|
97
102
|
findAndMap: <R>(predicate: (value: T) => R | false) => R | undefined;
|
|
98
103
|
};
|
|
99
104
|
/**
|
|
100
|
-
* Finds the first item in an array where the predicate returns a non-false
|
|
105
|
+
* Finds the first item in an array where the predicate returns a non-false
|
|
106
|
+
* value and returns that mapped value.
|
|
101
107
|
*
|
|
102
|
-
* Combines find and map operations - applies the predicate to each item until
|
|
103
|
-
* a value that is not `false`, then returns that mapped value. If
|
|
108
|
+
* Combines find and map operations - applies the predicate to each item until
|
|
109
|
+
* one returns a value that is not `false`, then returns that mapped value. If
|
|
110
|
+
* no item matches, returns `undefined`.
|
|
104
111
|
*
|
|
105
|
-
* @param array - The array to search through
|
|
106
|
-
* @param predicate - Function that returns a mapped value or `false` to skip the item
|
|
107
|
-
* @returns The first mapped value that is not `false`, or `undefined` if no item matches
|
|
108
112
|
* @example
|
|
109
|
-
*
|
|
113
|
+
* const users = [
|
|
114
|
+
* { id: 1, name: 'Alice' },
|
|
115
|
+
* { id: 2, name: 'Bob' },
|
|
116
|
+
* ];
|
|
117
|
+
*
|
|
118
|
+
* const foundName = findAndMap(users, (user) =>
|
|
119
|
+
* user.id === 2 ? user.name.toUpperCase() : false,
|
|
120
|
+
* );
|
|
121
|
+
* // foundName is 'BOB'
|
|
110
122
|
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
123
|
+
* @param array - The array to search through
|
|
124
|
+
* @param predicate - Function that returns a mapped value or `false` to skip
|
|
125
|
+
* the item
|
|
126
|
+
* @returns The first mapped value that is not `false`, or `undefined` if no
|
|
127
|
+
* item matches
|
|
115
128
|
*/
|
|
116
129
|
declare function findAndMap<T, R>(array: T[], predicate: (value: T) => R | false): R | undefined;
|
|
117
130
|
/**
|
|
118
131
|
* Enhance an array with extra methods
|
|
119
132
|
*
|
|
120
|
-
* @param array
|
|
121
133
|
* @example
|
|
134
|
+
* const enhancedItems = arrayOps(array);
|
|
122
135
|
*
|
|
123
|
-
*
|
|
136
|
+
* enhancedItems.filterAndMap((item) => (item === 2 ? false : item));
|
|
137
|
+
* enhancedItems.sortBy((item) => item);
|
|
138
|
+
* enhancedItems.rejectDuplicates((item) => item);
|
|
124
139
|
*
|
|
125
|
-
*
|
|
126
|
-
* enhancedItems.sortBy((item) => item);
|
|
127
|
-
* enhancedItems.rejectDuplicates((item) => item);
|
|
140
|
+
* @param array
|
|
128
141
|
*/
|
|
129
142
|
declare function arrayOps<T>(array: T[]): ArrayOps<T>;
|
|
130
143
|
|
|
131
|
-
export { type FilterAndMapReturn, arrayOps, arrayWithPrev, arrayWithPrevAndIndex, filterAndMap, findAfterIndex, findAndMap, findBeforeIndex, getAscIndexOrder, hasDuplicates, isInArray, rejectArrayUndefinedValues, rejectDuplicates, sortBy, truncateArray };
|
|
144
|
+
export { type FilterAndMapReturn, type SortByProps, type SortByValueFn, arrayOps, arrayWithPrev, arrayWithPrevAndIndex, filterAndMap, findAfterIndex, findAndMap, findBeforeIndex, getAscIndexOrder, hasDuplicates, isInArray, rejectArrayUndefinedValues, rejectDuplicates, sortBy, truncateArray };
|