@ls-stack/utils 3.40.0 → 3.42.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 (159) hide show
  1. package/dist/arrayUtils.d.cts +70 -57
  2. package/dist/arrayUtils.d.ts +70 -57
  3. package/dist/assertions.d.cts +128 -117
  4. package/dist/assertions.d.ts +128 -117
  5. package/dist/asyncQueue.cjs +117 -112
  6. package/dist/asyncQueue.d.cts +217 -215
  7. package/dist/asyncQueue.d.ts +217 -215
  8. package/dist/asyncQueue.js +117 -112
  9. package/dist/awaitDebounce.d.cts +26 -23
  10. package/dist/awaitDebounce.d.ts +26 -23
  11. package/dist/cache.cjs +2 -1
  12. package/dist/cache.d.cts +15 -9
  13. package/dist/cache.d.ts +15 -9
  14. package/dist/cache.js +2 -1
  15. package/dist/{chunk-ADM37GSC.js → chunk-7L4KCZJJ.js} +12 -10
  16. package/dist/{chunk-KW55OTUG.js → chunk-B3KFV2MH.js} +2 -2
  17. package/dist/chunk-GMJTLFM6.js +60 -0
  18. package/dist/{chunk-GHAQOUA6.js → chunk-Y45CE75W.js} +22 -1
  19. package/dist/concurrentCalls.d.cts +8 -4
  20. package/dist/concurrentCalls.d.ts +8 -4
  21. package/dist/concurrentCalls.js +1 -1
  22. package/dist/debounce.d.cts +12 -20
  23. package/dist/debounce.d.ts +12 -20
  24. package/dist/dedent.d.cts +31 -31
  25. package/dist/dedent.d.ts +31 -31
  26. package/dist/deepEqual.d.cts +10 -9
  27. package/dist/deepEqual.d.ts +10 -9
  28. package/dist/filterObjectOrArrayKeys.d.cts +44 -19
  29. package/dist/filterObjectOrArrayKeys.d.ts +44 -19
  30. package/dist/getAutoIncrementId.d.cts +25 -23
  31. package/dist/getAutoIncrementId.d.ts +25 -23
  32. package/dist/getCompositeKey.d.cts +2 -1
  33. package/dist/getCompositeKey.d.ts +2 -1
  34. package/dist/getValueStableKey.d.cts +4 -3
  35. package/dist/getValueStableKey.d.ts +4 -3
  36. package/dist/mutationUtils.d.cts +2 -2
  37. package/dist/mutationUtils.d.ts +2 -2
  38. package/dist/objUtils.cjs +51 -2
  39. package/dist/objUtils.d.cts +8 -3
  40. package/dist/objUtils.d.ts +8 -3
  41. package/dist/objUtils.js +11 -3
  42. package/dist/parallelAsyncCalls.cjs +2 -1
  43. package/dist/parallelAsyncCalls.d.cts +5 -4
  44. package/dist/parallelAsyncCalls.d.ts +5 -4
  45. package/dist/parallelAsyncCalls.js +2 -1
  46. package/dist/retryOnError.d.cts +23 -20
  47. package/dist/retryOnError.d.ts +23 -20
  48. package/dist/runShellCmd.d.cts +40 -40
  49. package/dist/runShellCmd.d.ts +40 -40
  50. package/dist/safeJson.d.cts +6 -2
  51. package/dist/safeJson.d.ts +6 -2
  52. package/dist/saferTyping.d.cts +21 -14
  53. package/dist/saferTyping.d.ts +21 -14
  54. package/dist/shallowEqual.d.cts +1 -1
  55. package/dist/shallowEqual.d.ts +1 -1
  56. package/dist/stringUtils.cjs +2 -2
  57. package/dist/stringUtils.d.cts +6 -7
  58. package/dist/stringUtils.d.ts +6 -7
  59. package/dist/stringUtils.js +1 -1
  60. package/dist/testUtils.cjs +11 -9
  61. package/dist/testUtils.d.cts +32 -14
  62. package/dist/testUtils.d.ts +32 -14
  63. package/dist/testUtils.js +4 -3
  64. package/dist/throttle.d.cts +57 -48
  65. package/dist/throttle.d.ts +57 -48
  66. package/dist/timers.d.cts +68 -63
  67. package/dist/timers.d.ts +68 -63
  68. package/dist/tsResult.d.cts +7 -6
  69. package/dist/tsResult.d.ts +7 -6
  70. package/dist/typeGuards.d.cts +65 -64
  71. package/dist/typeGuards.d.ts +65 -64
  72. package/dist/typeUtils.d.cts +18 -4
  73. package/dist/typeUtils.d.ts +18 -4
  74. package/dist/typedStrings.d.cts +68 -57
  75. package/dist/typedStrings.d.ts +68 -57
  76. package/dist/typingFnUtils.cjs +15 -0
  77. package/dist/typingFnUtils.d.cts +34 -7
  78. package/dist/typingFnUtils.d.ts +34 -7
  79. package/dist/typingFnUtils.js +18 -35
  80. package/dist/typingTestUtils.cjs +7 -1
  81. package/dist/typingTestUtils.d.cts +52 -11
  82. package/dist/typingTestUtils.d.ts +52 -11
  83. package/dist/typingTestUtils.js +7 -1
  84. package/dist/typingUtils.d.cts +4 -1
  85. package/dist/typingUtils.d.ts +4 -1
  86. package/dist/yamlStringify.cjs +11 -9
  87. package/dist/yamlStringify.js +2 -2
  88. package/package.json +5 -1
  89. package/docs/README.md +0 -72
  90. package/docs/_media/modules.md +0 -58
  91. package/docs/arrayUtils/-internal-.md +0 -179
  92. package/docs/arrayUtils/README.md +0 -550
  93. package/docs/assertions/-internal-.md +0 -63
  94. package/docs/assertions/README.md +0 -565
  95. package/docs/asyncQueue/-internal-.md +0 -297
  96. package/docs/asyncQueue/README.md +0 -1485
  97. package/docs/awaitDebounce.md +0 -66
  98. package/docs/cache/-internal-.md +0 -168
  99. package/docs/cache/README.md +0 -360
  100. package/docs/castValues.md +0 -47
  101. package/docs/concurrentCalls/-internal-.md +0 -490
  102. package/docs/concurrentCalls/README.md +0 -299
  103. package/docs/consoleFmt.md +0 -115
  104. package/docs/conversions.md +0 -27
  105. package/docs/createThrottleController/-internal-.md +0 -73
  106. package/docs/createThrottleController/README.md +0 -31
  107. package/docs/debounce.md +0 -188
  108. package/docs/dedent/-internal-.md +0 -17
  109. package/docs/dedent/README.md +0 -204
  110. package/docs/deepEqual.md +0 -94
  111. package/docs/enhancedMap.md +0 -358
  112. package/docs/exhaustiveMatch/-internal-.md +0 -39
  113. package/docs/exhaustiveMatch/README.md +0 -146
  114. package/docs/filterObjectOrArrayKeys.md +0 -109
  115. package/docs/getAutoIncrementId.md +0 -93
  116. package/docs/getCompositeKey.md +0 -39
  117. package/docs/getValueStableKey.md +0 -57
  118. package/docs/hash.md +0 -31
  119. package/docs/interpolate/-internal-.md +0 -61
  120. package/docs/interpolate/README.md +0 -62
  121. package/docs/keepPrevIfUnchanged.md +0 -43
  122. package/docs/levenshtein.md +0 -93
  123. package/docs/main.md +0 -21
  124. package/docs/mathUtils.md +0 -137
  125. package/docs/modules.md +0 -58
  126. package/docs/mutationUtils.md +0 -44
  127. package/docs/objUtils.md +0 -237
  128. package/docs/parallelAsyncCalls/-internal-.md +0 -347
  129. package/docs/parallelAsyncCalls/README.md +0 -45
  130. package/docs/promiseUtils/-internal-.md +0 -69
  131. package/docs/promiseUtils/README.md +0 -31
  132. package/docs/retryOnError/-internal-.md +0 -111
  133. package/docs/retryOnError/README.md +0 -168
  134. package/docs/runShellCmd/-internal-.md +0 -111
  135. package/docs/runShellCmd/README.md +0 -201
  136. package/docs/safeJson.md +0 -51
  137. package/docs/saferTyping.md +0 -228
  138. package/docs/serializeXML.md +0 -100
  139. package/docs/shallowEqual.md +0 -33
  140. package/docs/sleep.md +0 -27
  141. package/docs/stringUtils/-internal-.md +0 -17
  142. package/docs/stringUtils/README.md +0 -270
  143. package/docs/testUtils.md +0 -382
  144. package/docs/throttle/-internal-.md +0 -47
  145. package/docs/throttle/README.md +0 -178
  146. package/docs/time.md +0 -274
  147. package/docs/timers.md +0 -256
  148. package/docs/tsResult/-internal-.md +0 -327
  149. package/docs/tsResult/README.md +0 -702
  150. package/docs/typeGuards.md +0 -399
  151. package/docs/typeUtils/-internal-.md +0 -99
  152. package/docs/typeUtils/README.md +0 -195
  153. package/docs/typeUtils.typesTest.md +0 -7
  154. package/docs/typedStrings.md +0 -458
  155. package/docs/typingFnUtils/-internal-.md +0 -43
  156. package/docs/typingFnUtils/README.md +0 -317
  157. package/docs/typingTestUtils.md +0 -172
  158. package/docs/typingUtils.md +0 -135
  159. package/docs/yamlStringify.md +0 -83
