radashi 12.1.0 → 12.2.0-beta.0dc9c8a

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 (48) hide show
  1. package/LICENSE.md +2 -1
  2. package/README.md +124 -17
  3. package/dist/radashi.cjs +1589 -0
  4. package/dist/radashi.d.cts +1212 -0
  5. package/dist/radashi.d.ts +1212 -0
  6. package/dist/radashi.js +1452 -0
  7. package/package.json +51 -40
  8. package/dist/cjs/array.cjs +0 -281
  9. package/dist/cjs/array.cjs.map +0 -1
  10. package/dist/cjs/async.cjs +0 -169
  11. package/dist/cjs/async.cjs.map +0 -1
  12. package/dist/cjs/curry.cjs +0 -113
  13. package/dist/cjs/curry.cjs.map +0 -1
  14. package/dist/cjs/index.cjs +0 -109
  15. package/dist/cjs/index.cjs.map +0 -1
  16. package/dist/cjs/number.cjs +0 -34
  17. package/dist/cjs/number.cjs.map +0 -1
  18. package/dist/cjs/object.cjs +0 -204
  19. package/dist/cjs/object.cjs.map +0 -1
  20. package/dist/cjs/random.cjs +0 -34
  21. package/dist/cjs/random.cjs.map +0 -1
  22. package/dist/cjs/series.cjs +0 -62
  23. package/dist/cjs/series.cjs.map +0 -1
  24. package/dist/cjs/string.cjs +0 -72
  25. package/dist/cjs/string.cjs.map +0 -1
  26. package/dist/cjs/typed.cjs +0 -104
  27. package/dist/cjs/typed.cjs.map +0 -1
  28. package/dist/esm/array.mjs +0 -251
  29. package/dist/esm/array.mjs.map +0 -1
  30. package/dist/esm/async.mjs +0 -158
  31. package/dist/esm/async.mjs.map +0 -1
  32. package/dist/esm/curry.mjs +0 -103
  33. package/dist/esm/curry.mjs.map +0 -1
  34. package/dist/esm/index.mjs +0 -10
  35. package/dist/esm/index.mjs.map +0 -1
  36. package/dist/esm/number.mjs +0 -30
  37. package/dist/esm/number.mjs.map +0 -1
  38. package/dist/esm/object.mjs +0 -186
  39. package/dist/esm/object.mjs.map +0 -1
  40. package/dist/esm/random.mjs +0 -29
  41. package/dist/esm/random.mjs.map +0 -1
  42. package/dist/esm/series.mjs +0 -60
  43. package/dist/esm/series.mjs.map +0 -1
  44. package/dist/esm/string.mjs +0 -63
  45. package/dist/esm/string.mjs.map +0 -1
  46. package/dist/esm/typed.mjs +0 -90
  47. package/dist/esm/typed.mjs.map +0 -1
  48. package/dist/index.d.ts +0 -682
