@ls-stack/utils 3.18.0 → 3.19.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/README.md +1 -15
- package/docs/README.md +72 -0
- package/docs/_media/modules.md +52 -0
- package/docs/arrayUtils/-internal-.md +17 -0
- package/docs/arrayUtils/README.md +423 -0
- package/docs/assertions/-internal-.md +63 -0
- package/docs/assertions/README.md +565 -0
- package/docs/asyncQueue/-internal-.md +815 -0
- package/docs/asyncQueue/README.md +75 -0
- package/docs/awaitDebounce.md +66 -0
- package/docs/cache/-internal-.md +168 -0
- package/docs/cache/README.md +360 -0
- package/docs/castValues.md +47 -0
- package/docs/concurrentCalls/-internal-.md +416 -0
- package/docs/concurrentCalls/README.md +77 -0
- package/docs/consoleFmt.md +91 -0
- package/docs/conversions.md +27 -0
- package/docs/createThrottleController/-internal-.md +73 -0
- package/docs/createThrottleController/README.md +31 -0
- package/docs/debounce.md +188 -0
- package/docs/dedent.md +117 -0
- package/docs/deepEqual.md +94 -0
- package/docs/enhancedMap.md +358 -0
- package/docs/exhaustiveMatch/-internal-.md +39 -0
- package/docs/exhaustiveMatch/README.md +146 -0
- package/docs/getAutoIncrementId.md +93 -0
- package/docs/getCompositeKey.md +39 -0
- package/docs/getValueStableKey.md +57 -0
- package/docs/hash.md +31 -0
- package/docs/interpolate/-internal-.md +61 -0
- package/docs/interpolate/README.md +62 -0
- package/docs/levenshtein.md +93 -0
- package/docs/main.md +21 -0
- package/docs/mathUtils.md +137 -0
- package/docs/modules.md +52 -0
- package/docs/objUtils.md +237 -0
- package/docs/parallelAsyncCalls/-internal-.md +347 -0
- package/docs/parallelAsyncCalls/README.md +45 -0
- package/docs/promiseUtils/-internal-.md +69 -0
- package/docs/promiseUtils/README.md +31 -0
- package/docs/retryOnError.md +67 -0
- package/docs/runShellCmd/-internal-.md +111 -0
- package/docs/runShellCmd/README.md +201 -0
- package/docs/safeJson.md +51 -0
- package/docs/saferTyping.md +228 -0
- package/docs/serializeXML.md +100 -0
- package/docs/shallowEqual.md +33 -0
- package/docs/sleep.md +27 -0
- package/docs/stringUtils/-internal-.md +17 -0
- package/docs/stringUtils/README.md +166 -0
- package/docs/testUtils.md +315 -0
- package/docs/throttle/-internal-.md +47 -0
- package/docs/throttle/README.md +178 -0
- package/docs/time.md +274 -0
- package/docs/timers.md +256 -0
- package/docs/tsResult/-internal-.md +327 -0
- package/docs/tsResult/README.md +696 -0
- package/docs/typeGuards.md +399 -0
- package/docs/typingFnUtils/-internal-.md +27 -0
- package/docs/typingFnUtils/README.md +293 -0
- package/docs/typingTestUtils.md +172 -0
- package/docs/typingUtils.md +111 -0
- package/docs/yamlStringify.md +45 -0
- package/lib/arrayUtils.js +3 -3
- package/lib/assertions.js +2 -2
- package/lib/awaitDebounce.cjs +106 -0
- package/lib/awaitDebounce.d.cts +38 -0
- package/lib/awaitDebounce.d.ts +38 -0
- package/lib/awaitDebounce.js +28 -0
- package/lib/cache.js +2 -2
- package/lib/{chunk-NH2LCAQS.js → chunk-6FIBVC2P.js} +1 -1
- package/lib/{chunk-GKOTKAIV.js → chunk-7CQPOM5I.js} +1 -1
- package/lib/{chunk-WS4WEVHU.js → chunk-C2SVCIWE.js} +1 -1
- package/lib/{chunk-SSKW673U.js → chunk-JF2MDHOJ.js} +5 -1
- package/lib/chunk-NW5H5EW7.js +100 -0
- package/lib/{chunk-DMW5Q4T2.js → chunk-SRVMMYSW.js} +1 -1
- package/lib/concurrentCalls.js +3 -3
- package/lib/createThrottleController.js +3 -3
- package/lib/debounce.js +4 -95
- package/lib/enhancedMap.js +3 -3
- package/lib/getAutoIncrementId.cjs +44 -0
- package/lib/getAutoIncrementId.d.cts +44 -0
- package/lib/getAutoIncrementId.d.ts +44 -0
- package/lib/getAutoIncrementId.js +18 -0
- package/lib/getCompositeKey.js +3 -3
- package/lib/getValueStableKey.js +3 -3
- package/lib/interpolate.js +2 -2
- package/lib/parallelAsyncCalls.js +2 -2
- package/lib/runShellCmd.d.cts +50 -0
- package/lib/runShellCmd.d.ts +50 -0
- package/lib/serializeXML.cjs +7 -2
- package/lib/serializeXML.d.cts +1 -1
- package/lib/serializeXML.d.ts +1 -1
- package/lib/serializeXML.js +7 -5
- package/lib/testUtils.js +3 -3
- package/lib/throttle.cjs +250 -0
- package/lib/throttle.d.cts +89 -0
- package/lib/throttle.d.ts +89 -0
- package/lib/throttle.js +38 -0
- package/lib/tsResult.js +2 -2
- package/lib/typeGuards.cjs +7 -2
- package/lib/typeGuards.d.cts +2 -1
- package/lib/typeGuards.d.ts +2 -1
- package/lib/typeGuards.js +5 -3
- package/lib/typingFnUtils.cjs +5 -1
- package/lib/typingFnUtils.d.cts +1 -1
- package/lib/typingFnUtils.d.ts +1 -1
- package/lib/typingFnUtils.js +5 -1
- package/lib/yamlStringify.js +5 -5
- package/package.json +22 -12
package/README.md
CHANGED
|
@@ -22,23 +22,9 @@ import { deepEqual } from '@ls-stack/utils/deepEqual';
|
|
|
22
22
|
import { debounce } from '@ls-stack/utils/debounce';
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
-
## Available Utilities
|
|
26
|
-
|
|
27
|
-
This package includes a wide range of utilities for:
|
|
28
|
-
|
|
29
|
-
- **Array manipulation** (`arrayUtils`) - sorting, grouping, filtering
|
|
30
|
-
- **Async operations** (`asyncQueue`, `parallelAsyncCalls`, `promiseUtils`) - queue management and promise utilities
|
|
31
|
-
- **Type assertions** (`assertions`) - runtime type checking
|
|
32
|
-
- **Caching** (`cache`) - efficient caching with TTL support
|
|
33
|
-
- **Concurrency control** (`concurrentCalls`, `createThrottleController`) - rate limiting and throttling
|
|
34
|
-
- **Object utilities** (`objUtils`) - deep operations on objects
|
|
35
|
-
- **String utilities** (`stringUtils`) - string manipulation and formatting
|
|
36
|
-
- **Math utilities** (`mathUtils`) - mathematical operations and calculations
|
|
37
|
-
- **And many more...**
|
|
38
|
-
|
|
39
25
|
## Documentation
|
|
40
26
|
|
|
41
|
-
|
|
27
|
+
For a complete list of available utilities and their APIs, see the auto-generated documentation in the [`docs/`](docs/) folder. Start with the [modules overview](docs/modules.md) to explore all available utilities.
|
|
42
28
|
|
|
43
29
|
### Generating Documentation
|
|
44
30
|
|
package/docs/README.md
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
**@ls-stack/utils**
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
# @ls-stack/utils
|
|
6
|
+
|
|
7
|
+
Generic TypeScript utilities for modern JavaScript/TypeScript projects.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @ls-stack/utils
|
|
13
|
+
# or
|
|
14
|
+
pnpm add @ls-stack/utils
|
|
15
|
+
# or
|
|
16
|
+
yarn add @ls-stack/utils
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
Import specific utilities from their modules:
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import { createAsyncQueue } from '@ls-stack/utils/asyncQueue';
|
|
25
|
+
import { deepEqual } from '@ls-stack/utils/deepEqual';
|
|
26
|
+
import { debounce } from '@ls-stack/utils/debounce';
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Documentation
|
|
30
|
+
|
|
31
|
+
For a complete list of available utilities and their APIs, see the auto-generated documentation in the [`docs/`](docs/) folder. Start with the [modules overview](_media/modules.md) to explore all available utilities.
|
|
32
|
+
|
|
33
|
+
### Generating Documentation
|
|
34
|
+
|
|
35
|
+
To regenerate the documentation after making changes:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
pnpm docs
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
For continuous updates during development:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
pnpm docs:watch
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Development
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
# Install dependencies
|
|
51
|
+
pnpm install
|
|
52
|
+
|
|
53
|
+
# Run tests
|
|
54
|
+
pnpm test
|
|
55
|
+
|
|
56
|
+
# Run tests with UI
|
|
57
|
+
pnpm test:ui
|
|
58
|
+
|
|
59
|
+
# Build the library
|
|
60
|
+
pnpm build
|
|
61
|
+
|
|
62
|
+
# Lint code
|
|
63
|
+
pnpm lint
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## License
|
|
67
|
+
|
|
68
|
+
MIT
|
|
69
|
+
|
|
70
|
+
## Repository
|
|
71
|
+
|
|
72
|
+
[github:lucasols/utils](https://github.com/lucasols/utils)
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
[**@ls-stack/utils**](README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
# @ls-stack/utils
|
|
6
|
+
|
|
7
|
+
## Modules
|
|
8
|
+
|
|
9
|
+
- [arrayUtils](arrayUtils/README.md)
|
|
10
|
+
- [assertions](assertions/README.md)
|
|
11
|
+
- [asyncQueue](asyncQueue/README.md)
|
|
12
|
+
- [awaitDebounce](awaitDebounce.md)
|
|
13
|
+
- [cache](cache/README.md)
|
|
14
|
+
- [castValues](castValues.md)
|
|
15
|
+
- [concurrentCalls](concurrentCalls/README.md)
|
|
16
|
+
- [consoleFmt](consoleFmt.md)
|
|
17
|
+
- [conversions](conversions.md)
|
|
18
|
+
- [createThrottleController](createThrottleController/README.md)
|
|
19
|
+
- [debounce](debounce.md)
|
|
20
|
+
- [dedent](dedent.md)
|
|
21
|
+
- [deepEqual](deepEqual.md)
|
|
22
|
+
- [enhancedMap](enhancedMap.md)
|
|
23
|
+
- [exhaustiveMatch](exhaustiveMatch/README.md)
|
|
24
|
+
- [getAutoIncrementId](getAutoIncrementId.md)
|
|
25
|
+
- [getCompositeKey](getCompositeKey.md)
|
|
26
|
+
- [getValueStableKey](getValueStableKey.md)
|
|
27
|
+
- [hash](hash.md)
|
|
28
|
+
- [interpolate](interpolate/README.md)
|
|
29
|
+
- [levenshtein](levenshtein.md)
|
|
30
|
+
- [main](main.md)
|
|
31
|
+
- [mathUtils](mathUtils.md)
|
|
32
|
+
- [objUtils](objUtils.md)
|
|
33
|
+
- [parallelAsyncCalls](parallelAsyncCalls/README.md)
|
|
34
|
+
- [promiseUtils](promiseUtils/README.md)
|
|
35
|
+
- [retryOnError](retryOnError.md)
|
|
36
|
+
- [runShellCmd](runShellCmd/README.md)
|
|
37
|
+
- [safeJson](safeJson.md)
|
|
38
|
+
- [saferTyping](saferTyping.md)
|
|
39
|
+
- [serializeXML](serializeXML.md)
|
|
40
|
+
- [shallowEqual](shallowEqual.md)
|
|
41
|
+
- [sleep](sleep.md)
|
|
42
|
+
- [stringUtils](stringUtils/README.md)
|
|
43
|
+
- [testUtils](testUtils.md)
|
|
44
|
+
- [throttle](throttle/README.md)
|
|
45
|
+
- [time](time.md)
|
|
46
|
+
- [timers](timers.md)
|
|
47
|
+
- [tsResult](tsResult/README.md)
|
|
48
|
+
- [typeGuards](typeGuards.md)
|
|
49
|
+
- [typingFnUtils](typingFnUtils/README.md)
|
|
50
|
+
- [typingTestUtils](typingTestUtils.md)
|
|
51
|
+
- [typingUtils](typingUtils.md)
|
|
52
|
+
- [yamlStringify](yamlStringify.md)
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
### SortOrder
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
type SortOrder = "desc" | "asc";
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Defined in: [packages/utils/src/arrayUtils.ts:42](https://github.com/lucasols/utils/blob/main/packages/utils/src/arrayUtils.ts#L42)
|
|
@@ -0,0 +1,423 @@
|
|
|
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:40](https://github.com/lucasols/utils/blob/main/packages/utils/src/arrayUtils.ts#L40)
|
|
22
|
+
|
|
23
|
+
#### Type Parameters
|
|
24
|
+
|
|
25
|
+
##### T
|
|
26
|
+
|
|
27
|
+
`T`
|
|
28
|
+
|
|
29
|
+
## Functions
|
|
30
|
+
|
|
31
|
+
### arrayWithPrev()
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
function arrayWithPrev<T>(array): [T, null | T][];
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Defined in: [packages/utils/src/arrayUtils.ts:103](https://github.com/lucasols/utils/blob/main/packages/utils/src/arrayUtils.ts#L103)
|
|
38
|
+
|
|
39
|
+
#### Type Parameters
|
|
40
|
+
|
|
41
|
+
##### T
|
|
42
|
+
|
|
43
|
+
`T`
|
|
44
|
+
|
|
45
|
+
#### Parameters
|
|
46
|
+
|
|
47
|
+
##### array
|
|
48
|
+
|
|
49
|
+
`T`[]
|
|
50
|
+
|
|
51
|
+
#### Returns
|
|
52
|
+
|
|
53
|
+
\[`T`, `null` \| `T`\][]
|
|
54
|
+
|
|
55
|
+
***
|
|
56
|
+
|
|
57
|
+
### arrayWithPrevAndIndex()
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
function arrayWithPrevAndIndex<T>(array): object[];
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Defined in: [packages/utils/src/arrayUtils.ts:107](https://github.com/lucasols/utils/blob/main/packages/utils/src/arrayUtils.ts#L107)
|
|
64
|
+
|
|
65
|
+
#### Type Parameters
|
|
66
|
+
|
|
67
|
+
##### T
|
|
68
|
+
|
|
69
|
+
`T`
|
|
70
|
+
|
|
71
|
+
#### Parameters
|
|
72
|
+
|
|
73
|
+
##### array
|
|
74
|
+
|
|
75
|
+
`T`[]
|
|
76
|
+
|
|
77
|
+
#### Returns
|
|
78
|
+
|
|
79
|
+
`object`[]
|
|
80
|
+
|
|
81
|
+
***
|
|
82
|
+
|
|
83
|
+
### filterAndMap()
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
function filterAndMap<T, R>(array, mapFilter): R[];
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Defined in: [packages/utils/src/arrayUtils.ts:21](https://github.com/lucasols/utils/blob/main/packages/utils/src/arrayUtils.ts#L21)
|
|
90
|
+
|
|
91
|
+
allow to filter and map with better typing ergonomics
|
|
92
|
+
|
|
93
|
+
In the `mapFilter` function return `false` to reject the item, or any other
|
|
94
|
+
value to map it.
|
|
95
|
+
|
|
96
|
+
#### Type Parameters
|
|
97
|
+
|
|
98
|
+
##### T
|
|
99
|
+
|
|
100
|
+
`T`
|
|
101
|
+
|
|
102
|
+
##### R
|
|
103
|
+
|
|
104
|
+
`R`
|
|
105
|
+
|
|
106
|
+
#### Parameters
|
|
107
|
+
|
|
108
|
+
##### array
|
|
109
|
+
|
|
110
|
+
`IterableIterator`\<`T`, `any`, `any`\> | readonly `T`[]
|
|
111
|
+
|
|
112
|
+
##### mapFilter
|
|
113
|
+
|
|
114
|
+
(`item`, `index`) => `false` \| `R`
|
|
115
|
+
|
|
116
|
+
#### Returns
|
|
117
|
+
|
|
118
|
+
`R`[]
|
|
119
|
+
|
|
120
|
+
#### Example
|
|
121
|
+
|
|
122
|
+
```ts
|
|
123
|
+
// Filter reject and turn value into `value mapped`
|
|
124
|
+
const items = ['value', 'value', 'reject', 'reject'];
|
|
125
|
+
|
|
126
|
+
const mappedItems = filterAndMap(items, (item) =>
|
|
127
|
+
item === 'reject'
|
|
128
|
+
? false
|
|
129
|
+
: `${item} mapped`,
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
mappedItems; // ['value mapped', 'value mapped']
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
***
|
|
136
|
+
|
|
137
|
+
### findAfterIndex()
|
|
138
|
+
|
|
139
|
+
```ts
|
|
140
|
+
function findAfterIndex<T>(
|
|
141
|
+
array,
|
|
142
|
+
index,
|
|
143
|
+
predicate): undefined | T;
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
Defined in: [packages/utils/src/arrayUtils.ts:130](https://github.com/lucasols/utils/blob/main/packages/utils/src/arrayUtils.ts#L130)
|
|
147
|
+
|
|
148
|
+
#### Type Parameters
|
|
149
|
+
|
|
150
|
+
##### T
|
|
151
|
+
|
|
152
|
+
`T`
|
|
153
|
+
|
|
154
|
+
#### Parameters
|
|
155
|
+
|
|
156
|
+
##### array
|
|
157
|
+
|
|
158
|
+
`T`[]
|
|
159
|
+
|
|
160
|
+
##### index
|
|
161
|
+
|
|
162
|
+
`number`
|
|
163
|
+
|
|
164
|
+
##### predicate
|
|
165
|
+
|
|
166
|
+
(`item`) => `boolean`
|
|
167
|
+
|
|
168
|
+
#### Returns
|
|
169
|
+
|
|
170
|
+
`undefined` \| `T`
|
|
171
|
+
|
|
172
|
+
***
|
|
173
|
+
|
|
174
|
+
### findBeforeIndex()
|
|
175
|
+
|
|
176
|
+
```ts
|
|
177
|
+
function findBeforeIndex<T>(
|
|
178
|
+
array,
|
|
179
|
+
index,
|
|
180
|
+
predicate): undefined | T;
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
Defined in: [packages/utils/src/arrayUtils.ts:144](https://github.com/lucasols/utils/blob/main/packages/utils/src/arrayUtils.ts#L144)
|
|
184
|
+
|
|
185
|
+
#### Type Parameters
|
|
186
|
+
|
|
187
|
+
##### T
|
|
188
|
+
|
|
189
|
+
`T`
|
|
190
|
+
|
|
191
|
+
#### Parameters
|
|
192
|
+
|
|
193
|
+
##### array
|
|
194
|
+
|
|
195
|
+
`T`[]
|
|
196
|
+
|
|
197
|
+
##### index
|
|
198
|
+
|
|
199
|
+
`number`
|
|
200
|
+
|
|
201
|
+
##### predicate
|
|
202
|
+
|
|
203
|
+
(`item`) => `boolean`
|
|
204
|
+
|
|
205
|
+
#### Returns
|
|
206
|
+
|
|
207
|
+
`undefined` \| `T`
|
|
208
|
+
|
|
209
|
+
***
|
|
210
|
+
|
|
211
|
+
### hasDuplicates()
|
|
212
|
+
|
|
213
|
+
```ts
|
|
214
|
+
function hasDuplicates<T>(array, getKey): boolean;
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
Defined in: [packages/utils/src/arrayUtils.ts:168](https://github.com/lucasols/utils/blob/main/packages/utils/src/arrayUtils.ts#L168)
|
|
218
|
+
|
|
219
|
+
#### Type Parameters
|
|
220
|
+
|
|
221
|
+
##### T
|
|
222
|
+
|
|
223
|
+
`T`
|
|
224
|
+
|
|
225
|
+
#### Parameters
|
|
226
|
+
|
|
227
|
+
##### array
|
|
228
|
+
|
|
229
|
+
`T`[]
|
|
230
|
+
|
|
231
|
+
##### getKey
|
|
232
|
+
|
|
233
|
+
(`item`) => `unknown`
|
|
234
|
+
|
|
235
|
+
#### Returns
|
|
236
|
+
|
|
237
|
+
`boolean`
|
|
238
|
+
|
|
239
|
+
***
|
|
240
|
+
|
|
241
|
+
### isInArray()
|
|
242
|
+
|
|
243
|
+
```ts
|
|
244
|
+
function isInArray<T, U>(value, oneOf): value is U;
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
Defined in: [packages/utils/src/arrayUtils.ts:117](https://github.com/lucasols/utils/blob/main/packages/utils/src/arrayUtils.ts#L117)
|
|
248
|
+
|
|
249
|
+
#### Type Parameters
|
|
250
|
+
|
|
251
|
+
##### T
|
|
252
|
+
|
|
253
|
+
`T`
|
|
254
|
+
|
|
255
|
+
##### U
|
|
256
|
+
|
|
257
|
+
`U`
|
|
258
|
+
|
|
259
|
+
#### Parameters
|
|
260
|
+
|
|
261
|
+
##### value
|
|
262
|
+
|
|
263
|
+
`T`
|
|
264
|
+
|
|
265
|
+
##### oneOf
|
|
266
|
+
|
|
267
|
+
readonly `U`[]
|
|
268
|
+
|
|
269
|
+
#### Returns
|
|
270
|
+
|
|
271
|
+
`value is U`
|
|
272
|
+
|
|
273
|
+
***
|
|
274
|
+
|
|
275
|
+
### rejectArrayUndefinedValues()
|
|
276
|
+
|
|
277
|
+
```ts
|
|
278
|
+
function rejectArrayUndefinedValues<T>(array): T;
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
Defined in: [packages/utils/src/arrayUtils.ts:164](https://github.com/lucasols/utils/blob/main/packages/utils/src/arrayUtils.ts#L164)
|
|
282
|
+
|
|
283
|
+
#### Type Parameters
|
|
284
|
+
|
|
285
|
+
##### T
|
|
286
|
+
|
|
287
|
+
`T` *extends* `unknown`[]
|
|
288
|
+
|
|
289
|
+
#### Parameters
|
|
290
|
+
|
|
291
|
+
##### array
|
|
292
|
+
|
|
293
|
+
`T`
|
|
294
|
+
|
|
295
|
+
#### Returns
|
|
296
|
+
|
|
297
|
+
`T`
|
|
298
|
+
|
|
299
|
+
***
|
|
300
|
+
|
|
301
|
+
### rejectDuplicates()
|
|
302
|
+
|
|
303
|
+
```ts
|
|
304
|
+
function rejectDuplicates<T>(array, getKey): T[];
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
Defined in: [packages/utils/src/arrayUtils.ts:185](https://github.com/lucasols/utils/blob/main/packages/utils/src/arrayUtils.ts#L185)
|
|
308
|
+
|
|
309
|
+
#### Type Parameters
|
|
310
|
+
|
|
311
|
+
##### T
|
|
312
|
+
|
|
313
|
+
`T`
|
|
314
|
+
|
|
315
|
+
#### Parameters
|
|
316
|
+
|
|
317
|
+
##### array
|
|
318
|
+
|
|
319
|
+
`T`[]
|
|
320
|
+
|
|
321
|
+
##### getKey
|
|
322
|
+
|
|
323
|
+
(`item`) => `unknown`
|
|
324
|
+
|
|
325
|
+
#### Returns
|
|
326
|
+
|
|
327
|
+
`T`[]
|
|
328
|
+
|
|
329
|
+
***
|
|
330
|
+
|
|
331
|
+
### sortBy()
|
|
332
|
+
|
|
333
|
+
```ts
|
|
334
|
+
function sortBy<T>(
|
|
335
|
+
arr,
|
|
336
|
+
sortByValue,
|
|
337
|
+
props): T[];
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
Defined in: [packages/utils/src/arrayUtils.ts:62](https://github.com/lucasols/utils/blob/main/packages/utils/src/arrayUtils.ts#L62)
|
|
341
|
+
|
|
342
|
+
Sort an array based on a value
|
|
343
|
+
|
|
344
|
+
Sort by `ascending` order by default
|
|
345
|
+
|
|
346
|
+
Use `Infinity` as as wildcard to absolute max and min values
|
|
347
|
+
|
|
348
|
+
#### Type Parameters
|
|
349
|
+
|
|
350
|
+
##### T
|
|
351
|
+
|
|
352
|
+
`T`
|
|
353
|
+
|
|
354
|
+
#### Parameters
|
|
355
|
+
|
|
356
|
+
##### arr
|
|
357
|
+
|
|
358
|
+
`T`[]
|
|
359
|
+
|
|
360
|
+
##### sortByValue
|
|
361
|
+
|
|
362
|
+
(`item`) => `string` \| `number` \| (`string` \| `number`)[]
|
|
363
|
+
|
|
364
|
+
##### props
|
|
365
|
+
|
|
366
|
+
[`SortOrder`](-internal-.md#sortorder) | [`SortOrder`](-internal-.md#sortorder)[] | \{
|
|
367
|
+
`order?`: SortOrder \| SortOrder\[\] \| undefined;
|
|
368
|
+
\}
|
|
369
|
+
|
|
370
|
+
#### Returns
|
|
371
|
+
|
|
372
|
+
`T`[]
|
|
373
|
+
|
|
374
|
+
#### Example
|
|
375
|
+
|
|
376
|
+
```ts
|
|
377
|
+
const items = [1, 3, 2, 4];
|
|
378
|
+
|
|
379
|
+
const sortedItems = sortBy(items, (item) => item);
|
|
380
|
+
// [1, 2, 3, 4]
|
|
381
|
+
|
|
382
|
+
const items2 = [{ a: 1, b: 2 }, { a: 2, b: 1 }, { a: 1, b: 1}]
|
|
383
|
+
|
|
384
|
+
// return a array to sort by multiple values
|
|
385
|
+
const sortedItems = sortBy(items, (item) => [item.a, item.b]);
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
***
|
|
389
|
+
|
|
390
|
+
### truncateArray()
|
|
391
|
+
|
|
392
|
+
```ts
|
|
393
|
+
function truncateArray<T>(
|
|
394
|
+
array,
|
|
395
|
+
maxLength,
|
|
396
|
+
appendIfTruncated?): T[];
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
Defined in: [packages/utils/src/arrayUtils.ts:205](https://github.com/lucasols/utils/blob/main/packages/utils/src/arrayUtils.ts#L205)
|
|
400
|
+
|
|
401
|
+
#### Type Parameters
|
|
402
|
+
|
|
403
|
+
##### T
|
|
404
|
+
|
|
405
|
+
`T`
|
|
406
|
+
|
|
407
|
+
#### Parameters
|
|
408
|
+
|
|
409
|
+
##### array
|
|
410
|
+
|
|
411
|
+
`T`[]
|
|
412
|
+
|
|
413
|
+
##### maxLength
|
|
414
|
+
|
|
415
|
+
`number`
|
|
416
|
+
|
|
417
|
+
##### appendIfTruncated?
|
|
418
|
+
|
|
419
|
+
`T` | (`truncatedCount`) => `T`
|
|
420
|
+
|
|
421
|
+
#### Returns
|
|
422
|
+
|
|
423
|
+
`T`[]
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
[**@ls-stack/utils**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@ls-stack/utils](../modules.md) / [assertions](README.md) / \<internal\>
|
|
6
|
+
|
|
7
|
+
# \<internal\>
|
|
8
|
+
|
|
9
|
+
## Type Aliases
|
|
10
|
+
|
|
11
|
+
### NotUndefined\<T\>
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
type NotUndefined<T> = T extends undefined ? never : T;
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Defined in: [packages/utils/src/assertions.ts:11](https://github.com/lucasols/utils/blob/main/packages/utils/src/assertions.ts#L11)
|
|
18
|
+
|
|
19
|
+
#### Type Parameters
|
|
20
|
+
|
|
21
|
+
##### T
|
|
22
|
+
|
|
23
|
+
`T`
|
|
24
|
+
|
|
25
|
+
***
|
|
26
|
+
|
|
27
|
+
### StrictNonNullable\<T, N\>
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
type StrictNonNullable<T, N> = undefined extends T ? NonNullable<T> : null extends T ? NonNullable<T> : N;
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Defined in: [packages/utils/src/assertions.ts:50](https://github.com/lucasols/utils/blob/main/packages/utils/src/assertions.ts#L50)
|
|
34
|
+
|
|
35
|
+
#### Type Parameters
|
|
36
|
+
|
|
37
|
+
##### T
|
|
38
|
+
|
|
39
|
+
`T`
|
|
40
|
+
|
|
41
|
+
##### N
|
|
42
|
+
|
|
43
|
+
`N` = `unknown`
|
|
44
|
+
|
|
45
|
+
***
|
|
46
|
+
|
|
47
|
+
### StrictNonUndefined\<T, N\>
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
type StrictNonUndefined<T, N> = undefined extends T ? NotUndefined<T> : N;
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Defined in: [packages/utils/src/assertions.ts:13](https://github.com/lucasols/utils/blob/main/packages/utils/src/assertions.ts#L13)
|
|
54
|
+
|
|
55
|
+
#### Type Parameters
|
|
56
|
+
|
|
57
|
+
##### T
|
|
58
|
+
|
|
59
|
+
`T`
|
|
60
|
+
|
|
61
|
+
##### N
|
|
62
|
+
|
|
63
|
+
`N` = `unknown`
|