@@ -1,179 +0,0 @@
1
- [**@ls-stack/utils**](../README.md)
2
-
3
- ***
4
-
5
- [@ls-stack/utils](../modules.md) / [arrayUtils](README.md) / \<internal\>
6
-
7
- # \<internal\>
8
-
9
- ## Type Aliases
10
-
11
- ### ArrayOps\<T\>
12
-
13
- ```ts
14
- type ArrayOps<T> = object;
15
- ```
16
-
17
- Defined in: [packages/utils/src/arrayUtils.ts:259](https://github.com/lucasols/utils/blob/main/packages/utils/src/arrayUtils.ts#L259)
18
-
19
- #### Type Parameters
20
-
21
- ##### T
22
-
23
- `T`
24
-
25
- #### Properties
26
-
27
- ##### filterAndMap()
28
-
29
- ```ts
30
- filterAndMap: <R>(mapFilter) => R[];
31
- ```
32
-
33
- Defined in: [packages/utils/src/arrayUtils.ts:272](https://github.com/lucasols/utils/blob/main/packages/utils/src/arrayUtils.ts#L272)
34
-
35
- Filter and map an array
36
-
37
- ###### Type Parameters
38
-
39
- ###### R
40
-
41
- `R`
42
-
43
- ###### Parameters
44
-
45
- ###### mapFilter
46
-
47
- (`item`, `index`) => `false` \| `R`
48
-
49
- A function that takes an item and returns a value or `false`
50
- to reject the item.
51
-
52
- ###### Returns
53
-
54
- `R`[]
55
-
56
- ###### Example
57
-
58
- ```ts
59
- const items = [1, 2, 3];
60
-
61
- const enhancedItems = arrayOps(items);
62
-
63
- enhancedItems.filterAndMap((item) => item === 2 ? false : item);
64
- ```
65
-
66
- ##### findAndMap()
67
-
68
- ```ts
69
- findAndMap: <R>(predicate) => R | undefined;
70
- ```
71
-
72
- Defined in: [packages/utils/src/arrayUtils.ts:275](https://github.com/lucasols/utils/blob/main/packages/utils/src/arrayUtils.ts#L275)
73
-
74
- ###### Type Parameters
75
-
76
- ###### R
77
-
78
- `R`
79
-
80
- ###### Parameters
81
-
82
- ###### predicate
83
-
84
- (`value`) => `R` \| `false`
85
-
86
- ###### Returns
87
-
88
- `R` \| `undefined`
89
-
90
- ##### rejectDuplicates()
91
-
92
- ```ts
93
- rejectDuplicates: (getKey) => T[];
94
- ```
95
-
96
- Defined in: [packages/utils/src/arrayUtils.ts:274](https://github.com/lucasols/utils/blob/main/packages/utils/src/arrayUtils.ts#L274)
97
-
98
- ###### Parameters
99
-
100
- ###### getKey
101
-
102
- (`item`) => `unknown`
103
-
104
- ###### Returns
105
-
106
- `T`[]
107
-
108
- ##### sortBy()
109
-
110
- ```ts
111
- sortBy: (sortByValue, props) => T[];
112
- ```
113
-
114
- Defined in: [packages/utils/src/arrayUtils.ts:273](https://github.com/lucasols/utils/blob/main/packages/utils/src/arrayUtils.ts#L273)
115
-
116
- ###### Parameters
117
-
118
- ###### sortByValue
119
-
120
- [`SortByValue`](#sortbyvalue)\<`T`\>
121
-
122
- ###### props
123
-
124
- [`SortByProps`](#sortbyprops)
125
-
126
- ###### Returns
127
-
128
- `T`[]
129
-
130
- ***
131
-
132
- ### SortByProps
133
-
134
- ```ts
135
- type SortByProps =
136
- | {
137
- order?: SortOrder | SortOrder[];
138
- }
139
- | SortOrder
140
- | SortOrder[];
141
- ```
142
-
143
- Defined in: [packages/utils/src/arrayUtils.ts:48](https://github.com/lucasols/utils/blob/main/packages/utils/src/arrayUtils.ts#L48)
144
-
145
- ***
146
-
147
- ### SortByValue()\<T\>
148
-
149
- ```ts
150
- type SortByValue<T> = (item) => (number | string)[] | number | string;
151
- ```
152
-
153
- Defined in: [packages/utils/src/arrayUtils.ts:46](https://github.com/lucasols/utils/blob/main/packages/utils/src/arrayUtils.ts#L46)
154
-
155
- #### Type Parameters
156
-
157
- ##### T
158
-
159
- `T`
160
-
161
- #### Parameters
162
-
163
- ##### item
164
-
165
- `T`
166
-
167
- #### Returns
168
-
169
- (`number` \| `string`)[] \| `number` \| `string`
170
-
171
- ***
172
-
173
- ### SortOrder
174
-
175
- ```ts
176
- type SortOrder = "desc" | "asc";
177
- ```
178
-
179
- Defined in: [packages/utils/src/arrayUtils.ts:44](https://github.com/lucasols/utils/blob/main/packages/utils/src/arrayUtils.ts#L44)
@@ -1,550 +0,0 @@
1
- [**@ls-stack/utils**](../README.md)
2
-
3
- ***
4
-
5
- [@ls-stack/utils](../modules.md) / arrayUtils
6
-
7
- # arrayUtils
8
-
9
- ## Modules
10
-
11
- - [\<internal\>](-internal-.md)
12
-
13
- ## Type Aliases
14
-
15
- ### FilterAndMapReturn\<T\>
16
-
17
- ```ts
18
- type FilterAndMapReturn<T> = false | T;
19
- ```
20
-
21
- Defined in: [packages/utils/src/arrayUtils.ts:42](https://github.com/lucasols/utils/blob/main/packages/utils/src/arrayUtils.ts#L42)
22
-
23
- #### Type Parameters
24
-
25
- ##### T
26
-
27
- `T`
28
-
29
- ## Functions
30
-
31
- ### arrayOps()
32
-
33
- ```ts
34
- function arrayOps<T>(array): ArrayOps<T>;
35
- ```
36
-
37
- Defined in: [packages/utils/src/arrayUtils.ts:318](https://github.com/lucasols/utils/blob/main/packages/utils/src/arrayUtils.ts#L318)
38
-
39
- Enhance an array with extra methods
40
-
41
- #### Type Parameters
42
-
43
- ##### T
44
-
45
- `T`
46
-
47
- #### Parameters
48
-
49
- ##### array
50
-
51
- `T`[]
52
-
53
- #### Returns
54
-
55
- [`ArrayOps`](-internal-.md#arrayops)\<`T`\>
56
-
57
- #### Example
58
-
59
- ```ts
60
- const enhancedItems = arrayOps(array);
61
-
62
- enhancedItems.filterAndMap((item) => item === 2 ? false : item);
63
- enhancedItems.sortBy((item) => item);
64
- enhancedItems.rejectDuplicates((item) => item);
65
- ```
66
-
67
- ***
68
-
69
- ### arrayWithPrev()
70
-
71
- ```ts
72
- function arrayWithPrev<T>(array): [T, null | T][];
73
- ```
74
-
75
- Defined in: [packages/utils/src/arrayUtils.ts:138](https://github.com/lucasols/utils/blob/main/packages/utils/src/arrayUtils.ts#L138)
76
-
77
- #### Type Parameters
78
-
79
- ##### T
80
-
81
- `T`
82
-
83
- #### Parameters
84
-
85
- ##### array
86
-
87
- `T`[]
88
-
89
- #### Returns
90
-
91
- \[`T`, `null` \| `T`\][]
92
-
93
- ***
94
-
95
- ### arrayWithPrevAndIndex()
96
-
97
- ```ts
98
- function arrayWithPrevAndIndex<T>(array): object[];
99
- ```
100
-
101
- Defined in: [packages/utils/src/arrayUtils.ts:142](https://github.com/lucasols/utils/blob/main/packages/utils/src/arrayUtils.ts#L142)
102
-
103
- #### Type Parameters
104
-
105
- ##### T
106
-
107
- `T`
108
-
109
- #### Parameters
110
-
111
- ##### array
112
-
113
- `T`[]
114
-
115
- #### Returns
116
-
117
- `object`[]
118
-
119
- ***
120
-
121
- ### filterAndMap()
122
-
123
- ```ts
124
- function filterAndMap<T, R>(array, mapFilter): R[];
125
- ```
126
-
127
- Defined in: [packages/utils/src/arrayUtils.ts:23](https://github.com/lucasols/utils/blob/main/packages/utils/src/arrayUtils.ts#L23)
128
-
129
- allow to filter and map with better typing ergonomics
130
-
131
- In the `mapFilter` function return `false` to reject the item, or any other
132
- value to map it.
133
-
134
- #### Type Parameters
135
-
136
- ##### T
137
-
138
- `T`
139
-
140
- ##### R
141
-
142
- `R`
143
-
144
- #### Parameters
145
-
146
- ##### array
147
-
148
- `IterableIterator`\<`T`, `any`, `any`\> | readonly `T`[]
149
-
150
- ##### mapFilter
151
-
152
- (`item`, `index`) => `false` \| `R`
153
-
154
- #### Returns
155
-
156
- `R`[]
157
-
158
- #### Example
159
-
160
- ```ts
161
- // Filter reject and turn value into `value mapped`
162
- const items = ['value', 'value', 'reject', 'reject'];
163
-
164
- const mappedItems = filterAndMap(items, (item) =>
165
- item === 'reject'
166
- ? false
167
- : `${item} mapped`,
168
- );
169
-
170
- mappedItems; // ['value mapped', 'value mapped']
171
- ```
172
-
173
- ***
174
-
175
- ### findAfterIndex()
176
-
177
- ```ts
178
- function findAfterIndex<T>(
179
- array,
180
- index,
181
- predicate): undefined | T;
182
- ```
183
-
184
- Defined in: [packages/utils/src/arrayUtils.ts:165](https://github.com/lucasols/utils/blob/main/packages/utils/src/arrayUtils.ts#L165)
185
-
186
- #### Type Parameters
187
-
188
- ##### T
189
-
190
- `T`
191
-
192
- #### Parameters
193
-
194
- ##### array
195
-
196
- `T`[]
197
-
198
- ##### index
199
-
200
- `number`
201
-
202
- ##### predicate
203
-
204
- (`item`) => `boolean`
205
-
206
- #### Returns
207
-
208
- `undefined` \| `T`
209
-
210
- ***
211
-
212
- ### findAndMap()
213
-
214
- ```ts
215
- function findAndMap<T, R>(array, predicate): undefined | R;
216
- ```
217
-
218
- Defined in: [packages/utils/src/arrayUtils.ts:295](https://github.com/lucasols/utils/blob/main/packages/utils/src/arrayUtils.ts#L295)
219
-
220
- Finds the first item in an array where the predicate returns a non-false value and returns that mapped value.
221
-
222
- Combines find and map operations - applies the predicate to each item until one returns
223
- a value that is not `false`, then returns that mapped value. If no item matches, returns `undefined`.
224
-
225
- #### Type Parameters
226
-
227
- ##### T
228
-
229
- `T`
230
-
231
- ##### R
232
-
233
- `R`
234
-
235
- #### Parameters
236
-
237
- ##### array
238
-
239
- `T`[]
240
-
241
- The array to search through
242
-
243
- ##### predicate
244
-
245
- (`value`) => `false` \| `R`
246
-
247
- Function that returns a mapped value or `false` to skip the item
248
-
249
- #### Returns
250
-
251
- `undefined` \| `R`
252
-
253
- The first mapped value that is not `false`, or `undefined` if no item matches
254
-
255
- #### Example
256
-
257
- ```ts
258
- const users = [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }];
259
-
260
- const foundName = findAndMap(users, (user) =>
261
- user.id === 2 ? user.name.toUpperCase() : false
262
- );
263
- // foundName is 'BOB'
264
- ```
265
-
266
- ***
267
-
268
- ### findBeforeIndex()
269
-
270
- ```ts
271
- function findBeforeIndex<T>(
272
- array,
273
- index,
274
- predicate): undefined | T;
275
- ```
276
-
277
- Defined in: [packages/utils/src/arrayUtils.ts:179](https://github.com/lucasols/utils/blob/main/packages/utils/src/arrayUtils.ts#L179)
278
-
279
- #### Type Parameters
280
-
281
- ##### T
282
-
283
- `T`
284
-
285
- #### Parameters
286
-
287
- ##### array
288
-
289
- `T`[]
290
-
291
- ##### index
292
-
293
- `number`
294
-
295
- ##### predicate
296
-
297
- (`item`) => `boolean`
298
-
299
- #### Returns
300
-
301
- `undefined` \| `T`
302
-
303
- ***
304
-
305
- ### getAscIndexOrder()
306
-
307
- ```ts
308
- function getAscIndexOrder(index): number;
309
- ```
310
-
311
- Defined in: [packages/utils/src/arrayUtils.ts:134](https://github.com/lucasols/utils/blob/main/packages/utils/src/arrayUtils.ts#L134)
312
-
313
- Get the correct 0 based value for sync with other array in ascending order
314
-
315
- #### Parameters
316
-
317
- ##### index
318
-
319
- `undefined` | `number`
320
-
321
- #### Returns
322
-
323
- `number`
324
-
325
- #### Example
326
-
327
- ```ts
328
- const items = [1, 2, 3];
329
-
330
- const index = sortBy(
331
- items,
332
- (item) => getAscIndexOrder(
333
- followOrder.findIndex((order) => order === item)
334
- )
335
- );
336
- ```
337
-
338
- ***
339
-
340
- ### hasDuplicates()
341
-
342
- ```ts
343
- function hasDuplicates<T>(array, getKey): boolean;
344
- ```
345
-
346
- Defined in: [packages/utils/src/arrayUtils.ts:203](https://github.com/lucasols/utils/blob/main/packages/utils/src/arrayUtils.ts#L203)
347
-
348
- #### Type Parameters
349
-
350
- ##### T
351
-
352
- `T`
353
-
354
- #### Parameters
355
-
356
- ##### array
357
-
358
- `T`[]
359
-
360
- ##### getKey
361
-
362
- (`item`) => `unknown`
363
-
364
- #### Returns
365
-
366
- `boolean`
367
-
368
- ***
369
-
370
- ### isInArray()
371
-
372
- ```ts
373
- function isInArray<T, U>(value, oneOf): value is U;
374
- ```
375
-
376
- Defined in: [packages/utils/src/arrayUtils.ts:152](https://github.com/lucasols/utils/blob/main/packages/utils/src/arrayUtils.ts#L152)
377
-
378
- #### Type Parameters
379
-
380
- ##### T
381
-
382
- `T`
383
-
384
- ##### U
385
-
386
- `U`
387
-
388
- #### Parameters
389
-
390
- ##### value
391
-
392
- `T`
393
-
394
- ##### oneOf
395
-
396
- readonly `U`[]
397
-
398
- #### Returns
399
-
400
- `value is U`
401
-
402
- ***
403
-
404
- ### rejectArrayUndefinedValues()
405
-
406
- ```ts
407
- function rejectArrayUndefinedValues<T>(array): T;
408
- ```
409
-
410
- Defined in: [packages/utils/src/arrayUtils.ts:199](https://github.com/lucasols/utils/blob/main/packages/utils/src/arrayUtils.ts#L199)
411
-
412
- #### Type Parameters
413
-
414
- ##### T
415
-
416
- `T` *extends* `unknown`[]
417
-
418
- #### Parameters
419
-
420
- ##### array
421
-
422
- `T`
423
-
424
- #### Returns
425
-
426
- `T`
427
-
428
- ***
429
-
430
- ### rejectDuplicates()
431
-
432
- ```ts
433
- function rejectDuplicates<T>(array, getKey): T[];
434
- ```
435
-
436
- Defined in: [packages/utils/src/arrayUtils.ts:220](https://github.com/lucasols/utils/blob/main/packages/utils/src/arrayUtils.ts#L220)
437
-
438
- #### Type Parameters
439
-
440
- ##### T
441
-
442
- `T`
443
-
444
- #### Parameters
445
-
446
- ##### array
447
-
448
- `T`[]
449
-
450
- ##### getKey
451
-
452
- (`item`) => `unknown`
453
-
454
- #### Returns
455
-
456
- `T`[]
457
-
458
- ***
459
-
460
- ### sortBy()
461
-
462
- ```ts
463
- function sortBy<T>(
464
- arr,
465
- sortByValue,
466
- props): T[];
467
- ```
468
-
469
- Defined in: [packages/utils/src/arrayUtils.ts:76](https://github.com/lucasols/utils/blob/main/packages/utils/src/arrayUtils.ts#L76)
470
-
471
- Sort an array based on a value
472
-
473
- Sort by `ascending` order by default
474
-
475
- Use `Infinity` as as wildcard to absolute max and min values
476
-
477
- #### Type Parameters
478
-
479
- ##### T
480
-
481
- `T`
482
-
483
- #### Parameters
484
-
485
- ##### arr
486
-
487
- `T`[]
488
-
489
- ##### sortByValue
490
-
491
- [`SortByValue`](-internal-.md#sortbyvalue)\<`T`\>
492
-
493
- ##### props
494
-
495
- [`SortByProps`](-internal-.md#sortbyprops) = `'asc'`
496
-
497
- #### Returns
498
-
499
- `T`[]
500
-
501
- #### Example
502
-
503
- ```ts
504
- const items = [1, 3, 2, 4];
505
-
506
- const sortedItems = sortBy(items, (item) => item);
507
- // [1, 2, 3, 4]
508
-
509
- const items2 = [{ a: 1, b: 2 }, { a: 2, b: 1 }, { a: 1, b: 1}]
510
-
511
- // return a array to sort by multiple values
512
- const sortedItems = sortBy(items, (item) => [item.a, item.b]);
513
- ```
514
-
515
- ***
516
-
517
- ### truncateArray()
518
-
519
- ```ts
520
- function truncateArray<T>(
521
- array,
522
- maxLength,
523
- appendIfTruncated?): T[];
524
- ```
525
-
526
- Defined in: [packages/utils/src/arrayUtils.ts:240](https://github.com/lucasols/utils/blob/main/packages/utils/src/arrayUtils.ts#L240)
527
-
528
- #### Type Parameters
529
-
530
- ##### T
531
-
532
- `T`
533
-
534
- #### Parameters
535
-
536
- ##### array
537
-
538
- `T`[]
539
-
540
- ##### maxLength
541
-
542
- `number`
543
-
544
- ##### appendIfTruncated?
545
-
546
- `T` | (`truncatedCount`) => `T`
547
-
548
- #### Returns
549
-
550
- `T`[]