@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.
- 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-ADM37GSC.js → chunk-7L4KCZJJ.js} +12 -10
- package/dist/{chunk-KW55OTUG.js → chunk-B3KFV2MH.js} +2 -2
- package/dist/chunk-GMJTLFM6.js +60 -0
- package/dist/{chunk-GHAQOUA6.js → chunk-Y45CE75W.js} +22 -1
- 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.cjs +15 -0
- package/dist/typingFnUtils.d.cts +34 -7
- package/dist/typingFnUtils.d.ts +34 -7
- package/dist/typingFnUtils.js +18 -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/docs/testUtils.md
DELETED
|
@@ -1,382 +0,0 @@
|
|
|
1
|
-
[**@ls-stack/utils**](README.md)
|
|
2
|
-
|
|
3
|
-
***
|
|
4
|
-
|
|
5
|
-
[@ls-stack/utils](modules.md) / testUtils
|
|
6
|
-
|
|
7
|
-
# testUtils
|
|
8
|
-
|
|
9
|
-
## Functions
|
|
10
|
-
|
|
11
|
-
### compactSnapshot()
|
|
12
|
-
|
|
13
|
-
```ts
|
|
14
|
-
function compactSnapshot(value, options): string;
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
Defined in: [packages/utils/src/testUtils.ts:364](https://github.com/lucasols/utils/blob/main/packages/utils/src/testUtils.ts#L364)
|
|
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
|
|
46
|
-
- Expanding the patterns with parentheses:
|
|
47
|
-
- `'prop.test.(prop1|prop2|prop3.prop4)'` - Will produce `prop.test.prop1`, `prop.test.prop2`, and `prop.test.prop3.prop4`
|
|
48
|
-
- Array filtering by value:
|
|
49
|
-
- `'users[%name="John"]'` - Filters the `users` with the `name` property equal to `John`
|
|
50
|
-
- `'users[%name="John" | "Jane"]'` - Filters the `users` with the `name` property equal to `John` or `Jane`
|
|
51
|
-
- `'users[%name="John" | "Jane" && %age=20]'` - AND and OR are supported by using `&&` and `||`, nesting logical operators is not supported yet
|
|
52
|
-
- `'users[%config.name="John" | "Jane"]'` - Dot notation is supported
|
|
53
|
-
|
|
54
|
-
Check more supported patterns in [filterObjectOrArrayKeys](filterObjectOrArrayKeys.md#filterobjectorarraykeys) docs.
|
|
55
|
-
|
|
56
|
-
#### Parameters
|
|
57
|
-
|
|
58
|
-
##### value
|
|
59
|
-
|
|
60
|
-
`unknown`
|
|
61
|
-
|
|
62
|
-
The value to snapshot.
|
|
63
|
-
|
|
64
|
-
##### options
|
|
65
|
-
|
|
66
|
-
[`YamlStringifyOptions`](yamlStringify.md#yamlstringifyoptions) & `object` = `{}`
|
|
67
|
-
|
|
68
|
-
The options for the snapshot.
|
|
69
|
-
|
|
70
|
-
#### Returns
|
|
71
|
-
|
|
72
|
-
`string`
|
|
73
|
-
|
|
74
|
-
The compact snapshot of the value.
|
|
75
|
-
|
|
76
|
-
***
|
|
77
|
-
|
|
78
|
-
### createLoggerStore()
|
|
79
|
-
|
|
80
|
-
```ts
|
|
81
|
-
function createLoggerStore(__namedParameters): object;
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
Defined in: [packages/utils/src/testUtils.ts:11](https://github.com/lucasols/utils/blob/main/packages/utils/src/testUtils.ts#L11)
|
|
85
|
-
|
|
86
|
-
#### Parameters
|
|
87
|
-
|
|
88
|
-
##### \_\_namedParameters
|
|
89
|
-
|
|
90
|
-
###### arrays?
|
|
91
|
-
|
|
92
|
-
\| `"length"`
|
|
93
|
-
\| `"all"`
|
|
94
|
-
\| `"firstAndLast"`
|
|
95
|
-
\| \{
|
|
96
|
-
`firstNItems`: `number`;
|
|
97
|
-
\} = `...`
|
|
98
|
-
|
|
99
|
-
###### changesOnly?
|
|
100
|
-
|
|
101
|
-
`boolean` = `false`
|
|
102
|
-
|
|
103
|
-
###### filterKeys?
|
|
104
|
-
|
|
105
|
-
`string`[]
|
|
106
|
-
|
|
107
|
-
###### fromLastSnapshot?
|
|
108
|
-
|
|
109
|
-
`boolean` = `false`
|
|
110
|
-
|
|
111
|
-
###### maxLineLengthBeforeSplit?
|
|
112
|
-
|
|
113
|
-
`number` = `80`
|
|
114
|
-
|
|
115
|
-
###### rejectKeys?
|
|
116
|
-
|
|
117
|
-
`string`[]
|
|
118
|
-
|
|
119
|
-
###### splitLongLines?
|
|
120
|
-
|
|
121
|
-
`true` = `true`
|
|
122
|
-
|
|
123
|
-
###### useEmojiForBooleans?
|
|
124
|
-
|
|
125
|
-
`boolean` = `true`
|
|
126
|
-
|
|
127
|
-
#### Returns
|
|
128
|
-
|
|
129
|
-
`object`
|
|
130
|
-
|
|
131
|
-
##### add()
|
|
132
|
-
|
|
133
|
-
```ts
|
|
134
|
-
add: (render) => void;
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
###### Parameters
|
|
138
|
-
|
|
139
|
-
###### render
|
|
140
|
-
|
|
141
|
-
`Record`\<`string`, `unknown`\> | readonly `Record`\<`string`, `unknown`\>[]
|
|
142
|
-
|
|
143
|
-
###### Returns
|
|
144
|
-
|
|
145
|
-
`void`
|
|
146
|
-
|
|
147
|
-
##### addMark()
|
|
148
|
-
|
|
149
|
-
```ts
|
|
150
|
-
addMark: (label) => void;
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
###### Parameters
|
|
154
|
-
|
|
155
|
-
###### label
|
|
156
|
-
|
|
157
|
-
`string`
|
|
158
|
-
|
|
159
|
-
###### Returns
|
|
160
|
-
|
|
161
|
-
`void`
|
|
162
|
-
|
|
163
|
-
##### getSnapshot()
|
|
164
|
-
|
|
165
|
-
```ts
|
|
166
|
-
getSnapshot: (__namedParameters) => string;
|
|
167
|
-
```
|
|
168
|
-
|
|
169
|
-
###### Parameters
|
|
170
|
-
|
|
171
|
-
###### \_\_namedParameters
|
|
172
|
-
|
|
173
|
-
###### arrays?
|
|
174
|
-
|
|
175
|
-
\| `"length"`
|
|
176
|
-
\| `"all"`
|
|
177
|
-
\| `"firstAndLast"`
|
|
178
|
-
\| \{
|
|
179
|
-
`firstNItems`: `number`;
|
|
180
|
-
\} = `defaultArrays`
|
|
181
|
-
|
|
182
|
-
###### changesOnly?
|
|
183
|
-
|
|
184
|
-
`boolean` = `defaultChangesOnly`
|
|
185
|
-
|
|
186
|
-
###### filterKeys?
|
|
187
|
-
|
|
188
|
-
`string`[] = `defaultFilterKeys`
|
|
189
|
-
|
|
190
|
-
###### fromLastSnapshot?
|
|
191
|
-
|
|
192
|
-
`boolean` = `defaultFromLastSnapshot`
|
|
193
|
-
|
|
194
|
-
###### includeLastSnapshotEndMark?
|
|
195
|
-
|
|
196
|
-
`boolean` = `true`
|
|
197
|
-
|
|
198
|
-
###### maxLineLengthBeforeSplit?
|
|
199
|
-
|
|
200
|
-
`number` = `defaultMaxLineLengthBeforeSplit`
|
|
201
|
-
|
|
202
|
-
###### rejectKeys?
|
|
203
|
-
|
|
204
|
-
`string`[] = `defaultRejectKeys`
|
|
205
|
-
|
|
206
|
-
###### splitLongLines?
|
|
207
|
-
|
|
208
|
-
`boolean` = `defaultSplitLongLines`
|
|
209
|
-
|
|
210
|
-
###### useEmojiForBooleans?
|
|
211
|
-
|
|
212
|
-
`boolean` = `defaultUseEmojiForBooleans`
|
|
213
|
-
|
|
214
|
-
###### Returns
|
|
215
|
-
|
|
216
|
-
`string`
|
|
217
|
-
|
|
218
|
-
##### logsCount()
|
|
219
|
-
|
|
220
|
-
```ts
|
|
221
|
-
logsCount: () => number;
|
|
222
|
-
```
|
|
223
|
-
|
|
224
|
-
###### Returns
|
|
225
|
-
|
|
226
|
-
`number`
|
|
227
|
-
|
|
228
|
-
##### reset()
|
|
229
|
-
|
|
230
|
-
```ts
|
|
231
|
-
reset: (keepLastRender) => void;
|
|
232
|
-
```
|
|
233
|
-
|
|
234
|
-
###### Parameters
|
|
235
|
-
|
|
236
|
-
###### keepLastRender
|
|
237
|
-
|
|
238
|
-
`boolean` = `false`
|
|
239
|
-
|
|
240
|
-
###### Returns
|
|
241
|
-
|
|
242
|
-
`void`
|
|
243
|
-
|
|
244
|
-
##### waitNextLog()
|
|
245
|
-
|
|
246
|
-
```ts
|
|
247
|
-
waitNextLog: (timeout) => Promise<void>;
|
|
248
|
-
```
|
|
249
|
-
|
|
250
|
-
###### Parameters
|
|
251
|
-
|
|
252
|
-
###### timeout
|
|
253
|
-
|
|
254
|
-
`number` = `50`
|
|
255
|
-
|
|
256
|
-
###### Returns
|
|
257
|
-
|
|
258
|
-
`Promise`\<`void`\>
|
|
259
|
-
|
|
260
|
-
##### changesSnapshot
|
|
261
|
-
|
|
262
|
-
###### Get Signature
|
|
263
|
-
|
|
264
|
-
```ts
|
|
265
|
-
get changesSnapshot(): string;
|
|
266
|
-
```
|
|
267
|
-
|
|
268
|
-
###### Returns
|
|
269
|
-
|
|
270
|
-
`string`
|
|
271
|
-
|
|
272
|
-
##### rendersTime
|
|
273
|
-
|
|
274
|
-
###### Get Signature
|
|
275
|
-
|
|
276
|
-
```ts
|
|
277
|
-
get rendersTime(): number[];
|
|
278
|
-
```
|
|
279
|
-
|
|
280
|
-
###### Returns
|
|
281
|
-
|
|
282
|
-
`number`[]
|
|
283
|
-
|
|
284
|
-
##### snapshot
|
|
285
|
-
|
|
286
|
-
###### Get Signature
|
|
287
|
-
|
|
288
|
-
```ts
|
|
289
|
-
get snapshot(): string;
|
|
290
|
-
```
|
|
291
|
-
|
|
292
|
-
###### Returns
|
|
293
|
-
|
|
294
|
-
`string`
|
|
295
|
-
|
|
296
|
-
##### snapshotFromLast
|
|
297
|
-
|
|
298
|
-
###### Get Signature
|
|
299
|
-
|
|
300
|
-
```ts
|
|
301
|
-
get snapshotFromLast(): string;
|
|
302
|
-
```
|
|
303
|
-
|
|
304
|
-
###### Returns
|
|
305
|
-
|
|
306
|
-
`string`
|
|
307
|
-
|
|
308
|
-
***
|
|
309
|
-
|
|
310
|
-
### getResultFn()
|
|
311
|
-
|
|
312
|
-
```ts
|
|
313
|
-
function getResultFn<T>(fnGetter, wrapper?): T;
|
|
314
|
-
```
|
|
315
|
-
|
|
316
|
-
Defined in: [packages/utils/src/testUtils.ts:277](https://github.com/lucasols/utils/blob/main/packages/utils/src/testUtils.ts#L277)
|
|
317
|
-
|
|
318
|
-
#### Type Parameters
|
|
319
|
-
|
|
320
|
-
##### T
|
|
321
|
-
|
|
322
|
-
`T` *extends* (...`args`) => `any`
|
|
323
|
-
|
|
324
|
-
#### Parameters
|
|
325
|
-
|
|
326
|
-
##### fnGetter
|
|
327
|
-
|
|
328
|
-
() => `T`
|
|
329
|
-
|
|
330
|
-
##### wrapper?
|
|
331
|
-
|
|
332
|
-
(...`args`) => `any`
|
|
333
|
-
|
|
334
|
-
#### Returns
|
|
335
|
-
|
|
336
|
-
`T`
|
|
337
|
-
|
|
338
|
-
***
|
|
339
|
-
|
|
340
|
-
### waitController()
|
|
341
|
-
|
|
342
|
-
```ts
|
|
343
|
-
function waitController(): object;
|
|
344
|
-
```
|
|
345
|
-
|
|
346
|
-
Defined in: [packages/utils/src/testUtils.ts:292](https://github.com/lucasols/utils/blob/main/packages/utils/src/testUtils.ts#L292)
|
|
347
|
-
|
|
348
|
-
#### Returns
|
|
349
|
-
|
|
350
|
-
`object`
|
|
351
|
-
|
|
352
|
-
##### stopWaiting()
|
|
353
|
-
|
|
354
|
-
```ts
|
|
355
|
-
stopWaiting: () => void;
|
|
356
|
-
```
|
|
357
|
-
|
|
358
|
-
###### Returns
|
|
359
|
-
|
|
360
|
-
`void`
|
|
361
|
-
|
|
362
|
-
##### stopWaitingAfter()
|
|
363
|
-
|
|
364
|
-
```ts
|
|
365
|
-
stopWaitingAfter: (ms) => void;
|
|
366
|
-
```
|
|
367
|
-
|
|
368
|
-
###### Parameters
|
|
369
|
-
|
|
370
|
-
###### ms
|
|
371
|
-
|
|
372
|
-
`number`
|
|
373
|
-
|
|
374
|
-
###### Returns
|
|
375
|
-
|
|
376
|
-
`void`
|
|
377
|
-
|
|
378
|
-
##### wait
|
|
379
|
-
|
|
380
|
-
```ts
|
|
381
|
-
wait: Promise<void>;
|
|
382
|
-
```
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
[**@ls-stack/utils**](../README.md)
|
|
2
|
-
|
|
3
|
-
***
|
|
4
|
-
|
|
5
|
-
[@ls-stack/utils](../modules.md) / [throttle](README.md) / \<internal\>
|
|
6
|
-
|
|
7
|
-
# \<internal\>
|
|
8
|
-
|
|
9
|
-
## Interfaces
|
|
10
|
-
|
|
11
|
-
### ThrottleSettings
|
|
12
|
-
|
|
13
|
-
Defined in: [packages/utils/src/throttle.ts:7](https://github.com/lucasols/utils/blob/main/packages/utils/src/throttle.ts#L7)
|
|
14
|
-
|
|
15
|
-
#### Properties
|
|
16
|
-
|
|
17
|
-
##### leading?
|
|
18
|
-
|
|
19
|
-
```ts
|
|
20
|
-
optional leading: boolean;
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
Defined in: [packages/utils/src/throttle.ts:12](https://github.com/lucasols/utils/blob/main/packages/utils/src/throttle.ts#L12)
|
|
24
|
-
|
|
25
|
-
Specify invoking on the leading edge of the timeout.
|
|
26
|
-
|
|
27
|
-
###### Default
|
|
28
|
-
|
|
29
|
-
```ts
|
|
30
|
-
true
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
##### trailing?
|
|
34
|
-
|
|
35
|
-
```ts
|
|
36
|
-
optional trailing: boolean;
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
Defined in: [packages/utils/src/throttle.ts:17](https://github.com/lucasols/utils/blob/main/packages/utils/src/throttle.ts#L17)
|
|
40
|
-
|
|
41
|
-
Specify invoking on the trailing edge of the timeout.
|
|
42
|
-
|
|
43
|
-
###### Default
|
|
44
|
-
|
|
45
|
-
```ts
|
|
46
|
-
true
|
|
47
|
-
```
|
package/docs/throttle/README.md
DELETED
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
[**@ls-stack/utils**](../README.md)
|
|
2
|
-
|
|
3
|
-
***
|
|
4
|
-
|
|
5
|
-
[@ls-stack/utils](../modules.md) / throttle
|
|
6
|
-
|
|
7
|
-
# throttle
|
|
8
|
-
|
|
9
|
-
## Modules
|
|
10
|
-
|
|
11
|
-
- [\<internal\>](-internal-.md)
|
|
12
|
-
|
|
13
|
-
## Functions
|
|
14
|
-
|
|
15
|
-
### createThrottledFunctionFactory()
|
|
16
|
-
|
|
17
|
-
```ts
|
|
18
|
-
function createThrottledFunctionFactory<T, R>(
|
|
19
|
-
wait,
|
|
20
|
-
callback,
|
|
21
|
-
options?): object;
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
Defined in: [packages/utils/src/throttle.ts:104](https://github.com/lucasols/utils/blob/main/packages/utils/src/throttle.ts#L104)
|
|
25
|
-
|
|
26
|
-
Creates a factory for throttled functions that caches throttled instances based on function arguments.
|
|
27
|
-
Each unique set of arguments gets its own throttled function instance, allowing for fine-grained
|
|
28
|
-
throttling control per argument combination.
|
|
29
|
-
|
|
30
|
-
This is useful when you want to throttle calls to the same function but with different parameters
|
|
31
|
-
independently. For example, throttling API calls per user ID or throttling UI updates per component.
|
|
32
|
-
|
|
33
|
-
#### Type Parameters
|
|
34
|
-
|
|
35
|
-
##### T
|
|
36
|
-
|
|
37
|
-
`T` *extends* `undefined` \| `null` \| `string` \| `number` \| `boolean`
|
|
38
|
-
|
|
39
|
-
The type of arguments the callback function accepts
|
|
40
|
-
|
|
41
|
-
##### R
|
|
42
|
-
|
|
43
|
-
`R`
|
|
44
|
-
|
|
45
|
-
The return type of the callback function
|
|
46
|
-
|
|
47
|
-
#### Parameters
|
|
48
|
-
|
|
49
|
-
##### wait
|
|
50
|
-
|
|
51
|
-
`number`
|
|
52
|
-
|
|
53
|
-
The number of milliseconds to throttle invocations to
|
|
54
|
-
|
|
55
|
-
##### callback
|
|
56
|
-
|
|
57
|
-
(...`args`) => `R`
|
|
58
|
-
|
|
59
|
-
The function to throttle
|
|
60
|
-
|
|
61
|
-
##### options?
|
|
62
|
-
|
|
63
|
-
[`ThrottleSettings`](-internal-.md#throttlesettings)
|
|
64
|
-
|
|
65
|
-
The throttle options (leading/trailing behavior)
|
|
66
|
-
|
|
67
|
-
#### Returns
|
|
68
|
-
|
|
69
|
-
`object`
|
|
70
|
-
|
|
71
|
-
An object with a `call` method that accepts the callback arguments
|
|
72
|
-
|
|
73
|
-
##### call()
|
|
74
|
-
|
|
75
|
-
```ts
|
|
76
|
-
call: (...args) => undefined | R;
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
###### Parameters
|
|
80
|
-
|
|
81
|
-
###### args
|
|
82
|
-
|
|
83
|
-
...`T`[]
|
|
84
|
-
|
|
85
|
-
###### Returns
|
|
86
|
-
|
|
87
|
-
`undefined` \| `R`
|
|
88
|
-
|
|
89
|
-
#### Examples
|
|
90
|
-
|
|
91
|
-
```ts
|
|
92
|
-
const apiThrottle = createThrottledFunctionFactory(
|
|
93
|
-
1000,
|
|
94
|
-
(userId: string, action: string) => callAPI(userId, action)
|
|
95
|
-
);
|
|
96
|
-
|
|
97
|
-
// Each user gets their own throttled instance
|
|
98
|
-
apiThrottle.call('user1', 'update'); // Executes immediately
|
|
99
|
-
apiThrottle.call('user2', 'update'); // Executes immediately (different user)
|
|
100
|
-
apiThrottle.call('user1', 'update'); // Throttled (same user)
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
```ts
|
|
104
|
-
// Throttle UI updates per component
|
|
105
|
-
const updateThrottle = createThrottledFunctionFactory(
|
|
106
|
-
100,
|
|
107
|
-
(componentId: string, data: any) => updateComponent(componentId, data)
|
|
108
|
-
);
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
***
|
|
112
|
-
|
|
113
|
-
### throttle()
|
|
114
|
-
|
|
115
|
-
```ts
|
|
116
|
-
function throttle<T>(
|
|
117
|
-
func,
|
|
118
|
-
wait,
|
|
119
|
-
options?): DebouncedFunc<T>;
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
Defined in: [packages/utils/src/throttle.ts:51](https://github.com/lucasols/utils/blob/main/packages/utils/src/throttle.ts#L51)
|
|
123
|
-
|
|
124
|
-
Creates a throttled function that only invokes the provided function at most once per every `wait` milliseconds.
|
|
125
|
-
The throttled function comes with a `cancel` method to cancel delayed invocations and a `flush` method to immediately invoke them.
|
|
126
|
-
|
|
127
|
-
Throttling is useful for rate-limiting events that fire frequently, like scroll or resize handlers.
|
|
128
|
-
Unlike debouncing, throttling guarantees the function is called at regular intervals.
|
|
129
|
-
|
|
130
|
-
#### Type Parameters
|
|
131
|
-
|
|
132
|
-
##### T
|
|
133
|
-
|
|
134
|
-
`T` *extends* [`__LEGIT_ANY_FUNCTION__`](../saferTyping.md#__legit_any_function__)
|
|
135
|
-
|
|
136
|
-
The type of the function to throttle
|
|
137
|
-
|
|
138
|
-
#### Parameters
|
|
139
|
-
|
|
140
|
-
##### func
|
|
141
|
-
|
|
142
|
-
`T`
|
|
143
|
-
|
|
144
|
-
The function to throttle
|
|
145
|
-
|
|
146
|
-
##### wait
|
|
147
|
-
|
|
148
|
-
`number`
|
|
149
|
-
|
|
150
|
-
The number of milliseconds to throttle invocations to
|
|
151
|
-
|
|
152
|
-
##### options?
|
|
153
|
-
|
|
154
|
-
[`ThrottleSettings`](-internal-.md#throttlesettings)
|
|
155
|
-
|
|
156
|
-
The options object
|
|
157
|
-
|
|
158
|
-
#### Returns
|
|
159
|
-
|
|
160
|
-
[`DebouncedFunc`](../debounce.md#debouncedfunc)\<`T`\>
|
|
161
|
-
|
|
162
|
-
Returns the new throttled function
|
|
163
|
-
|
|
164
|
-
#### Examples
|
|
165
|
-
|
|
166
|
-
```ts
|
|
167
|
-
const throttledSave = throttle(saveData, 1000);
|
|
168
|
-
|
|
169
|
-
// Will only call saveData at most once per second
|
|
170
|
-
throttledSave();
|
|
171
|
-
throttledSave();
|
|
172
|
-
throttledSave();
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
```ts
|
|
176
|
-
// Only invoke on trailing edge
|
|
177
|
-
const throttledHandler = throttle(handleScroll, 100, { leading: false });
|
|
178
|
-
```
|