@@ -0,0 +1,1212 @@
1
+ /**
2
+ * Sort an array without modifying it and return the newly sorted
3
+ * value. Allows for a string sorting value.
4
+ */
5
+ declare function alphabetical<T>(array: readonly T[], getter: (item: T) => string, direction?: 'asc' | 'desc'): T[];
6
+
7
+ /**
8
+ * Go through a list of items, starting with the first item, and
9
+ * comparing with the second. Keep the one you want then compare that
10
+ * to the next item in the list with the same
11
+ *
12
+ * ```ts
13
+ * boil([1, 2, 3, 0], (a, b) => a > b ? a : b) // 3
14
+ * ```
15
+ */
16
+ declare function boil<T>(array: readonly T[], compareFunc: (a: T, b: T) => T): T | null;
17
+
18
+ /**
19
+ * Splits a single list into many lists of the desired size.
20
+ *
21
+ * ```ts
22
+ * cluster([1, 2, 3, 4, 5, 6], 2)
23
+ * // [[1, 2], [3, 4], [5, 6]]
24
+ * ```
25
+ */
26
+ declare function cluster<T>(array: readonly T[], size?: number): T[][];
27
+
28
+ /**
29
+ * Counts the occurrences of each unique value returned by the `identity`
30
+ * function when applied to each item in the array.
31
+ *
32
+ * ```ts
33
+ * counting([1, 2, 3, 4], (n) => n % 2 === 0 ? 'even' : 'odd')
34
+ * // { even: 2, odd: 2 }
35
+ * ```
36
+ */
37
+ declare function counting<T, TId extends string | number | symbol>(array: readonly T[], identity: (item: T) => TId): Record<TId, number>;
38
+
39
+ /**
40
+ * Returns all items from the first list that do not exist in the
41
+ * second list.
42
+ *
43
+ * ```ts
44
+ * diff([1, 2, 3, 4], [2, 4])
45
+ * // [1, 3]
46
+ *
47
+ * diff([{a:1}, {a:2}, {a:3}], [{a:2}, {a:4}], (n) => n.a)
48
+ * // [{a:1}, {a:3}]
49
+ * ```
50
+ */
51
+ declare function diff<T>(root: readonly T[], other: readonly T[], identity?: (item: T) => string | number | symbol): T[];
52
+
53
+ /**
54
+ * Get the first item in an array or a default value
55
+ *
56
+ * ```ts
57
+ * first([1, 2, 3, 4])
58
+ * // 1
59
+ *
60
+ * first([], 0)
61
+ * // 0
62
+ * ```
63
+ */
64
+ declare function first<T>(array: readonly T[]): T | undefined;
65
+ declare function first<T, U>(array: readonly T[], defaultValue: U): T | U;
66
+
67
+ /**
68
+ * Given an array of arrays, returns a single dimensional array with
69
+ * all items in it.
70
+ *
71
+ * ```ts
72
+ * flat([[1, 2], [[3], 4], [5]])
73
+ * // [1, 2, [3], 4, 5]
74
+ * ```
75
+ */
76
+ declare function flat<T>(lists: readonly T[][]): T[];
77
+
78
+ /**
79
+ * Split an array into two array based on a true/false condition
80
+ * function
81
+ *
82
+ * ```ts
83
+ * fork([1, 2, 3, 4], (n) => n % 2 === 0)
84
+ * // [[2, 4], [1, 3]]
85
+ * ```
86
+ */
87
+ declare function fork<T>(array: readonly T[], condition: (item: T) => boolean): [T[], T[]];
88
+
89
+ /**
90
+ * Sorts an `array` of items into groups. The return value is a map
91
+ * where the keys are the group IDs the given `getGroupId` function
92
+ * produced and the value is an array of each item in that group.
93
+ *
94
+ * ```ts
95
+ * group([1, 2, 3, 4], (n) => n % 2 === 0 ? 'even' : 'odd')
96
+ * // { even: [2], odd: [1, 3, 4] }
97
+ * ```
98
+ */
99
+ declare function group<T, Key extends string | number | symbol>(array: readonly T[], getGroupId: (item: T) => Key): {
100
+ [K in Key]?: T[];
101
+ };
102
+
103
+ /**
104
+ * Given two arrays, returns true if any elements intersect.
105
+ *
106
+ * ```ts
107
+ * intersects([1, 2, 3], [4, 5, 6])
108
+ * // false
109
+ *
110
+ * intersects([1, 0, 0], [0, 1], (n) => n > 1)
111
+ * // true
112
+ * ```
113
+ */
114
+ declare function intersects<T, K>(listA: readonly T[], listB: readonly T[], identity?: (t: T) => K): boolean;
115
+
116
+ /**
117
+ * Like a reduce but does not require an array. Only need a number and
118
+ * will iterate the function as many times as specified.
119
+ *
120
+ * NOTE: This is NOT zero indexed. If you pass count=5 you will get 1,
121
+ * 2, 3, 4, 5 iteration in the callback function
122
+ *
123
+ * ```ts
124
+ * iterate(3, (total, i) => total + i, 0)
125
+ * // 6
126
+ * ```
127
+ */
128
+ declare function iterate<T>(count: number, func: (currentValue: T, iteration: number) => T, initValue: T): T;
129
+
130
+ /**
131
+ * Get the last item in an array or a default value
132
+ *
133
+ * ```ts
134
+ * last([1, 2, 3, 4])
135
+ * // 4
136
+ *
137
+ * last([], 0)
138
+ * // 0
139
+ * ```
140
+ */
141
+ declare function last<T>(array: readonly T[]): T | undefined;
142
+ declare function last<T, U>(array: readonly T[], defaultValue: U): T | U;
143
+
144
+ /**
145
+ * Creates a list of given start, end, value, and step parameters.
146
+ *
147
+ * ```ts
148
+ * list(3) // 0, 1, 2, 3
149
+ * list(0, 3) // 0, 1, 2, 3
150
+ * list(0, 3, 'y') // y, y, y, y
151
+ * list(0, 3, () => 'y') // y, y, y, y
152
+ * list(0, 3, i => i) // 0, 1, 2, 3
153
+ * list(0, 3, i => `y${i}`) // y0, y1, y2, y3
154
+ * list(0, 3, obj) // obj, obj, obj, obj
155
+ * list(0, 6, i => i, 2) // 0, 2, 4, 6
156
+ * ```
157
+ */
158
+ declare function list<T = number>(startOrLength: number, end?: number, valueOrMapper?: T | ((i: number) => T), step?: number): T[];
159
+
160
+ declare function mapify<T, Key, Value = T>(array: readonly T[], getKey: (item: T) => Key, getValue?: (item: T) => Value): Map<Key, Value>;
161
+
162
+ /**
163
+ * Max gets the greatest value from a list
164
+ *
165
+ * ```ts
166
+ * max([2, 3, 5]) // => 5
167
+ * max([{ num: 1 }, { num: 2 }], x => x.num) // => { num: 2 }
168
+ * ```
169
+ */
170
+ declare function max(array: readonly [number, ...number[]]): number;
171
+ declare function max(array: readonly number[]): number | null;
172
+ declare function max<T>(array: readonly T[], getter: (item: T) => number): T | null;
173
+
174
+ /**
175
+ * Given two arrays of the same type, iterate the first list and
176
+ * replace items matched by the `matcher` function in the first place.
177
+ * The given arrays are never modified.
178
+ *
179
+ * ```ts
180
+ * merge(
181
+ * [{id: 1}, {id: 2}],
182
+ * [{id: 3}, {id: 1, name: 'John'}],
183
+ * (obj) => obj.id
184
+ * )
185
+ * // [{id: 1, name: 'John'}, {id: 2}]
186
+ * ```
187
+ */
188
+ declare function merge<T>(prev: readonly T[], array: readonly T[], toKey: (item: T) => any): T[];
189
+
190
+ /**
191
+ * Min gets the smallest value from a list
192
+ *
193
+ * ```ts
194
+ * min([1, 2, 3, 4]) // => 1
195
+ * min([{ num: 1 }, { num: 2 }], x => x.num) // => { num: 1 }
196
+ * ```
197
+ */
198
+ declare function min(array: readonly [number, ...number[]]): number;
199
+ declare function min(array: readonly number[]): number | null;
200
+ declare function min<T>(array: readonly T[], getter: (item: T) => number): T | null;
201
+
202
+ /**
203
+ * Convert an array to a dictionary by mapping each item into a
204
+ * dictionary key & value
205
+ *
206
+ * ```ts
207
+ * objectify([1, 2, 3], (n) => '#' + n)
208
+ * // { '#1': 1, '#2': 2, '#3': 3 }
209
+ *
210
+ * objectify(
211
+ * [{id: 1, name: 'John'}, {id: 2, name: 'Jane'}],
212
+ * (obj) => obj.id,
213
+ * (obj) => obj.name
214
+ * )
215
+ * // { 1: 'John', 2: 'Jane' }
216
+ * ```
217
+ */
218
+ declare function objectify<T, Key extends string | number | symbol, Value = T>(array: readonly T[], getKey: (item: T) => Key, getValue?: (item: T) => Value): Record<Key, Value>;
219
+
220
+ /**
221
+ * Creates a generator that will produce an iteration through the
222
+ * range of number as requested.
223
+ *
224
+ * ```ts
225
+ * range(3) // yields 0, 1, 2, 3
226
+ * range(0, 3) // yields 0, 1, 2, 3
227
+ * range(0, 3, 'y') // yields y, y, y, y
228
+ * range(0, 3, () => 'y') // yields y, y, y, y
229
+ * range(0, 3, i => i) // yields 0, 1, 2, 3
230
+ * range(0, 3, i => `y${i}`) // yields y0, y1, y2, y3
231
+ * range(0, 3, obj) // yields obj, obj, obj, obj
232
+ * range(0, 6, i => i, 2) // yields 0, 2, 4, 6
233
+ * ```
234
+ */
235
+ declare function range<T = number>(startOrLength: number, end?: number, valueOrMapper?: T | ((i: number) => T), step?: number): Generator<T>;
236
+
237
+ /**
238
+ * Replace an element in an array with a new item without modifying
239
+ * the array and return the new value
240
+ *
241
+ * ```ts
242
+ * replace([1, 2, 3], 4, (n) => n === 2)
243
+ * // [1, 4, 3]
244
+ * ```
245
+ */
246
+ declare function replace<T>(array: readonly T[], newItem: T, match: (item: T, idx: number) => boolean): T[];
247
+
248
+ /**
249
+ * Replace the first occurrence of an item in an array where the
250
+ * `match` function returns true. If no items match, append the new
251
+ * item to the end of the list.
252
+ *
253
+ * ```ts
254
+ * replaceOrAppend([1, 2, 3], 4, (n) => n > 1)
255
+ * // [1, 4, 3]
256
+ *
257
+ * replaceOrAppend([1, 2, 3], 4, (n) => n > 100)
258
+ * // [1, 2, 3, 4]
259
+ * ```
260
+ */
261
+ declare function replaceOrAppend<T>(array: readonly T[], newItem: T, match: (a: T, idx: number) => boolean): T[];
262
+
263
+ /**
264
+ * Select performs a filter and a mapper inside of a reduce, only
265
+ * iterating the list one time. If condition is omitted, will
266
+ * select all mapped values that are non-nullish.
267
+ *
268
+ * ```ts
269
+ * select(
270
+ * [1, 2, 3, 4],
271
+ * x => x * x,
272
+ * x => x > 2
273
+ * )
274
+ * // => [9, 16]
275
+ * ```
276
+ */
277
+ declare function select<T, U>(array: readonly T[], mapper: (item: T, index: number) => U, condition: (item: T, index: number) => boolean): U[];
278
+ declare function select<T, U>(array: readonly T[], mapper: (item: T, index: number) => U | null | undefined): U[];
279
+
280
+ /**
281
+ * Select performs a find + map operation, short-circuiting on the first
282
+ * element that satisfies the prescribed condition. If condition is omitted,
283
+ * will select the first mapped value which is non-nullish.
284
+ *
285
+ * ```ts
286
+ * selectFirst(
287
+ * [1, 2, 3, 4],
288
+ * x => x * x,
289
+ * x => x > 2
290
+ * )
291
+ * // => 9
292
+ * ```
293
+ */
294
+ declare function selectFirst<T, U>(array: readonly T[], mapper: (item: T, index: number) => U, condition?: (item: T, index: number) => boolean): U | undefined;
295
+
296
+ /**
297
+ * Shifts array items by `n` steps. If `n` is greater than 0, items
298
+ * will shift `n` steps to the right. If `n` is less than 0, items
299
+ * will shift `n` steps to the left.
300
+ *
301
+ * ```ts
302
+ * shift([1, 2, 3], 1) // [3, 1, 2]
303
+ * shift([1, 2, 3], -1) // [2, 3, 1]
304
+ * ```
305
+ */
306
+ declare function shift<T>(arr: T[], n: number): T[];
307
+
308
+ type Falsy = null | undefined | false | '' | 0 | 0n;
309
+ /**
310
+ * Given a list returns a new list with only truthy values
311
+ *
312
+ * ```ts
313
+ * sift([0, 1, undefined, null, 2, false, 3, ''])
314
+ * // => [1, 2, 3]
315
+ * ```
316
+ */
317
+ declare function sift<T>(array: readonly (T | Falsy)[]): T[];
318
+
319
+ /**
320
+ * Sort an array without modifying it and return the newly sorted
321
+ * value
322
+ *
323
+ * ```ts
324
+ * const fish = [
325
+ * { name: 'Marlin', weight: 105 },
326
+ * { name: 'Bass', weight: 8 },
327
+ * { name: 'Trout', weight: 13 }
328
+ * ]
329
+ *
330
+ * sort(fish, f => f.weight) // => [Bass, Trout, Marlin]
331
+ * sort(fish, f => f.weight, true) // => [Marlin, Trout, Bass]
332
+ * ```
333
+ */
334
+ declare function sort<T>(array: readonly T[], getter: (item: T) => number, desc?: boolean): T[];
335
+
336
+ /**
337
+ * Sum all numbers in an array. Optionally provide a function to
338
+ * convert objects in the array to number values.
339
+ *
340
+ * ```ts
341
+ * sum([1, 2, 3])
342
+ * // => 6
343
+ *
344
+ * sum([
345
+ * {value: 1},
346
+ * {value: 2},
347
+ * {value: 3}
348
+ * ], (item) => item.value)
349
+ * // => 6
350
+ * ```
351
+ */
352
+ declare function sum<T extends number>(array: readonly T[]): number;
353
+ declare function sum<T extends object>(array: readonly T[], fn: (item: T) => number): number;
354
+
355
+ /**
356
+ * If the item matching the condition already exists in the list it
357
+ * will be removed. If it does not it will be added.
358
+ *
359
+ * ```ts
360
+ * toggle([1, 2, 3], 4) // => [1, 2, 3, 4]
361
+ * toggle([1, 2, 3], 2) // => [1, 3]
362
+ *
363
+ * toggle(
364
+ * [
365
+ * { id: 1 },
366
+ * { id: 2 },
367
+ * ],
368
+ * { id: 3 },
369
+ * (obj) => obj.id,
370
+ * { strategy: 'prepend' }
371
+ * )
372
+ * // => [{ id: 3 }, { id: 1 }, { id: 2 }]
373
+ * ```
374
+ */
375
+ declare function toggle<T>(array: readonly T[], item: T,
376
+ /**
377
+ * Converts an item of type T item into a value that can be checked
378
+ * for equality
379
+ */
380
+ toKey?: null | ((item: T, idx: number) => number | string | symbol), options?: {
381
+ strategy?: 'prepend' | 'append';
382
+ }): T[];
383
+
384
+ /**
385
+ * Given a list of items returns a new list with only unique items.
386
+ * Accepts an optional identity function to convert each item in the
387
+ * list to a comparable identity value
388
+ *
389
+ * ```ts
390
+ * unique([1, 1, 2, 2]) // => [1, 2]
391
+ * unique([1, 2, 3], (n) => n % 2) // => [1, 2]
392
+ * ```
393
+ */
394
+ declare function unique<T, K = T>(array: readonly T[], toKey?: (item: T) => K): T[];
395
+
396
+ /**
397
+ * Creates an array of ungrouped elements, where each resulting array
398
+ * contains all elements at a specific index from the input arrays.
399
+ * The first array contains all first elements, the second array
400
+ * contains all second elements, and so on.
401
+ *
402
+ * ```ts
403
+ * unzip([['a', 1, true], ['b', 2, false]])
404
+ * // [['a', 'b'], [1, 2], [true, false]]
405
+ * ```
406
+ */
407
+ declare function unzip<T>(arrays: readonly (readonly T[])[]): T[][];
408
+
409
+ /**
410
+ * Creates an array of grouped elements, the first of which contains
411
+ * the first elements of the given arrays, the second of which
412
+ * contains the second elements of the given arrays, and so on.
413
+ *
414
+ * ```ts
415
+ * zip(['a', 'b'], [1, 2], [true, false])
416
+ * // [['a', 1, true], ['b', 2, false]]
417
+ * ```
418
+ */
419
+ declare function zip<T1, T2, T3, T4, T5>(array1: readonly T1[], array2: readonly T2[], array3: readonly T3[], array4: readonly T4[], array5: readonly T5[]): [T1, T2, T3, T4, T5][];
420
+ declare function zip<T1, T2, T3, T4>(array1: readonly T1[], array2: readonly T2[], array3: readonly T3[], array4: readonly T4[]): [T1, T2, T3, T4][];
421
+ declare function zip<T1, T2, T3>(array1: readonly T1[], array2: readonly T2[], array3: readonly T3[]): [T1, T2, T3][];
422
+ declare function zip<T1, T2>(array1: readonly T1[], array2: readonly T2[]): [T1, T2][];
423
+
424
+ /**
425
+ * Creates an object mapping the specified keys to their corresponding
426
+ * values
427
+ *
428
+ * ```ts
429
+ * zipToObject(['a', 'b'], [1, 2])
430
+ * // { a: 1, b: 2 }
431
+ *
432
+ * zipToObject(['a', 'b'], (k, i) => k + i)
433
+ * // { a: 'a0', b: 'b1' }
434
+ *
435
+ * zipToObject(['a', 'b'], 1)
436
+ * // { a: 1, b: 1 }
437
+ * ```
438
+ */
439
+ declare function zipToObject<K extends string | number | symbol, V>(keys: K[], values: V | ((key: K, idx: number) => V) | V[]): Record<K, V>;
440
+
441
+ /**
442
+ * Support for the built-in AggregateError is still new. Node < 15
443
+ * doesn't have it so patching here.
444
+ * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AggregateError#browser_compatibility
445
+ */
446
+ declare class AggregateError extends Error {
447
+ errors: Error[];
448
+ constructor(errors?: Error[]);
449
+ }
450
+
451
+ type PromiseValues<T extends Promise<any>[]> = {
452
+ [K in keyof T]: T[K] extends Promise<infer U> ? U : never;
453
+ };
454
+ /**
455
+ * Functionally similar to `Promise.all` or `Promise.allSettled`. If
456
+ * any errors are thrown, all errors are gathered and thrown in an
457
+ * `AggregateError`.
458
+ *
459
+ * ```ts
460
+ * const [user] = await all([
461
+ * api.users.create(...),
462
+ * s3.buckets.create(...),
463
+ * slack.customerSuccessChannel.sendMessage(...)
464
+ * ])
465
+ * ```
466
+ */
467
+ declare function all<T extends [Promise<any>, ...Promise<any>[]]>(promises: T): Promise<PromiseValues<T>>;
468
+ declare function all<T extends Promise<any>[]>(promises: T): Promise<PromiseValues<T>>;
469
+ /**
470
+ * Functionally similar to `Promise.all` or `Promise.allSettled`. If
471
+ * any errors are thrown, all errors are gathered and thrown in an
472
+ * `AggregateError`.
473
+ *
474
+ * ```ts
475
+ * const { user } = await all({
476
+ * user: api.users.create(...),
477
+ * bucket: s3.buckets.create(...),
478
+ * message: slack.customerSuccessChannel.sendMessage(...)
479
+ * })
480
+ * ```
481
+ */
482
+ declare function all<T extends Record<string, Promise<any>>>(promises: T): Promise<{
483
+ [K in keyof T]: Awaited<T[K]>;
484
+ }>;
485
+
486
+ /**
487
+ * Useful when for script like things where cleanup should be done on
488
+ * fail or sucess no matter.
489
+ *
490
+ * You can call defer many times to register many defered functions
491
+ * that will all be called when the function exits in any state.
492
+ */
493
+ declare function defer<TResponse>(func: (register: (fn: (error?: any) => any, options?: {
494
+ rethrow?: boolean;
495
+ }) => void) => Promise<TResponse>): Promise<TResponse>;
496
+
497
+ /**
498
+ * A helper to try an async function that returns undefined if it
499
+ * fails.
500
+ *
501
+ * ```ts
502
+ * const result = await guard(fetchUsers)() ?? [];
503
+ * ```
504
+ */
505
+ declare function guard<TFunction extends () => any>(func: TFunction, shouldGuard?: (err: any) => boolean): ReturnType<TFunction> extends Promise<any> ? Promise<Awaited<ReturnType<TFunction>> | undefined> : ReturnType<TFunction> | undefined;
506
+
507
+ /**
508
+ * An async map function. Works like the built-in Array.map function
509
+ * but handles an async mapper function
510
+ */
511
+ declare function map<T, K>(array: readonly T[], asyncMapFunc: (item: T, index: number) => Promise<K>): Promise<K[]>;
512
+
513
+ /**
514
+ * Executes many async functions in parallel. Returns the results from
515
+ * all functions as an array. After all functions have resolved, if
516
+ * any errors were thrown, they are rethrown in an instance of
517
+ * AggregateError
518
+ */
519
+ declare function parallel<T, K>(limit: number, array: readonly T[], func: (item: T) => Promise<K>): Promise<K[]>;
520
+
521
+ /**
522
+ * An async reduce function. Works like the built-in Array.reduce
523
+ * function but handles an async reducer function
524
+ */
525
+ declare function reduce<T, K>(array: readonly T[], asyncReducer: (acc: K, item: T, index: number) => Promise<K>, initValue?: K): Promise<K>;
526
+
527
+ type RetryOptions = {
528
+ times?: number;
529
+ delay?: number | null;
530
+ backoff?: (count: number) => number;
531
+ };
532
+ /**
533
+ * Retries the given function the specified number of times.
534
+ */
535
+ declare function retry<TResponse>(options: RetryOptions, func: (exit: (err: any) => void) => Promise<TResponse>): Promise<TResponse>;
536
+
537
+ /**
538
+ * Async wait
539
+ */
540
+ declare function sleep(milliseconds: number): Promise<void>;
541
+
542
+ /**
543
+ * The result of a `tryit` function.
544
+ *
545
+ * If the function returns a promise, the result is a promise that
546
+ * resolves to an error-first callback-_like_ array response as
547
+ * `[Error, result]`.
548
+ *
549
+ * If the function returns a non-promise, the result is an error-first
550
+ * callback-_like_ array response as `[Error, result]`.
551
+ */
552
+ type TryitResult<Return> = Return extends Promise<any> ? Promise<[Error, undefined] | [undefined, Awaited<Return>]> : [Error, undefined] | [undefined, Return];
553
+ /**
554
+ * A helper to try an async function without forking the control flow.
555
+ * Returns an error-first callback-_like_ array response as `[Error,
556
+ * result]`
557
+ */
558
+ declare function tryit<Args extends any[], Return>(func: (...args: Args) => Return): (...args: Args) => TryitResult<Return>;
559
+
560
+ /**
561
+ * Make an object callable. Given an object and a function the
562
+ * returned object will be a function with all the objects properties.
563
+ *
564
+ * ```ts
565
+ * const car = callable({
566
+ * wheels: 2
567
+ * }, self => () => {
568
+ * return 'driving'
569
+ * })
570
+ *
571
+ * car.wheels // => 2
572
+ * car() // => 'driving'
573
+ * ```
574
+ */
575
+ declare function callable<TValue, TObj extends Record<string | number | symbol, TValue>, TFunc extends (...args: any) => any>(obj: TObj, fn: (self: TObj) => TFunc): TObj & TFunc;
576
+
577
+ declare function chain<T1 extends any[], T2, T3>(f1: (...arg: T1) => T2, f2: (arg: T2) => T3): (...arg: T1) => T3;
578
+ declare function chain<T1 extends any[], T2, T3, T4>(f1: (...arg: T1) => T2, f2: (arg: T2) => T3, f3: (arg: T3) => T4): (...arg: T1) => T4;
579
+ declare function chain<T1 extends any[], T2, T3, T4, T5>(f1: (...arg: T1) => T2, f2: (arg: T2) => T3, f3: (arg: T3) => T4, f4: (arg: T3) => T5): (...arg: T1) => T5;
580
+ declare function chain<T1 extends any[], T2, T3, T4, T5, T6>(f1: (...arg: T1) => T2, f2: (arg: T2) => T3, f3: (arg: T3) => T4, f4: (arg: T3) => T5, f5: (arg: T3) => T6): (...arg: T1) => T6;
581
+ declare function chain<T1 extends any[], T2, T3, T4, T5, T6, T7>(f1: (...arg: T1) => T2, f2: (arg: T2) => T3, f3: (arg: T3) => T4, f4: (arg: T3) => T5, f5: (arg: T3) => T6, f6: (arg: T3) => T7): (...arg: T1) => T7;
582
+ declare function chain<T1 extends any[], T2, T3, T4, T5, T6, T7, T8>(f1: (...arg: T1) => T2, f2: (arg: T2) => T3, f3: (arg: T3) => T4, f4: (arg: T3) => T5, f5: (arg: T3) => T6, f6: (arg: T3) => T7, f7: (arg: T3) => T8): (...arg: T1) => T8;
583
+ declare function chain<T1 extends any[], T2, T3, T4, T5, T6, T7, T8, T9>(f1: (...arg: T1) => T2, f2: (arg: T2) => T3, f3: (arg: T3) => T4, f4: (arg: T3) => T5, f5: (arg: T3) => T6, f6: (arg: T3) => T7, f7: (arg: T3) => T8, f8: (arg: T3) => T9): (...arg: T1) => T9;
584
+ declare function chain<T1 extends any[], T2, T3, T4, T5, T6, T7, T8, T9, T10>(f1: (...arg: T1) => T2, f2: (arg: T2) => T3, f3: (arg: T3) => T4, f4: (arg: T3) => T5, f5: (arg: T3) => T6, f6: (arg: T3) => T7, f7: (arg: T3) => T8, f8: (arg: T3) => T9, f9: (arg: T3) => T10): (...arg: T1) => T10;
585
+ declare function chain<T1 extends any[], T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>(f1: (...arg: T1) => T2, f2: (arg: T2) => T3, f3: (arg: T3) => T4, f4: (arg: T3) => T5, f5: (arg: T3) => T6, f6: (arg: T3) => T7, f7: (arg: T3) => T8, f8: (arg: T3) => T9, f9: (arg: T3) => T10, f10: (arg: T3) => T11): (...arg: T1) => T11;
586
+
587
+ declare function compose<F1Result, F1Args extends any[], F1NextArgs extends any[], LastResult>(f1: (next: (...args: F1NextArgs) => LastResult) => (...args: F1Args) => F1Result, last: (...args: F1NextArgs) => LastResult): (...args: F1Args) => F1Result;
588
+ declare function compose<F1Result, F1Args extends any[], F1NextArgs extends any[], F2Result, F2NextArgs extends any[], LastResult>(f1: (next: (...args: F1NextArgs) => F2Result) => (...args: F1Args) => F1Result, f2: (next: (...args: F2NextArgs) => LastResult) => (...args: F1NextArgs) => F2Result, last: (...args: F2NextArgs) => LastResult): (...args: F1Args) => F1Result;
589
+ declare function compose<F1Result, F1Args extends any[], F1NextArgs extends any[], F2NextArgs extends any[], F2Result, F3NextArgs extends any[], F3Result, LastResult>(f1: (next: (...args: F1NextArgs) => F2Result) => (...args: F1Args) => F1Result, f2: (next: (...args: F2NextArgs) => F3Result) => (...args: F1NextArgs) => F2Result, f3: (next: (...args: F3NextArgs) => LastResult) => (...args: F2NextArgs) => F3Result, last: (...args: F3NextArgs) => LastResult): (...args: F1Args) => F1Result;
590
+ declare function compose<F1Result, F1Args extends any[], F1NextArgs extends any[], F2NextArgs extends any[], F2Result, F3NextArgs extends any[], F3Result, F4NextArgs extends any[], F4Result, LastResult>(f1: (next: (...args: F1NextArgs) => F2Result) => (...args: F1Args) => F1Result, f2: (next: (...args: F2NextArgs) => F3Result) => (...args: F1NextArgs) => F2Result, f3: (next: (...args: F3NextArgs) => F4Result) => (...args: F2NextArgs) => F3Result, f4: (next: (...args: F4NextArgs) => LastResult) => (...args: F3NextArgs) => F4Result, last: (...args: F4NextArgs) => LastResult): (...args: F1Args) => F1Result;
591
+ declare function compose<F1Result, F1Args extends any[], F1NextArgs extends any[], F2NextArgs extends any[], F2Result, F3NextArgs extends any[], F3Result, F4NextArgs extends any[], F4Result, F5NextArgs extends any[], F5Result, LastResult>(f1: (next: (...args: F1NextArgs) => F2Result) => (...args: F1Args) => F1Result, f2: (next: (...args: F2NextArgs) => F3Result) => (...args: F1NextArgs) => F2Result, f3: (next: (...args: F3NextArgs) => F4Result) => (...args: F2NextArgs) => F3Result, f4: (next: (...args: F4NextArgs) => F5Result) => (...args: F3NextArgs) => F4Result, f5: (next: (...args: F5NextArgs) => LastResult) => (...args: F4NextArgs) => F5Result, last: (...args: F5NextArgs) => LastResult): (...args: F1Args) => F1Result;
592
+ declare function compose<F1Result, F1Args extends any[], F1NextArgs extends any[], F2NextArgs extends any[], F2Result, F3NextArgs extends any[], F3Result, F4NextArgs extends any[], F4Result, F5NextArgs extends any[], F5Result, F6NextArgs extends any[], F6Result, LastResult>(f1: (next: (...args: F1NextArgs) => F2Result) => (...args: F1Args) => F1Result, f2: (next: (...args: F2NextArgs) => F3Result) => (...args: F1NextArgs) => F2Result, f3: (next: (...args: F3NextArgs) => F4Result) => (...args: F2NextArgs) => F3Result, f4: (next: (...args: F4NextArgs) => F5Result) => (...args: F3NextArgs) => F4Result, f5: (next: (...args: F5NextArgs) => F6Result) => (...args: F4NextArgs) => F5Result, f6: (next: (...args: F6NextArgs) => LastResult) => (...args: F5NextArgs) => F6Result, last: (...args: F6NextArgs) => LastResult): (...args: F1Args) => F1Result;
593
+ declare function compose<F1Result, F1Args extends any[], F1NextArgs extends any[], F2NextArgs extends any[], F2Result, F3NextArgs extends any[], F3Result, F4NextArgs extends any[], F4Result, F5NextArgs extends any[], F5Result, F6NextArgs extends any[], F6Result, F7NextArgs extends any[], F7Result, LastResult>(f1: (next: (...args: F1NextArgs) => F2Result) => (...args: F1Args) => F1Result, f2: (next: (...args: F2NextArgs) => F3Result) => (...args: F1NextArgs) => F2Result, f3: (next: (...args: F3NextArgs) => F4Result) => (...args: F2NextArgs) => F3Result, f4: (next: (...args: F4NextArgs) => F5Result) => (...args: F3NextArgs) => F4Result, f5: (next: (...args: F5NextArgs) => F6Result) => (...args: F4NextArgs) => F5Result, f6: (next: (...args: F6NextArgs) => F7Result) => (...args: F5NextArgs) => F6Result, f7: (next: (...args: F7NextArgs) => LastResult) => (...args: F6NextArgs) => F7Result, last: (...args: F7NextArgs) => LastResult): (...args: F1Args) => F1Result;
594
+ declare function compose<F1Result, F1Args extends any[], F1NextArgs extends any[], F2NextArgs extends any[], F2Result, F3NextArgs extends any[], F3Result, F4NextArgs extends any[], F4Result, F5NextArgs extends any[], F5Result, F6NextArgs extends any[], F6Result, F7NextArgs extends any[], F7Result, F8NextArgs extends any[], F8Result, LastResult>(f1: (next: (...args: F1NextArgs) => F2Result) => (...args: F1Args) => F1Result, f2: (next: (...args: F2NextArgs) => F3Result) => (...args: F1NextArgs) => F2Result, f3: (next: (...args: F3NextArgs) => F4Result) => (...args: F2NextArgs) => F3Result, f4: (next: (...args: F4NextArgs) => F5Result) => (...args: F3NextArgs) => F4Result, f5: (next: (...args: F5NextArgs) => F6Result) => (...args: F4NextArgs) => F5Result, f6: (next: (...args: F6NextArgs) => F7Result) => (...args: F5NextArgs) => F6Result, f7: (next: (...args: F7NextArgs) => LastResult) => (...args: F6NextArgs) => F7Result, f8: (next: (...args: F8NextArgs) => LastResult) => (...args: F7NextArgs) => F8Result, last: (...args: F8NextArgs) => LastResult): (...args: F1Args) => F1Result;
595
+ declare function compose<F1Result, F1Args extends any[], F1NextArgs extends any[], F2NextArgs extends any[], F2Result, F3NextArgs extends any[], F3Result, F4NextArgs extends any[], F4Result, F5NextArgs extends any[], F5Result, F6NextArgs extends any[], F6Result, F7NextArgs extends any[], F7Result, F8NextArgs extends any[], F8Result, F9NextArgs extends any[], F9Result, LastResult>(f1: (next: (...args: F1NextArgs) => F2Result) => (...args: F1Args) => F1Result, f2: (next: (...args: F2NextArgs) => F3Result) => (...args: F1NextArgs) => F2Result, f3: (next: (...args: F3NextArgs) => F4Result) => (...args: F2NextArgs) => F3Result, f4: (next: (...args: F4NextArgs) => F5Result) => (...args: F3NextArgs) => F4Result, f5: (next: (...args: F5NextArgs) => F6Result) => (...args: F4NextArgs) => F5Result, f6: (next: (...args: F6NextArgs) => F7Result) => (...args: F5NextArgs) => F6Result, f7: (next: (...args: F7NextArgs) => LastResult) => (...args: F6NextArgs) => F7Result, f8: (next: (...args: F8NextArgs) => LastResult) => (...args: F7NextArgs) => F8Result, f9: (next: (...args: F9NextArgs) => LastResult) => (...args: F8NextArgs) => F9Result, last: (...args: F9NextArgs) => LastResult): (...args: F1Args) => F1Result;
596
+
597
+ type DebounceFunction<TArgs extends any[]> = {
598
+ (...args: TArgs): void;
599
+ /**
600
+ * Cancels the debounced function
601
+ */
602
+ cancel(): void;
603
+ /**
604
+ * Checks if there is any invocation debounced
605
+ */
606
+ isPending(): boolean;
607
+ /**
608
+ * Runs the debounced function immediately
609
+ */
610
+ flush(...args: TArgs): void;
611
+ };
612
+ /**
613
+ * Given a delay and a function returns a new function that will only
614
+ * call the source function after delay milliseconds have passed
615
+ * without any invocations.
616
+ *
617
+ * The debounce function comes with a `cancel` method to cancel
618
+ * delayed `func` invocations and a `flush` method to invoke them
619
+ * immediately
620
+ */
621
+ declare function debounce<TArgs extends any[]>({ delay }: {
622
+ delay: number;
623
+ }, func: (...args: TArgs) => any): DebounceFunction<TArgs>;
624
+
625
+ declare function flip<Args extends any[], Result>(fn: (...args: Args) => Result): (...args: Flip<Args>) => Result;
626
+ type Flip<T extends any[]> = T extends [infer A, infer B, ...infer R] ? [B, A, ...R] : never;
627
+
628
+ interface MemoOptions<TArgs extends any[]> {
629
+ key?: (...args: TArgs) => string;
630
+ ttl?: number;
631
+ }
632
+ /**
633
+ * Creates a memoized function. The returned function will only
634
+ * execute the source function when no value has previously been
635
+ * computed. If a ttl (milliseconds) is given previously computed
636
+ * values will be checked for expiration before being returned.
637
+ */
638
+ declare function memo<TArgs extends any[], TResult>(func: (...args: TArgs) => TResult, options?: MemoOptions<TArgs>): (...args: TArgs) => TResult;
639
+
640
+ declare const onceSymbol: unique symbol;
641
+ /**
642
+ * The type of a function wrapped with `once`.
643
+ */
644
+ interface OnceFunction<Args extends unknown[] = unknown[], Return = unknown, This = unknown> {
645
+ (this: This, ...args: Args): Return;
646
+ [onceSymbol]?: Return | typeof onceSymbol;
647
+ }
648
+ /**
649
+ * Create a function that runs at most once, no matter how many times
650
+ * it's called. If it was already called before, returns the result
651
+ * from the first call. This is a lighter version of `memo()`.
652
+ *
653
+ * To allow the function to be called again, use `onceReset()`.
654
+ *
655
+ * ```ts
656
+ * const fn = once(() => Math.random())
657
+ * fn() // 0.5
658
+ * fn() // 0.5
659
+ * ```
660
+ */
661
+ declare const once: {
662
+ <Args extends unknown[], Return, This = unknown>(fn: (this: This, ...args: Args) => Return): (this: This, ...args: Args) => Return;
663
+ /**
664
+ * Reset the result of a function that was created with `once`,
665
+ * allowing it to be called again.
666
+ *
667
+ * ```ts
668
+ * const fn = once(() => Math.random())
669
+ * fn() // 0.5
670
+ * fn() // 0.5
671
+ * once.reset(fn)
672
+ * fn() // 0.3
673
+ * fn() // 0.3
674
+ * ```
675
+ */
676
+ reset(fn: OnceFunction): void;
677
+ };
678
+
679
+ /**
680
+ * This type produces the type array of `TItems` with all the type items
681
+ * in `TItemsToRemove` removed from the start of the array type.
682
+ *
683
+ * ```ts
684
+ * type T = RemoveItemsInFront<[number, number], [number]>
685
+ * // [number]
686
+ *
687
+ * type T = RemoveItemsInFront<[File, number, string], [File, number]>
688
+ * // [string]
689
+ * ```
690
+ */
691
+ type RemoveItemsInFront<TItems extends any[], TItemsToRemove extends any[]> = TItems extends [...TItemsToRemove, ...infer TRest] ? TRest : TItems;
692
+ /**
693
+ * Create a partial function by providing some (or all) of the
694
+ * arguments the given function needs.
695
+ *
696
+ * ```ts
697
+ * const add = (a: number, b: number) => a + b
698
+ *
699
+ * const addFive = partial(add, 5)
700
+ *
701
+ * addFive(2) // => 7
702
+ * ```
703
+ */
704
+ declare function partial<T extends any[], TA extends Partial<T>, R>(fn: (...args: T) => R, ...args: TA): (...rest: RemoveItemsInFront<T, TA>) => R;
705
+
706
+ /**
707
+ * Like partial but for unary functions that accept a single object
708
+ * argument
709
+ */
710
+ declare function partob<T, K, PartialArgs extends Partial<T>>(fn: (args: T) => K, argobj: PartialArgs): (restobj: Omit<T, keyof PartialArgs>) => K;
711
+
712
+ /**
713
+ * Creates a Proxy object that will dynamically call the handler
714
+ * argument when attributes are accessed
715
+ */
716
+ declare function proxied<T, K>(handler: (propertyName: T) => K): Record<string, K>;
717
+
718
+ type ThrottledFunction<TArgs extends any[]> = {
719
+ (...args: TArgs): void;
720
+ /**
721
+ * Checks if there is any invocation throttled
722
+ */
723
+ isThrottled(): boolean;
724
+ };
725
+ /**
726
+ * Given an interval and a function returns a new function that will
727
+ * only call the source function if interval milliseconds have passed
728
+ * since the last invocation
729
+ */
730
+ declare function throttle<TArgs extends any[]>({ interval }: {
731
+ interval: number;
732
+ }, func: (...args: TArgs) => any): ThrottledFunction<TArgs>;
733
+
734
+ /**
735
+ * Checks if the given number is between zero (0) and the ending
736
+ * number. 0 is inclusive.
737
+ *
738
+ * * Numbers can be negative or positive.
739
+ * * Ending number is exclusive.
740
+ *
741
+ * @param {number} number The number to check.
742
+ * @param {number} end The end of the range. Exclusive. @returns
743
+ * {boolean} Returns `true` if `number` is in the range, else `false`.
744
+ */
745
+ declare function inRange(number: number, end: number): boolean;
746
+ /**
747
+ * Checks if the given number is between two numbers.
748
+ *
749
+ * * Numbers can be negative or positive.
750
+ * * Starting number is inclusive.
751
+ * * Ending number is exclusive.
752
+ * * The start and the end of the range can be ascending OR descending
753
+ * order.
754
+ *
755
+ * @param {number} number The number to check.
756
+ * @param {number} start The start of the range. Inclusive. @param
757
+ * {number} end The end of the range. Exclusive. @returns {boolean}
758
+ * Returns `true` if `number` is in the range, else `false`.
759
+ */
760
+ declare function inRange(number: number, start: number, end: number): boolean;
761
+
762
+ /**
763
+ * Linearly interpolates between two numbers.
764
+ *
765
+ * ```
766
+ * lerp(0, 10, 0.5) // => 5
767
+ * lerp(5, 15, 0.2) // => 7
768
+ * lerp(-10, 10, 0.75) // => 5
769
+ * ```
770
+ */
771
+ declare function lerp(from: number, to: number, amount: number): number;
772
+
773
+ /**
774
+ * Rounds a number to the given precision. The default `precision` is
775
+ * zero. An optional rounding function (e.g. `Math.floor` or
776
+ * `Math.ceil`) can be provided.
777
+ *
778
+ * The `precision` argument is limited to be within the range of -323
779
+ * to +292. Without this limit, precision values outside this range
780
+ * can result in NaN.
781
+ *
782
+ * ```ts
783
+ * round(123.456)
784
+ * // => 123.5
785
+ *
786
+ * round(1234.56, -2)
787
+ * // => 1200
788
+ *
789
+ * round(1234.56, 1, Math.floor)
790
+ * // => 1234.5
791
+ *
792
+ * round(1234.54, 1, Math.ceil)
793
+ * // => 1234.6
794
+ * ```
795
+ */
796
+ declare function round(value: number, precision?: number, toInteger?: (value: number) => number): number;
797
+
798
+ declare function toFloat(value: unknown): number;
799
+ declare function toFloat(value: unknown, defaultValue: number): number;
800
+ declare function toFloat<T>(value: unknown, defaultValue: T): number | Exclude<T, undefined>;
801
+
802
+ declare function toInt(value: unknown): number;
803
+ declare function toInt(value: unknown, defaultValue: number): number;
804
+ declare function toInt<T>(value: unknown, defaultValue: T): number | Exclude<T, undefined>;
805
+
806
+ /**
807
+ * Merges two objects together recursivly into a new object applying
808
+ * values from right to left. Recursion only applies to child object
809
+ * properties.
810
+ */
811
+ declare function assign<X extends Record<string | symbol | number, any>>(initial: X, override: X): X;
812
+
813
+ /**
814
+ * Creates a shallow copy of the given obejct/value.
815
+ * @param {*} obj value to clone @returns {*} shallow clone of the
816
+ * given value
817
+ */
818
+ declare function clone<T>(obj: T): T;
819
+
820
+ /**
821
+ * The opposite of crush, given an object that was crushed into key
822
+ * paths and values will return the original object reconstructed.
823
+ *
824
+ * ```ts
825
+ * construct({ name: 'ra', 'children.0.name': 'hathor' })
826
+ * // { name: 'ra', children: [{ name: 'hathor' }] }
827
+ * ```
828
+ */
829
+ declare function construct<TObject extends object>(obj: TObject): object;
830
+
831
+ /**
832
+ * Flattens a deep object to a single dimension, converting the keys
833
+ * to dot notation.
834
+ *
835
+ * ```ts
836
+ * crush({ name: 'ra', children: [{ name: 'hathor' }] })
837
+ * // { name: 'ra', 'children.0.name': 'hathor' }
838
+ * ```
839
+ */
840
+ declare function crush<TValue extends object>(value: TValue): object;
841
+
842
+ type KeyOf<T extends object> = object extends T ? keyof any : keyof T;
843
+ type ValueOf<T extends object> = object extends T ? unknown : T[keyof T];
844
+ type KeyFilterFunction<T extends object = object> = (value: ValueOf<T>, key: KeyOf<T>, obj: T) => boolean;
845
+ /**
846
+ * Functions can use this type to accept either an array of keys or a
847
+ * filter function.
848
+ */
849
+ type KeyFilter<T extends object = object, Key extends keyof any = keyof any> = KeyFilterFunction<T> | readonly Key[];
850
+ /**
851
+ * Extract the keys of an object that pass a filter.
852
+ */
853
+ type FilteredKeys<T extends object, F extends KeyFilter<T> | null | undefined> = Extract<keyof T, F extends readonly any[] ? F[number] : any>;
854
+ /**
855
+ * Returns true if the key is in the “keys array” or if the “filter
856
+ * function” returns true.
857
+ */
858
+ declare function filterKey<T extends object>(obj: T, key: keyof T, filter: KeyFilter<T, keyof T> | null | undefined): boolean;
859
+ declare function filterKey(obj: object, key: keyof any, filter: KeyFilter | null | undefined): boolean;
860
+
861
+ /**
862
+ * Dynamically get a nested value from an array or object with a
863
+ * string.
864
+ *
865
+ * ```ts
866
+ * const person = {
867
+ * name: 'John',
868
+ * friends: [{ name: 'Jane' }]
869
+ * }
870
+ *
871
+ * get(person, 'friends[0].name')
872
+ * // => 'Jane'
873
+ * ```
874
+ */
875
+ declare function get<TDefault = unknown>(value: any, path: string, defaultValue?: TDefault): TDefault;
876
+
877
+ /**
878
+ * Returns a new object whose keys are the values of the given object
879
+ * and its values are the keys of the given object.
880
+ */
881
+ declare function invert<TKey extends string | number | symbol, TValue extends string | number | symbol>(obj: Record<TKey, TValue>): Record<TValue, TKey>;
882
+
883
+ /**
884
+ * Get a string list of all key names that exist in an object (deep).
885
+ *
886
+ * ```ts
887
+ * keys({ name: 'ra' }) // ['name']
888
+ *
889
+ * keys({ name: 'ra', children: [{ name: 'hathor' }] })
890
+ * // ['name', 'children.0.name']
891
+ * ```
892
+ */
893
+ declare function keys(value: object): string[];
894
+
895
+ /**
896
+ * Convert an object to a list, mapping each entry into a list item
897
+ */
898
+ declare function listify<Value, Key extends string | number | symbol, Item>(obj: Record<Key, Value>, toItem: (key: Key, value: Value) => Item): Item[];
899
+
900
+ type LowercaseKeys<T extends Record<string, any>> = {
901
+ [P in keyof T & string as Lowercase<P>]: T[P];
902
+ };
903
+ /**
904
+ * Convert all keys in an object to lower case
905
+ */
906
+ declare function lowerize<T extends Record<string, any>>(obj: T): LowercaseKeys<T>;
907
+
908
+ /**
909
+ * Map over all the keys to create a new object
910
+ */
911
+ declare function mapEntries<TKey extends string | number | symbol, TValue, TNewKey extends string | number | symbol, TNewValue>(obj: Record<TKey, TValue>, toEntry: (key: TKey, value: TValue) => [TNewKey, TNewValue]): Record<TNewKey, TNewValue>;
912
+
913
+ /**
914
+ * Map over all the keys of an object to return a new object
915
+ */
916
+ declare function mapKeys<TValue, TKey extends string | number | symbol, TNewKey extends string | number | symbol>(obj: Record<TKey, TValue>, mapFunc: (key: TKey, value: TValue) => TNewKey): Record<TNewKey, TValue>;
917
+
918
+ /**
919
+ * Map over all the keys to create a new object
920
+ */
921
+ declare function mapValues<TValue, TKey extends string | number | symbol, TNewValue>(obj: {
922
+ [K in TKey]: TValue;
923
+ }, mapFunc: (value: TValue, key: TKey) => TNewValue): {
924
+ [K in TKey]: TNewValue;
925
+ };
926
+ declare function mapValues<TValue, TKey extends string | number | symbol, TNewValue>(obj: {
927
+ [K in TKey]?: TValue;
928
+ }, mapFunc: (value: TValue, key: TKey) => TNewValue): {
929
+ [K in TKey]?: TNewValue;
930
+ };
931
+
932
+ /**
933
+ * Omit a list of properties from an object returning a new object
934
+ * with the properties that remain
935
+ */
936
+ declare function omit<T, TKeys extends keyof T>(obj: T, keys: TKeys[]): Omit<T, TKeys>;
937
+
938
+ /**
939
+ * Pick a list of properties from an object into a new object
940
+ */
941
+ declare function pick<T extends object, F extends KeyFilter<T, keyof T>>(obj: T, filter: F): Pick<T, FilteredKeys<T, F>>;
942
+
943
+ /**
944
+ * Opposite of get, dynamically set a nested value into an object
945
+ * using a key path. Does not modify the given initial object.
946
+ *
947
+ * ```ts
948
+ * set({}, 'name', 'ra') // => { name: 'ra' }
949
+ * set({}, 'cards[0].value', 2) // => { cards: [{ value: 2 }] }
950
+ * ```
951
+ */
952
+ declare function set<T extends object, K>(initial: T, path: string, value: K): T;
953
+
954
+ /**
955
+ * Removes (shakes out) undefined entries from an object. Optional
956
+ * second argument shakes out values by custom evaluation.
957
+ */
958
+ declare function shake<T extends object>(obj: T, filter?: (value: T[keyof T]) => boolean): T;
959
+
960
+ type UppercaseKeys<T extends Record<string, any>> = {
961
+ [P in keyof T & string as Uppercase<P>]: T[P];
962
+ };
963
+ /**
964
+ * Convert all keys in an object to upper case
965
+ */
966
+ declare function upperize<T extends Record<string, any>>(obj: T): UppercaseKeys<T>;
967
+
968
+ /**
969
+ * Draw a random item from a list. Returns null if the list is empty
970
+ */
971
+ declare function draw<T>(array: readonly T[]): T | null;
972
+
973
+ /**
974
+ * Generates a random number between min and max
975
+ */
976
+ declare function random(min: number, max: number): number;
977
+
978
+ declare function shuffle<T>(array: readonly T[], random?: (min: number, max: number) => number): T[];
979
+
980
+ declare function uid(length: number, specials?: string): string;
981
+
982
+ interface Series<T> {
983
+ min: (a: T, b: T) => T;
984
+ max: (a: T, b: T) => T;
985
+ first: () => T;
986
+ last: () => T;
987
+ next: (current: T, defaultValue?: T) => T;
988
+ previous: (current: T, defaultValue?: T) => T;
989
+ spin: (current: T, num: number) => T;
990
+ }
991
+ /**
992
+ * Creates a series object around a list of values that should be
993
+ * treated with order.
994
+ */
995
+ declare const series: <T>(items: readonly T[], toKey?: (item: T) => string | symbol) => Series<T>;
996
+
997
+ /**
998
+ * Formats the given string in camel case fashion
999
+ *
1000
+ * camel('hello world') -> 'helloWorld' camel('va va-VOOM') ->
1001
+ * 'vaVaVoom' camel('helloWorld') -> 'helloWorld'
1002
+ */
1003
+ declare function camel(str: string): string;
1004
+
1005
+ /**
1006
+ * Capitalize the first word of the string
1007
+ *
1008
+ * capitalize('hello') -> 'Hello' capitalize('va va voom') -> 'Va va
1009
+ * voom'
1010
+ */
1011
+ declare function capitalize(str: string): string;
1012
+
1013
+ /**
1014
+ * Formats the given string in dash case fashion
1015
+ *
1016
+ * dash('hello world') -> 'hello-world' dash('va va_VOOM') ->
1017
+ * 'va-va-voom' dash('helloWord') -> 'hello-word'
1018
+ */
1019
+ declare function dash(str: string): string;
1020
+
1021
+ /**
1022
+ * Formats the given string in pascal case fashion
1023
+ *
1024
+ * pascal('hello world') -> 'HelloWorld' pascal('va va boom') ->
1025
+ * 'VaVaBoom'
1026
+ */
1027
+ declare function pascal(str: string): string;
1028
+
1029
+ /**
1030
+ * Formats the given string in snake case fashion
1031
+ *
1032
+ * snake('hello world') -> 'hello_world' snake('va va-VOOM') ->
1033
+ * 'va_va_voom' snake('helloWord') -> 'hello_world'
1034
+ */
1035
+ declare function snake(str: string, options?: {
1036
+ splitOnNumber?: boolean;
1037
+ }): string;
1038
+
1039
+ /**
1040
+ * Replace data by name in template strings. The default expression
1041
+ * looks for `{{name}}` to identify names.
1042
+ *
1043
+ * ```ts
1044
+ * template('Hello, {{name}}', { name: 'Radashi' })
1045
+ * // "Hello, Radashi"
1046
+ *
1047
+ * template('Hello, <name>', { name: 'Radashi' }, /<(.+?)>/g)
1048
+ * // "Hello, Radashi"
1049
+ * ```
1050
+ */
1051
+ declare function template(str: string, data: Record<string, any>, regex?: RegExp): string;
1052
+
1053
+ /**
1054
+ * Formats the given string in title case fashion
1055
+ *
1056
+ * title('hello world') -> 'Hello World' title('va_va_boom') -> 'Va Va
1057
+ * Boom' title('root-hook') -> 'Root Hook' title('queryItems') ->
1058
+ * 'Query Items'
1059
+ */
1060
+ declare function title(str: string | null | undefined): string;
1061
+
1062
+ /**
1063
+ * Trims all prefix and suffix characters from the given string. Like
1064
+ * the builtin trim function but accepts other characters you would
1065
+ * like to trim and trims multiple characters.
1066
+ *
1067
+ * ```typescript
1068
+ * trim(' hello ') // => 'hello'
1069
+ * trim('__hello__', '_') // => 'hello'
1070
+ * trim('/repos/:owner/:repo/', '/') // => 'repos/:owner/:repo'
1071
+ * trim('222222__hello__1111111', '12_') // => 'hello'
1072
+ * ```
1073
+ */
1074
+ declare function trim(str: string | null | undefined, charsToTrim?: string): string;
1075
+
1076
+ declare const isArray: <Input>(value: Input) => value is ExtractArray<Input>;
1077
+ /**
1078
+ * An absurdly complicated but accurate type for extracting Array types.
1079
+ *
1080
+ * It's like `Extract<T, any[]>` but better with edge cases.
1081
+ */
1082
+ type ExtractArray<T> = T extends any ? [StrictExtract<T, readonly any[]>] extends [readonly any[]] ? Extract<T, readonly any[]> : [StrictExtract<T, any[]>] extends [any[]] ? Extract<T, any[]> : unknown[] extends T ? unknown[] : never : never;
1083
+
1084
+ declare function isDate(value: unknown): value is Date;
1085
+
1086
+ declare function isEmpty(value: any): boolean;
1087
+
1088
+ declare function isEqual<TType>(x: TType, y: TType): boolean;
1089
+
1090
+ declare function isFloat(value: any): value is number;
1091
+
1092
+ declare function isFunction(value: any): value is Function;
1093
+
1094
+ declare const isInt: (value: unknown) => value is number;
1095
+
1096
+ declare function isIntString(value: any): value is string;
1097
+
1098
+ declare function isMap<Input>(value: Input): value is ExtractMap<Input>;
1099
+ /**
1100
+ * An absurdly complicated but accurate type for extracting Map types.
1101
+ *
1102
+ * It's like `Extract<T, Map<any, any>>` but better with edge cases.
1103
+ */
1104
+ type ExtractMap<T> = T extends any ? [StrictExtract<T, ReadonlyMap<unknown, unknown>>] extends [
1105
+ ReadonlyMap<unknown, unknown>
1106
+ ] ? Extract<T, ReadonlyMap<unknown, unknown>> : [StrictExtract<T, Map<unknown, unknown>>] extends [Map<unknown, unknown>] ? Extract<T, Map<unknown, unknown>> : Map<unknown, unknown> extends T ? Map<unknown, unknown> : never : never;
1107
+
1108
+ declare function isNumber(value: unknown): value is number;
1109
+
1110
+ /**
1111
+ * Returns true if `value` is a plain object, a class instance
1112
+ * (excluding built-in classes like Date/RegExp), or an
1113
+ * `Object.create(null)` result. Objects from [other realms][1] are
1114
+ * also supported.
1115
+ *
1116
+ * [1]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/instanceof#instanceof_and_multiple_realms
1117
+ *
1118
+ * ```
1119
+ * isObject({}) // true
1120
+ * isObject(new Object()) // true
1121
+ * isObject(Object.create(null)) // true
1122
+ * isObject(new class {}) // true
1123
+ *
1124
+ * isObject([]) // false
1125
+ * isObject(/.+/g) // false
1126
+ * isObject(new Date()) // false
1127
+ * isObject(new Map()) // false
1128
+ * isObject(new Set()) // false
1129
+ * ```
1130
+ */
1131
+ declare function isObject(value: unknown): value is object;
1132
+
1133
+ declare function isPlainObject(value: any): value is object;
1134
+
1135
+ /**
1136
+ * Checks if the given value is primitive.
1137
+ *
1138
+ * Primitive Types: number , string , boolean , symbol, bigint,
1139
+ * undefined, null
1140
+ *
1141
+ * @param {*} value value to check
1142
+ * @returns {boolean} result
1143
+ */
1144
+ declare function isPrimitive(value: any): boolean;
1145
+
1146
+ /**
1147
+ * This is really a _best guess_ promise checking. You should probably
1148
+ * use Promise.resolve(value) to be 100% sure you're handling it
1149
+ * correctly.
1150
+ */
1151
+ declare function isPromise(value: any): value is Promise<any>;
1152
+
1153
+ declare function isRegExp(value: unknown): value is RegExp;
1154
+
1155
+ declare function isSet<Input>(value: Input): value is ExtractSet<Input>;
1156
+ /**
1157
+ * An absurdly complicated but accurate type for extracting Set types.
1158
+ *
1159
+ * It's like `Extract<T, Set<any>>` but better with edge cases.
1160
+ */
1161
+ type ExtractSet<T> = T extends any ? [StrictExtract<T, ReadonlySet<unknown>>] extends [ReadonlySet<unknown>] ? Extract<T, ReadonlySet<unknown>> : [StrictExtract<T, Set<unknown>>] extends [Set<unknown>] ? Extract<T, Set<unknown>> : Set<unknown> extends T ? Set<unknown> : never : never;
1162
+
1163
+ declare function isString(value: unknown): value is string;
1164
+
1165
+ declare function isSymbol(value: unknown): value is symbol;
1166
+
1167
+ /**
1168
+ * Compare the given tag to the result of `Object.prototype.toString`.
1169
+ *
1170
+ * ⚠️ You probably won't use this except when implementing another type guard.
1171
+ *
1172
+ * ```ts
1173
+ * isTagged('foo', '[object String]') // true
1174
+ * ```
1175
+ */
1176
+ declare function isTagged(value: unknown, tag: string): boolean;
1177
+
1178
+ declare function isWeakMap<K extends WeakKey = WeakKey, V = unknown>(value: unknown): value is WeakMap<K, V>;
1179
+
1180
+ declare function isWeakSet<T extends WeakKey = WeakKey>(value: unknown): value is WeakSet<T>;
1181
+
1182
+ /**
1183
+ * The `Any` class does not exist at runtime. It's used in type
1184
+ * definitions to detect an `any` type.
1185
+ *
1186
+ * ```ts
1187
+ * type IsAny<T> = [T] extends [Any] ? 'is any' : 'is not any'
1188
+ * ```
1189
+ */
1190
+ declare class Any {
1191
+ private any;
1192
+ }
1193
+ /**
1194
+ * Extracts `T` if `T` is not `any`, otherwise `never`.
1195
+ *
1196
+ * ```ts
1197
+ * type A = ExtractNotAny<any, string>
1198
+ * // ^? never
1199
+ * type B = ExtractNotAny<string | number, string>
1200
+ * // ^? string
1201
+ * ```
1202
+ */
1203
+ type ExtractNotAny<T, U> = Extract<[T] extends [Any] ? never : T, U>;
1204
+ type SwitchAny<T, U> = [T] extends [Any] ? U : T;
1205
+ type SwitchNever<T, U> = [T] extends [never] ? U : T;
1206
+ /**
1207
+ * Extract types in `T` that are assignable to `U`. Coerce `any` and
1208
+ * `never` types to unknown.
1209
+ */
1210
+ type StrictExtract<T, U> = SwitchNever<Extract<SwitchAny<T, unknown>, U>, unknown>;
1211
+
1212
+ export { AggregateError, Any, type DebounceFunction, type ExtractArray, type ExtractMap, type ExtractNotAny, type ExtractSet, type FilteredKeys, type Flip, type KeyFilter, type KeyFilterFunction, type LowercaseKeys, type MemoOptions, type OnceFunction, type RetryOptions, type Series, type StrictExtract, type SwitchAny, type SwitchNever, type ThrottledFunction, type TryitResult, type UppercaseKeys, all, alphabetical, assign, boil, callable, camel, capitalize, chain, clone, cluster, compose, construct, counting, crush, dash, debounce, defer, diff, draw, filterKey, first, flat, flip, fork, get, group, guard, inRange, intersects, invert, isArray, isDate, isEmpty, isEqual, isFloat, isFunction, isInt, isIntString, isMap, isNumber, isObject, isPlainObject, isPrimitive, isPromise, isRegExp, isSet, isString, isSymbol, isTagged, isWeakMap, isWeakSet, iterate, keys, last, lerp, list, listify, lowerize, map, mapEntries, mapKeys, mapValues, mapify, max, memo, merge, min, objectify, omit, once, parallel, partial, partob, pascal, pick, proxied, random, range, reduce, replace, replaceOrAppend, retry, round, select, selectFirst, series, set, shake, shift, shuffle, sift, sleep, snake, sort, sum, template, throttle, title, toFloat, toInt, toggle, trim, tryit as try, tryit, uid, unique, unzip, upperize, zip, zipToObject };