moderndash 3.7.2 → 3.7.3

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.
@@ -0,0 +1,1428 @@
1
+ import { Call, Tuples, Objects } from 'hotscript';
2
+
3
+ /**
4
+ * Creates an array of elements split into groups the length of size. If array can't be split evenly, the final chunk will be the remaining elements.
5
+ *
6
+ * @example
7
+ * chunk(['a', 'b', 'c', 'd'], 2)
8
+ * // => [['a', 'b'], ['c', 'd']]
9
+ *
10
+ * chunk(['a', 'b', 'c', 'd'], 3)
11
+ * // => [['a', 'b', 'c'], ['d']]
12
+ * @param chunkSize The length of each chunk
13
+ * @param array The array to chunk
14
+ * @template TElem The type of the array elements
15
+ * @returns Returns the new array of chunks
16
+ */
17
+ declare function chunk<TElem>(array: readonly TElem[], chunkSize: number): TElem[][];
18
+
19
+ /**
20
+ * Creates an object with counts of occurrences of items in the array.
21
+ *
22
+ * @example
23
+ * const users = [
24
+ * { 'user': 'barney', 'active': true, age: 36 },
25
+ * { 'user': 'betty', 'active': false, age: 36 },
26
+ * { 'user': 'fred', 'active': true, age: 40 }
27
+ * ]
28
+ *
29
+ * count(users, value => value.active ? 'active' : 'inactive');
30
+ * // => { 'active': 2, 'inactive': 1 }
31
+ *
32
+ * count(users, value => value.age);
33
+ * // => { 36: 2, 40: 1 }
34
+ *
35
+ * @param criteria The criteria to count by
36
+ * @param array The array or record to iterate over
37
+ * @template TElem The type of the array elements
38
+ * @returns Returns the composed aggregate object
39
+ */
40
+ declare function count<TElem, TKey extends PropertyKey>(array: readonly TElem[], criteria: (value: TElem) => TKey): Record<TKey, number>;
41
+
42
+ /**
43
+ * This type builds an array with a minimum length.
44
+ *
45
+ * @example
46
+ * let arr: ArrayMinLength<number, 3> = [1, 2, 3];
47
+ * // => OK
48
+ *
49
+ * arr = [1, 2];
50
+ * // => Type '[number, number]' is not assignable to type '[number, number, number, ...number[]]'.
51
+ *
52
+ * @template TElem The type of the array elements.
53
+ * @template TMinLength The minimum length of the array.
54
+ */
55
+ type ArrayMinLength<TElem, TMinLength extends number> = BuildArrayMinLength<TElem, TMinLength, []>;
56
+ type BuildArrayMinLength<TElem, TMinLength extends number, Current extends TElem[]> = Current["length"] extends TMinLength ? [...Current, ...TElem[]] : BuildArrayMinLength<TElem, TMinLength, [...Current, TElem]>;
57
+
58
+ type CompareFunction<TArrays extends ArrayMinLength<unknown[], 2>> = (a: TArrays[0][number], b: ArrayTail<TArrays>[number][number]) => boolean;
59
+ type ArrayTail<TArray extends unknown[]> = TArray extends [unknown, ...infer U] ? U : never;
60
+
61
+ /**
62
+ * Create a new array with values from the first array that are not present in the other arrays.
63
+ *
64
+ * Optionally, use a compare function to determine the comparison of elements (default is `===`).
65
+ *
66
+ * @example
67
+ * difference([2, 1], [2, 3], [6])
68
+ * // => [1]
69
+ *
70
+ * // ---- Custom compare function ----
71
+ * const compareByFloor = (a, b) => Math.floor(a) === Math.floor(b);
72
+ * difference([1.2, 3.1], [1.3, 2.4], compareByFloor)
73
+ * // => [3.1]
74
+ *
75
+ * // ---- Only compare by id ----
76
+ * const arr1 = [{ id: 1, name: 'Yeet' }, { id: 3, name: 'John' }];
77
+ * const arr2 = [{ id: 3, name: 'Carl' }, { id: 4, name: 'Max' }];
78
+ *
79
+ * difference(arr1, arr2, (a, b) => a.id === b.id)
80
+ * // => [{ id: 1, name: 'Yeet' }]
81
+ * @param arraysOrCompareFn Two or more arrays with an optional compare function at the end
82
+ * @template TElem The type of the array elements
83
+ * @template TArrays The type of the arrays provided
84
+ * @returns Returns a new array of filtered values
85
+ */
86
+ declare function difference<TElem>(...arraysOrCompareFn: ArrayMinLength<TElem[], 2>): TElem[];
87
+ declare function difference<TArrays extends ArrayMinLength<unknown[], 2>>(...arraysOrCompareFn: [...TArrays, CompareFunction<TArrays>]): TArrays[0];
88
+
89
+ /**
90
+ * Creates a slice of `array` excluding elements dropped from the end.
91
+ * Elements are dropped until `predicate` returns falsy.
92
+ *
93
+ * @example
94
+ * const users = [
95
+ * { 'user': 'barney', 'active': false },
96
+ * { 'user': 'fred', 'active': true },
97
+ * { 'user': 'pebbles', 'active': true }
98
+ * ]
99
+ *
100
+ * dropRightWhile(users, user => user.active)
101
+ * // => objects for ['barney']
102
+ * @param predicate The function invoked per iteration
103
+ * @param array The array to query
104
+ * @template TElem The type of the array elements
105
+ * @returns Returns the slice of `array`
106
+ */
107
+ declare function dropRightWhile<TElem>(array: readonly TElem[], predicate: (value: TElem) => boolean): TElem[];
108
+
109
+ /**
110
+ * Creates a slice of `array` excluding elements dropped from the beginning.
111
+ * Elements are dropped until `predicate` returns falsy.
112
+ *
113
+ * @example
114
+ * const users = [
115
+ * { 'user': 'barney', 'active': true },
116
+ * { 'user': 'fred', 'active': true },
117
+ * { 'user': 'pebbles', 'active': false }
118
+ * ]
119
+ *
120
+ * dropWhile(users, user => user.active)
121
+ * // => objects for ['pebbles']
122
+ * @param predicate The function invoked per iteration
123
+ * @param array The array to query
124
+ * @template TElem The type of the array elements
125
+ * @returns Returns the slice of `array`
126
+ */
127
+ declare function dropWhile<TElem>(array: readonly TElem[], predicate: (value: TElem) => boolean): TElem[];
128
+
129
+ /**
130
+ * Creates an object with grouped items in the array.
131
+ *
132
+ * @example
133
+ * group([6.1, 4.2, 6.3], Math.floor)
134
+ * // => { 4: [4.2], 6: [6.1, 6.3] }
135
+ *
136
+ * group([6.1, 4.2, 6.3], value => value > 5 ? '>5' : '<=5')
137
+ * // => { '<=5': [4.2], '>5': [6.1, 6.3] }
138
+ *
139
+ * @param collection The array or object to iterate over
140
+ * @param getGroupKey A function that returns the group id for each item
141
+ * @template TElem The type of the array elements
142
+ * @returns An object with grouped items
143
+ */
144
+ declare function group<TElem, TKey extends PropertyKey>(array: readonly TElem[], getGroupKey: (elem: TElem) => TKey): Record<TKey, TElem[]>;
145
+
146
+ /**
147
+ * Create an array with unique values that are present in all arrays.
148
+ * The order of the values is based on the first array.
149
+ *
150
+ * Optionally, use a compare function for element comparison (default is `===`).
151
+ *
152
+ * @example
153
+ * intersection([2, 1], [2, 3], [6, 2])
154
+ * // => [2]
155
+ *
156
+ * // ---- Custom compare function ----
157
+ * const compareFn = (a, b) => Math.floor(a) === Math.floor(b);
158
+ *
159
+ * intersection([1.2, 1.1], [1.3, 2.4], compareFn)
160
+ * // => [1.2]
161
+ *
162
+ * // ---- Only compare by id ----
163
+ * const arr1 = [{ id: 1, name: 'Yeet' }, { id: 3, name: 'John' }];
164
+ * const arr2 = [{ id: 3, name: 'Carl' }, { id: 4, name: 'Max' }];
165
+ *
166
+ * intersection(arr1, arr2, (a, b) => a.id === b.id)
167
+ * // => [{ id: 3, name: 'John' }]
168
+ *
169
+ * @param arraysOrCompareFn Two or more arrays with an optional compare function at the end
170
+ * @template TElem Type of the array elements
171
+ * @template TArrays Type of the arrays provided
172
+ * @returns New array of intersecting values
173
+ */
174
+ declare function intersection<TElem>(...arraysOrCompareFn: ArrayMinLength<TElem[], 2>): TElem[];
175
+ declare function intersection<TArrays extends ArrayMinLength<unknown[], 2>>(...arraysOrCompareFn: [...TArrays, CompareFunction<TArrays>]): TArrays[0];
176
+
177
+ /**
178
+ * Moves an element within an array.
179
+ *
180
+ * @example
181
+ * ```typescript
182
+ * move([1, 2, 3, 4, 5], 0, 2);
183
+ * // => [2, 3, 1, 4, 5]
184
+ * ```
185
+ *
186
+ * @param array The input array
187
+ * @param fromIndex Index of the element to move
188
+ * @param toIndex Target index for the element
189
+ * @throws If index is out of bounds
190
+ * @template TArr Type of the array elements
191
+ * @returns The modified array with the moved element
192
+ */
193
+ declare function move<TArr>(array: TArr[], fromIndex: number, toIndex: number): TArr[];
194
+
195
+ /**
196
+ * Creates an array from start to end (inclusive), stepping by step.
197
+ * If start is larger than end, the array is generated in reverse
198
+ *
199
+ * @example
200
+ * for (const num of range(1, 5)) {
201
+ * console.log(num);
202
+ * }
203
+ * // => 1 2 3 4 5
204
+ *
205
+ * // Array of even numbers between 0 and 10:
206
+ * range(0, 10, 2);
207
+ * // => [0, 2, 4, 6, 8, 10]
208
+ *
209
+ * // Descending range:
210
+ * range(5, 0, 2);
211
+ * // => [5, 3, 1]
212
+ *
213
+ * @param start Start number of sequence
214
+ * @param end End number of sequence
215
+ * @param step Step between numbers, default: 1
216
+ * @throws If range is negative or step is 0
217
+ * @returns An array of numbers
218
+ */
219
+ declare function range(start: number, end: number, step?: number): number[];
220
+
221
+ /**
222
+ * Creates a new array of shuffled values, using the Fisher-Yates-Durstenfeld Shuffle algorithm.
223
+ *
224
+ * @example
225
+ * shuffle([1, 2, 3, 4])
226
+ * // => [4, 1, 3, 2]
227
+ * @param array Array to shuffle
228
+ * @template TElem The type of the array elements
229
+ * @returns A new shuffled array
230
+ */
231
+ declare function shuffle<TElem>(array: readonly TElem[]): TElem[];
232
+
233
+ /**
234
+ * Creates new array sorted in ascending/descending order with single or multiple criteria.
235
+ *
236
+ * @example
237
+ * sort([1, 2, 3, 4], { order: 'desc' })
238
+ * // => [4, 3, 2, 1]
239
+ *
240
+ * // --- Sorting by multiple properties ---
241
+ * const array = [{ a: 2, b: 1 }, { a: 1, b: 2 }, { a: 1, b: 1 }];
242
+ *
243
+ * sort(array,
244
+ * { order: 'asc', by: item => item.a },
245
+ * { order: 'desc', by: item => item.b }
246
+ * )
247
+ * // => [{ a: 1, b: 2 }, { a: 1, b: 1 }, { a: 2, b: 1 }]
248
+ *
249
+ * @param array Array to sort
250
+ * @param criteria Criteria to sort by
251
+ * @param criteria.order Order to sort in, either 'asc' or 'desc'
252
+ * @param criteria.by Iteratee function to sort based on a specific property
253
+ * @template TElem Type of the array elements
254
+ * @returns New sorted array
255
+ */
256
+ declare function sort<TElem>(array: readonly TElem[], ...criteria: {
257
+ order?: "asc" | "desc";
258
+ by?: (item: TElem) => number | bigint | Date | string;
259
+ }[]): TElem[];
260
+
261
+ /**
262
+ * Creates a slice of `array` with elements taken from the end.
263
+ * Elements are taken until `predicate` returns falsy.
264
+ *
265
+ * @example
266
+ * const users = [
267
+ * { 'user': 'barney', 'active': false },
268
+ * { 'user': 'fred', 'active': true },
269
+ * { 'user': 'pebbles', 'active': true }
270
+ * ]
271
+ *
272
+ * takeRightWhile(users, user => user.active)
273
+ * // => objects for ['fred', 'pebbles']
274
+ * @param predicate The function invoked per iteration.
275
+ * @param array The array to query.
276
+ * @template TElem The type of the array elements.
277
+ * @returns Returns the slice of `array`.
278
+ */
279
+ declare function takeRightWhile<TElem>(array: readonly TElem[], predicate: (elem: TElem) => boolean): TElem[];
280
+
281
+ /**
282
+ * Creates a slice of `array` with elements taken from the beginning.
283
+ * Elements are taken until `predicate` returns falsy.
284
+ *
285
+ * @example
286
+ * const users = [
287
+ * { 'user': 'barney', 'active': true },
288
+ * { 'user': 'fred', 'active': true },
289
+ * { 'user': 'pebbles', 'active': false }
290
+ * ]
291
+ *
292
+ * takeWhile(users, user => user.active)
293
+ * // => objects for ['barney', 'fred']
294
+ * @param predicate The function invoked per iteration.
295
+ * @param array The array to query.
296
+ * @template TElem The type of the array elements.
297
+ * @returns A new array of taken elements.
298
+ */
299
+ declare function takeWhile<TElem>(array: readonly TElem[], predicate: (elem: TElem) => boolean): TElem[];
300
+
301
+ /**
302
+ * Creates unique array retaining first occurrence of elements.
303
+ *
304
+ * A compare function is optional (default is `===`).
305
+ *
306
+ * @example
307
+ * unique([2, 1, 2])
308
+ * // => [2, 1]
309
+ *
310
+ * // compare by object values
311
+ * const users = [
312
+ * { id: 1, name: 'john' },
313
+ * { id: 2, name: 'john' },
314
+ * { id: 2, name: 'john' },
315
+ * ]
316
+ *
317
+ * unique(users, isEqual)
318
+ * // => [{ id: 1, name: 'john' }, { id: 2, name: 'john' }]
319
+ *
320
+ * // compare by id
321
+ * unique(users, (a, b) => a.name === b.name)
322
+ * // => [{ id: 1, name: 'john' }]
323
+ *
324
+ * @param array Array to inspect
325
+ * @param iteratee Iteratee invoked per element
326
+ * @template TElem Type of the array elements
327
+ * @returns A new unique array
328
+ */
329
+ declare function unique<TElem>(array: readonly TElem[], compareFn?: (a: TElem, b: TElem) => boolean): TElem[];
330
+
331
+ type JsonifiableObject = {
332
+ [Key in string]?: Jsonifiable;
333
+ } | {
334
+ toJSON: () => Jsonifiable;
335
+ };
336
+ type JsonifiableArray = readonly Jsonifiable[];
337
+ type JsonPrimitive = string | number | boolean | null;
338
+ /**
339
+ * Matches a value that can be losslessly converted to JSON.
340
+ * Can be used to type values that you expect to pass to `JSON.stringify`.
341
+ *
342
+ * `undefined` is allowed in object fields (for example, `{a?: number}`) as a special case even though `JSON.stringify({a: undefined})` is `{}` because it makes this class more widely useful and checking for undefined-but-present values is likely an anti-pattern.
343
+ *
344
+ * @example
345
+ * ```typescript
346
+ * const error: Jsonifiable = {
347
+ * map: new Map([['a', 1]]),
348
+ * };
349
+ * // => TypeError: Map is not a valid JSON value.
350
+ *
351
+ * JSON.stringify(error);
352
+ * // => {"map": {}}
353
+ *
354
+ * const good: Jsonifiable = {
355
+ * number: 3,
356
+ * date: new Date(),
357
+ * missing: undefined,
358
+ * }
359
+ *
360
+ * JSON.stringify(good);
361
+ * //=> {"number": 3, "date": "2022-10-17T22:22:35.920Z"}
362
+ * ```
363
+ */
364
+ type Jsonifiable = JsonPrimitive | JsonifiableObject | JsonifiableArray;
365
+
366
+ type SupportedAlgorithms = "SHA-256" | "SHA-384" | "SHA-512";
367
+ /**
368
+ * Generates a hash of the given data using the specified algorithm.
369
+ *
370
+ * It uses the Web Crypto API to generate the hash.
371
+ *
372
+ * *Note: If you need a secure hash use a specialized library like [crypto-js](https://www.npmjs.com/package/crypto-js) instead.*
373
+ *
374
+ * @example
375
+ * // Hash a string using the default algorithm (SHA-256)
376
+ * await hash('hello world');
377
+ * // => "b94d27b9934d3e08a52e52d7da7dabfac484efe37a53..."
378
+ *
379
+ * // Hash an object using the SHA-512 algorithm
380
+ * await hash({ foo: 'bar', baz: 123 }, 'SHA-512');
381
+ * // => "d8f3c752c6820e580977099368083f4266b569660558..."
382
+ *
383
+ * @param data The data to hash, either as a string or a JSON-serializable object.
384
+ * @param algorithm The hashing algorithm to use. Defaults to 'SHA-256'.
385
+ * @returns A Promise that resolves to the hexadecimal representation of the hash.
386
+ *
387
+ * @throws {DOMException} If the specified algorithm is not supported by the Web Crypto API.
388
+ */
389
+ declare function hash(data: Jsonifiable, algorithm?: SupportedAlgorithms): Promise<string>;
390
+
391
+ /**
392
+ * Gets a random element an array. A single element is returned by default.
393
+ * Specify the `multi` parameter to get an array of multiple random elements.
394
+ *
395
+ * If the array is empty, `undefined` is returned.
396
+ * If `multi` is defined it returns an empty array.
397
+ *
398
+ * It uses `crypto.getRandomValues` to get the random element.
399
+ * @example
400
+ * randomElem([1, 2, 3, 4])
401
+ * // => 2
402
+ *
403
+ * randomElem([1, 2, 3, 4], 2)
404
+ * // => [3, 1]
405
+ * @param array The array to sample.
406
+ * @returns Returns the random element.
407
+ */
408
+ declare function randomElem<TArr>(array: TArr[]): TArr | undefined;
409
+ declare function randomElem<TArr>(array: TArr[], multi: number): TArr[];
410
+
411
+ /**
412
+ * Generates a random float between two given numbers, including those numbers.
413
+ *
414
+ * It uses `crypto.getRandomValues` to generate the random number.
415
+ * @example
416
+ * randomFloat(1, 10)
417
+ * // => 1.123456789
418
+ *
419
+ * @param min The smallest float that can be generated.
420
+ * @param max The largest float that can be generated.
421
+ *
422
+ * @returns A random float between `min` and `max`, including `min` and `max`.
423
+ */
424
+ declare function randomFloat(min: number, max: number): number;
425
+
426
+ /**
427
+ * Generates a random integer between two given numbers, including those numbers.
428
+ *
429
+ * It uses `crypto.getRandomValues` to generate the random number.
430
+ * @example
431
+ * randomInt(1, 10)
432
+ * // => 5
433
+ *
434
+ * @param min The smallest integer that can be generated.
435
+ * @param max The largest integer that can be generated.
436
+ *
437
+ * @returns A random integer between `min` and `max`, including `min` and `max`.
438
+ */
439
+ declare function randomInt(min: number, max: number): number;
440
+
441
+ /**
442
+ * Generates a random string of the specified length.
443
+ * The default charset is alphanumeric characters.
444
+ *
445
+ * It uses `crypto.getRandomValues` to generate the random string.
446
+ *
447
+ * @example
448
+ * randomString(8);
449
+ * // => "JWw1p6rD"
450
+ *
451
+ * randomString(16, 'abc');
452
+ * // => "cbaacbabcabccabc"
453
+ * @param length The length of the string to generate.
454
+ * @param charSet The set of characters to use when generating the string. Defaults to alphanumeric characters.
455
+ * @returns A random string of the specified length.
456
+ */
457
+ declare function randomString(length: number, charSet?: string): string;
458
+
459
+ /**
460
+ * Debounces the decorated function. Only calling it after a specified amount of time has passed without any new calls.
461
+ *
462
+ * Look at {@link debounce} for the non-decorator version.
463
+ *
464
+ * *Requires the [experimentalDecorators](https://www.typescriptlang.org/tsconfig#experimentalDecorators) flag to be set.*
465
+ *
466
+ * @example
467
+ * ```typescript
468
+ * class TestClass {
469
+ * @decDebounce(100)
470
+ * testMethod(str: string) {
471
+ * console.log("Debounced:", str);
472
+ * }
473
+ * }
474
+ *
475
+ * const instance = new TestClass();
476
+ * instance.testMethod("Hello");
477
+ * instance.testMethod("World");
478
+ * // => Only the second invocation of `debouncedSayHello` is executed, after a delay of 1000ms.
479
+ * ```
480
+ * @param wait Milliseconds to wait before invoking the decorated function after the last invocation.
481
+ */
482
+ declare function decDebounce(wait: number): (_target: unknown, _key: string, descriptor: PropertyDescriptor) => void;
483
+
484
+ /**
485
+ * Only invokes the decorated function as long as it's called `<= n` times.
486
+ * Subsequent calls to the decorated function return the result of the last invocation.
487
+ *
488
+ * Look at {@link maxCalls} for the non-decorator version.
489
+ *
490
+ * *Requires the [experimentalDecorators](https://www.typescriptlang.org/tsconfig#experimentalDecorators) flag to be set.*
491
+ *
492
+ * @example
493
+ * ```typescript
494
+ * class TestClass {
495
+ * private count = 0;
496
+ * @decMaxCalls(2)
497
+ * testMethod() {
498
+ * return ++this.count;
499
+ * }
500
+ * }
501
+ * const instance = new TestClass();
502
+ * instance.testMethod(); // => 1
503
+ * instance.testMethod(); // => 2
504
+ * instance.testMethod(); // => 2
505
+ * ```
506
+ * @param n The number of calls before the cached result is returned.
507
+ */
508
+ declare function decMaxCalls(n: number): (_target: unknown, _key: string, descriptor: PropertyDescriptor) => void;
509
+
510
+ type GenericFunction<TFunc extends (...args: any) => any> = (...args: Parameters<TFunc>) => ReturnType<TFunc>;
511
+
512
+ /**
513
+ * Creates a function that memoizes the result of a given function.
514
+ *
515
+ * The cache key is determined by the `resolver` or by the arguments from the function call.
516
+ *
517
+ * **Options:**
518
+ * - `resolver` A function that determines the cache key based on the arguments provided.
519
+ * - `ttl` the time to live for the cache entries in milliseconds.
520
+ *
521
+ * **Properties:**
522
+ * - `cache` The cache is an instance of `Map` and can be used to clear or inspect the cache.
523
+ * It can be replaced by a custom cache that matches the `Map` interface.
524
+ *
525
+ *
526
+ * This function can be used as a decorator with {@link decMemoize}.
527
+ *
528
+ * @example
529
+ * ```typescript
530
+ * function fibonacci(n: number) {
531
+ * if (n <= 1) return n;
532
+ * return fibonacci(n - 1) + fibonacci(n - 2);
533
+ * }
534
+ *
535
+ * const memoizedFib = memoize(fibonacci, { ttl: 1000 })
536
+ *
537
+ * memoizedFib(40) // => 102334155
538
+ * memoizedFib(40) // => 102334155 (cache hit)
539
+ * setTimeout(() => memoizedFib(40), 1000) // => 102334155 (cache miss)
540
+ *
541
+ * // Cached values are exposed as the `cache` property.
542
+ * memoizedFib.cache.get("40") // => [value, timestamp]
543
+ * memoizedFib.cache.set("40", [1234, Date.now()])
544
+ * memoizedFib.cache.clear()
545
+ *
546
+ * // This is the default way to create cache keys.
547
+ * const defaultResolver = (...args: unknown[]) => JSON.stringify(args)
548
+ * ```
549
+ * @param func The function to have its output memoized.
550
+ * @param options The options object with optional `resolver` and `ttl` parameters.
551
+ * @param options.resolver - A function that determines the cache key for storing the result based on the arguments provided.
552
+ * @param options.ttl - The time to live for the cache in milliseconds.
553
+ * @template TFunc The type of the function to memoize.
554
+ * @template Cache The type of the cache storage.
555
+ * @returns Returns the new memoized function.
556
+ */
557
+ declare function memoize<TFunc extends GenericFunction<TFunc>, Cache extends Map<string, [ReturnType<TFunc>, number]>>(func: TFunc, options?: {
558
+ resolver?: (...args: Parameters<TFunc>) => string;
559
+ ttl?: number;
560
+ }): TFunc & {
561
+ cache: Cache;
562
+ };
563
+
564
+ /**
565
+ * Memoizes the decorated function.
566
+ * The cache key is either determined by the provided resolver or by the arguments used in the memoized function.
567
+ *
568
+ * **Options:**
569
+ * - `resolver` A function that determines the cache key for storing the result based on the arguments provided.
570
+ * - `ttl` sets the time to live for the cache in milliseconds. After `ttl` milliseconds, the next call to the memoized function will result in a cache miss.
571
+ *
572
+ * Look at {@link memoize} for the non-decorator version.
573
+ *
574
+ * *Requires the [experimentalDecorators](https://www.typescriptlang.org/tsconfig#experimentalDecorators) flag to be set.*
575
+ *
576
+ * @example
577
+ * ```typescript
578
+ * class TestClass {
579
+ * @decMemoize({ ttl: 1000 })
580
+ * testMethod(a: number, b: number) {
581
+ * return a + b;
582
+ * }
583
+ * }
584
+ * const instance = new TestClass();
585
+ * instance.testMethod(1, 2); // => 3
586
+ * instance.testMethod(1, 2); // => 3 (cached)
587
+ *
588
+ * // After 1 second:
589
+ * instance.testMethod(1, 2); // => 3 (cache miss)
590
+ * ```
591
+ * @param options The options object.
592
+ * @param options.resolver - A function that determines the cache key for storing the result based on the arguments provided.
593
+ * @param options.ttl - The time to live for the cache in milliseconds.
594
+ */
595
+ declare function decMemoize(options?: Parameters<typeof memoize>[1]): (_target: unknown, _key: string, descriptor: PropertyDescriptor) => void;
596
+
597
+ /**
598
+ * Only invokes the decorated function after it's called more than `n` times.
599
+ *
600
+ * Look at {@link minCalls} for the non-decorator version.
601
+ *
602
+ * *Requires the [experimentalDecorators](https://www.typescriptlang.org/tsconfig#experimentalDecorators) flag to be set.*
603
+ * @example
604
+ * ```typescript
605
+ * class TestClass {
606
+ * @decMinCalls(2)
607
+ * testMethod() {
608
+ * return 1;
609
+ * }
610
+ * }
611
+ * const instance = new TestClass();
612
+ * instance.testMethod(); // => undefined
613
+ * instance.testMethod(); // => undefined
614
+ * instance.testMethod(); // => 1
615
+ * ```
616
+ * @param n The number of calls before the decorated function is invoked.
617
+ */
618
+ declare function decMinCalls(n: number): (_target: unknown, _key: string, descriptor: PropertyDescriptor) => void;
619
+
620
+ /**
621
+ * The decorated function is invoked at most once per every `wait` milliseconds.
622
+ *
623
+ * Look at {@link throttle} for the non-decorator version.
624
+ *
625
+ * *Requires the [experimentalDecorators](https://www.typescriptlang.org/tsconfig#experimentalDecorators) flag to be set.*
626
+ *
627
+ * @example
628
+ * ```typescript
629
+ * class TestClass {
630
+ * @decThrottle(1000)
631
+ * testMethod() {
632
+ * console.log("Throttled!");
633
+ * }
634
+ * }
635
+ *
636
+ * const instance = new TestClass();
637
+ * instance.testMethod(); // => "Throttled!" is logged once per second.
638
+ * instance.testMethod(); // nothing happens
639
+ * ```
640
+ * @param wait The number of milliseconds to wait between invocations.
641
+ */
642
+ declare function decThrottle(wait: number): (_target: unknown, _key: string, descriptor: PropertyDescriptor) => void;
643
+
644
+ type Tail<T extends unknown[]> = T extends [infer _Head, ...infer Tail] ? Tail : never;
645
+ /**
646
+ * Transforms a function into a decorator function.
647
+ *
648
+ * @example
649
+ * ```typescript
650
+ * function log(func: Function, message: string) {
651
+ * return function (...args: unknown[]) {
652
+ * console.log(message);
653
+ * return func(...args);
654
+ * };
655
+ * }
656
+ *
657
+ * const logger = toDecorator(log);
658
+ *
659
+ * class TestClass {
660
+ * @logger("Hello world!")
661
+ * testMethod() {
662
+ * return 1;
663
+ * }
664
+ * }
665
+ *
666
+ * const instance = new TestClass();
667
+ * instance.testMethod();
668
+ * // => Log "Hello World" and return 1
669
+ * ```
670
+ * @param func The function to transform.
671
+ * @returns A decorator function that can be used to decorate a method.
672
+ */
673
+ declare function toDecorator<TFunc extends GenericFunction<TFunc>>(func: TFunc): (...args: Tail<Parameters<TFunc>>) => (_target: unknown, _key: string, descriptor: PropertyDescriptor) => void;
674
+
675
+ /**
676
+ * Creates a debounced version of a function. Only calling it after a specified amount of time has passed without any new calls.
677
+ *
678
+ * **Methods:**
679
+ * - `cancel` will cancel the next invocation of the debounced function.
680
+ * - `flush` will immediately invoke the debounced function and cancel any pending invocations.
681
+ *
682
+ * This function can be used as a decorator with {@link decDebounce}.
683
+ *
684
+ * @example
685
+ * const sayHello = (name: string) => console.log(`Hello, ${name}!`);
686
+ * const debouncedSayHello = debounce(sayHello, 200);
687
+ *
688
+ * debouncedSayHello("John");
689
+ * debouncedSayHello("Jane");
690
+ * // => Only the second invocation of `debouncedSayHello` is executed, after a delay of 200ms.
691
+ * @param func The function to debounce.
692
+ * @param wait The number of milliseconds to wait before invoking `func`.
693
+ * @returns A debounced version of `func` with `cancel` and `flush` methods.
694
+ */
695
+ declare function debounce<TFunc extends GenericFunction<TFunc>>(func: TFunc, wait: number): TFunc & {
696
+ cancel: () => void;
697
+ flush: () => void;
698
+ };
699
+
700
+ /**
701
+ * Creates a function that invokes the given function as long as it's called `<= n` times.
702
+ *
703
+ * Subsequent calls to the created function return the result of the last `func` invocation.
704
+ *
705
+ * This function can be used as a decorator with {@link decMaxCalls}.
706
+ * @example
707
+ * let count = 0;
708
+ * const addCount = () => ++count;
709
+ *
710
+ * // Allow addCount to be invoked twice.
711
+ * const limitAddCount = maxCalls(addCount, 2)
712
+ *
713
+ * limitAddCount() // => 1
714
+ * limitAddCount() // => 2
715
+ * limitAddCount() // => 2
716
+ * // => `limitAddCount` is invoked twice and the result is cached.
717
+ * @param n The number of calls before the cached result is returned.
718
+ * @param func The function to restrict.
719
+ * @returns Returns the new restricted function.
720
+ */
721
+ declare function maxCalls<TFunc extends GenericFunction<TFunc>>(func: TFunc, n: number): TFunc;
722
+
723
+ /**
724
+ * Creates a function that invokes the given function once it's called more than `n` times.
725
+ * Returns undefined until the minimum call count is reached.
726
+ *
727
+ * This function can be used as a decorator with {@link decMinCalls}.
728
+ * @example
729
+ * const caution = () => console.log("Caution!");
730
+ * const limitedCaution = minCalls(caution, 2);
731
+ *
732
+ * limitedCaution()
733
+ * limitedCaution()
734
+ * limitedCaution()
735
+ * // => `caution` is invoked on the third call.
736
+ * @param n The number of calls before the given function is invoked.
737
+ * @param func The function to restrict.
738
+ * @returns Returns the new restricted function.
739
+ */
740
+ declare function minCalls<TFunc extends GenericFunction<TFunc>>(func: TFunc, n: number): (this: unknown, ...args: Parameters<TFunc>) => ReturnType<TFunc> | undefined;
741
+
742
+ /**
743
+ * Generates a function that invokes the given function at most once per every `wait` milliseconds.
744
+ *
745
+ * This function can be used as a decorator with {@link decThrottle}.
746
+ * @example
747
+ * const throttled = throttle(() => console.log("Throttled!"), 1000);
748
+ *
749
+ * throttled();
750
+ * throttled();
751
+ * // => "Throttled!" is logged once per second.
752
+ * @param func The function to throttle.
753
+ * @param wait The number of milliseconds to throttle invocations to.
754
+ * @returns Returns the new throttled function.
755
+ */
756
+ declare function throttle<TFunc extends GenericFunction<TFunc>>(func: TFunc, wait: number): TFunc;
757
+
758
+ /**
759
+ * Invokes a function `n` times, returning an array of the results of
760
+ * each invocation.
761
+ *
762
+ * @example
763
+ * times(index => console.log("Run", index), 3)
764
+ * // => "Run 0" | "Run 1" | "Run 2"
765
+ * times(Math.random, 3)
766
+ * // => [0.123, 0.456, 0.789]
767
+ * times(() => 0, 4)
768
+ * // => [0, 0, 0, 0]
769
+ * @param n The number of times to invoke `func`.
770
+ * @param func The function invoked per iteration.
771
+ * @returns Returns an array of results.
772
+ */
773
+ declare function times<TInput>(func: (index: number) => TInput, n: number): TInput[];
774
+
775
+ /**
776
+ * Calculates the average of an array of numbers
777
+ *
778
+ * Returns `NaN` if the input array is empty.
779
+ * @example
780
+ * average([1, 2, 3, 4, 5]) // => 3
781
+ *
782
+ * @param numbers The input array of numbers
783
+ * @returns The average of the input array, or NaN if the input array is empty
784
+ */
785
+ declare function average(numbers: readonly number[]): number;
786
+
787
+ /**
788
+ * Calculates the median of an array of numbers
789
+ *
790
+ * Returns `NaN` if the input array is empty.
791
+ * @example
792
+ * median([1, 2, 3, 4, 5]) // => 3
793
+ * median([1, 2, 3, 4, 5, 6]) // => 3.5
794
+ *
795
+ * @param numbers The input array of numbers
796
+ * @returns The median of the input array
797
+ */
798
+ declare function median(numbers: readonly number[]): number;
799
+
800
+ /**
801
+ * Rounds a number to the given precision.
802
+ *
803
+ * @example
804
+ * round(1.23456, 2); // => 1.23
805
+ * round(1.235, 1); // => 1.2
806
+ * round(1234.56); // => 1234.56
807
+ *
808
+ * @param number The number to be rounded.
809
+ * @param precision The number of decimal places to round to. Defaults to 2.
810
+ * @returns The rounded number.
811
+ */
812
+ declare function round(number: number, precision?: number): number;
813
+
814
+ /**
815
+ * Calculates the sum of an array of numbers.
816
+ *
817
+ * Returns `NaN` if the input array is empty.
818
+ * @example
819
+ * sum([1, 2, 3, 4, 5]) // => 15
820
+ *
821
+ * @param numbers The input array of numbers
822
+ * @returns The sum of the input array
823
+ */
824
+ declare function sum(numbers: number[]): number;
825
+ declare function sum<TNum extends readonly number[]>(numbers: TNum): Call<Tuples.Sum, TNum>;
826
+
827
+ /**
828
+ * The type of a plain object.
829
+ *
830
+ * This is a more strict type than the `object` type which also includes functions and arrays.
831
+ *
832
+ * You can validate if a value is a plain object with {@link isPlainObject}.
833
+ * @example
834
+ * let obj: PlainObject = { a: 1, b: 2 };
835
+ *
836
+ * obj = [1, 2, 3];
837
+ * // => Type 'number[]' is not assignable to type 'PlainObject'.
838
+ */
839
+ type PlainObject = Record<PropertyKey, unknown>;
840
+
841
+ type StringIfNever<Type> = [Type] extends [never] ? string : Type;
842
+ type Paths$1<TObj> = StringIfNever<Call<Objects.AllPaths, TObj>>;
843
+ /**
844
+ * Flattens an object into a single level object.
845
+ *
846
+ * @example
847
+ * const obj = { a: { b: 2, c: [{ d: 3 }, { d: 4 }] } };
848
+ * flatKeys(obj);
849
+ * // => { 'a.b': 2, 'a.c[0].d': 3, 'a.c[1].d': 4 }
850
+ *
851
+ * @param obj The object to flatten.
852
+ * @template TObj The type of the object to flatten.
853
+ * @returns A new object with flattened keys.
854
+ */
855
+ declare function flatKeys<TObj extends PlainObject>(obj: TObj): Record<Paths$1<TObj>, unknown>;
856
+
857
+ /**
858
+ * This function combines two or more objects into a single new object. Arrays and other types are overwritten.
859
+ *
860
+ * @example
861
+ * // ---- Nested objects are merged ----
862
+ * merge({ a: 1 }, { b: 2 }, { c: 3, d: { e: 4 } })
863
+ * // => { a: 1, b: 2, c: 3, d: { e: 4 } }
864
+ *
865
+ * // ---- Other types are overwritten ----
866
+ * merge({ a: [1, 2] }, { a: [3, 4] })
867
+ * // => { a: [3, 4] }
868
+ *
869
+ * merge({ a: 1 }, { a: "Yes" })
870
+ * // => { a: "Yes" }
871
+ * @param target The target object
872
+ * @param sources The source objects
873
+ * @template TTarget The type of the target object
874
+ * @template TSources The type of the source objects
875
+ * @returns A new merged object
876
+ */
877
+ declare function merge<TTarget extends PlainObject, TSources extends ArrayMinLength<PlainObject, 1>>(target: TTarget, ...sources: TSources): MergeDeepObjects<[TTarget, ...TSources]>;
878
+ type OptionalPropertyNames<T> = {
879
+ [K in keyof T]-?: (PlainObject extends {
880
+ [P in K]: T[K];
881
+ } ? K : never);
882
+ }[keyof T];
883
+ type SpreadProperties<L, R, K extends keyof L & keyof R> = {
884
+ [P in K]: L[P] | Exclude<R[P], undefined>;
885
+ };
886
+ type Id<T> = T extends infer U ? {
887
+ [K in keyof U]: U[K];
888
+ } : never;
889
+ type SpreadTwo<L, R> = Id<Pick<L, Exclude<keyof L, keyof R>> & Pick<R, Exclude<keyof R, OptionalPropertyNames<R>>> & Pick<R, Exclude<OptionalPropertyNames<R>, keyof L>> & SpreadProperties<L, R, OptionalPropertyNames<R> & keyof L>>;
890
+ type MergeDeepObjects<A extends readonly [...unknown[]]> = A extends [infer L, ...infer R] ? SpreadTwo<L, MergeDeepObjects<R>> : unknown;
891
+
892
+ /**
893
+ * Omit specified keys from an object
894
+ *
895
+ * @example
896
+ * const obj = {a: 1, b: 2, c: 3};
897
+ * omit(obj, ['a', 'b']);
898
+ * // => {c: 3}
899
+ *
900
+ * @param object The object to filter
901
+ * @param keysToOmit The keys to exclude from the returned object
902
+ * @template TObj The type of the object
903
+ * @returns - An object without the specified keys
904
+ */
905
+ declare function omit<TObj extends PlainObject, Key extends keyof TObj>(object: TObj, keysToOmit: Key[]): Omit<TObj, Key>;
906
+
907
+ /**
908
+ * Creates an object composed of the picked `object` properties.
909
+ *
910
+ * @example
911
+ * const object = { 'a': 1, 'b': '2', 'c': 3 }
912
+ *
913
+ * pick(object, ['a', 'c'])
914
+ * // => { 'a': 1, 'c': 3 }
915
+ * @param object The source object.
916
+ * @param keysToPick The property paths to pick.
917
+ * @template TObj The type of the object.
918
+ * @returns Returns the new object.
919
+ */
920
+ declare function pick<TObj extends PlainObject, Key extends keyof TObj>(object: TObj, keysToPick: Key[]): Pick<TObj, Key>;
921
+
922
+ type Paths<TObj> = Call<Objects.AllPaths, TObj> | string & {};
923
+ type UpdateObj<TObj extends PlainObject, TPath extends string, TVal> = Call<Objects.Update<TPath, TVal>, TObj>;
924
+ /**
925
+ * Sets the value at path of object. If a portion of path doesn’t exist, it’s created.
926
+ *
927
+ * @example
928
+ * const obj = { a: { b: 2 } };
929
+ * set(obj, 'a.c', 1);
930
+ * // => { a: { b: 2, c: 1 } }
931
+ *
932
+ * // `[number]` can be used to access array elements
933
+ * set(obj, 'a.c[0]', 'hello');
934
+ * // => { a: { b: 2, c: ['hello'] } }
935
+ *
936
+ * // numbers with dots are treated as keys
937
+ * set(obj, 'a.c.0.d', 'world');
938
+ * // => { a: { b: 2, c: { 0: { d: 'world' } } }
939
+ *
940
+ * // supports numbers in keys
941
+ * set(obj, 'a.e0.a', 1);
942
+ * // => { a: { e0: { a: 1 } } }
943
+ *
944
+ * @param obj The object to modify.
945
+ * @param path The path of the property to set.
946
+ * @param value The value to set.
947
+ * @template TObj The type of the object.
948
+ * @template TPath The type of the object path.
949
+ * @template TVal The type of the value to set.
950
+ * @returns The modified object.
951
+ */
952
+ declare function set<TObj extends PlainObject, TPath extends Paths<TObj>, TVal>(obj: TObj, path: TPath, value: TVal): UpdateObj<TObj, TPath, TVal>;
953
+
954
+ /**
955
+ * A class managing an async function queue with limited concurrency (e.g., 10 functions with 3 running at a time).
956
+ *
957
+ * **Methods:**
958
+ * - `add` - Adds an async function or array of functions to the queue. Returns a promise that resolves or rejects when the added function(s) finish.
959
+ * - `clear` - Clears the queue.
960
+ * - `pause` - Pauses the queue.
961
+ * - `resume` - Resumes the queue.
962
+ * - `getQueue` - Returns the current queue.
963
+ * - `isPaused` - Returns whether the queue is paused.
964
+ * - `done` - Returns a promise resolving when all added tasks are finished. Individual rejections don't affect the done() promise.
965
+ *
966
+ * @example
967
+ * // Create a queue that can run 3 tasks concurrently
968
+ * const queue = new Queue(3);
969
+ *
970
+ * queue.add(() => fetch('https://example.com'));
971
+ *
972
+ * queue.add(async () => {
973
+ * const response = await fetch('https://example.com');
974
+ * return response.json();
975
+ * });
976
+ *
977
+ * await queue.done();
978
+ * console.log("All tasks finished");
979
+ *
980
+ * // Add an array of tasks to the queue and wait for them to resolve
981
+ * await queue.add([
982
+ * () => fetch('https://apple.com'),
983
+ * () => fetch('https://microsoft.com')
984
+ * ]);
985
+ * // => [Response, Response]
986
+ */
987
+ declare class Queue {
988
+ private running;
989
+ private maxConcurrent;
990
+ private paused;
991
+ private queue;
992
+ private finishedPromise;
993
+ private finishedResolver;
994
+ /**
995
+ * @constructor
996
+ * @param maxConcurrent The maximum number of async functions to run concurrently.
997
+ */
998
+ constructor(maxConcurrent: number);
999
+ /**
1000
+ * Add async functions or an array of async functions to the queue.
1001
+ *
1002
+ * @param asyncFn The async function(s) to add to the queue.
1003
+ * @returns A promise that resolves when the added function(s) finishes.
1004
+ */
1005
+ add<TProm, TAsyncFn extends () => Promise<TProm>>(asyncFn: TAsyncFn): Promise<TProm>;
1006
+ add<TProm, TAsyncFn extends () => Promise<TProm>>(asyncFn: TAsyncFn[]): Promise<TProm[]>;
1007
+ private buildWaitingPromise;
1008
+ private run;
1009
+ /** Removes all the tasks from the queue */
1010
+ clear(): void;
1011
+ /** Pauses the execution of the queue */
1012
+ pause(): void;
1013
+ /** Resumes the execution of the tasks in the queue */
1014
+ resume(): void;
1015
+ /** Return the tasks added to the queue */
1016
+ getQueue(): (() => Promise<any>)[];
1017
+ /** Returns whether the queue is paused */
1018
+ isPaused(): boolean;
1019
+ /** Returns a shared promise that resolves when the queue is empty and all tasks have finished executing. */
1020
+ done(): Promise<boolean>;
1021
+ private checkIfDone;
1022
+ }
1023
+
1024
+ /**
1025
+ * Similar to [Promise.race](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race?retiredLocale=de)
1026
+ * but allows to specify how many promises to wait for.
1027
+ *
1028
+ * @example
1029
+ * const prom1 = Promise.resolve(1);
1030
+ * const prom2 = new Promise(resolve => setTimeout(resolve, 100, 2));
1031
+ * const prom3 = Promise.resolve(3);
1032
+ *
1033
+ * const firstTwo = await races(2, prom1, prom2, prom3);
1034
+ * // => [1, 3]
1035
+ *
1036
+ * @template TRes The type of the result of the promises.
1037
+ * @param waitFor The number of promises to wait for.
1038
+ * @param promises The promises to wait for.
1039
+ * @returns A promise that resolves an array of the results of the first n promises.
1040
+ */
1041
+ declare function races<TRes>(waitFor: number, ...promises: Promise<TRes>[]): Promise<TRes[]>;
1042
+
1043
+ /**
1044
+ * Retry a function until it succeeds or the maximum number of retries is reached.
1045
+ *
1046
+ * Default maxRetries: `5`.
1047
+ * Default backoff: `2^retries * 100ms` (100, 200, 400, 800, 1600, 3200, ...)
1048
+ *
1049
+ * @example
1050
+ * await retry(() => fetch('https://example.com'));
1051
+ *
1052
+ * // ---- Advanced example ----
1053
+ * const fetchSite = async () => {
1054
+ * const response = await fetch('https://example.com');
1055
+ * if(!response.ok)
1056
+ * throw new Error('Failed to fetch');
1057
+ * }
1058
+ *
1059
+ * const logger = (error: unknown, retry?: number) => console.log("Retrying", retry, error);
1060
+ *
1061
+ * await retry(fetchSite, { maxRetries: 3, backoff: retries => retries * 1000, onRetry: logger });
1062
+ * // => Will retry 3 times with a 1 second delay between each retry.
1063
+ * // => Will log the error and retry number.
1064
+ *
1065
+ * @param func The function to retry.
1066
+ * @param options The options for the retry.
1067
+ * @param options.maxRetries The maximum number of retries. Defaults to `5`.
1068
+ * @param options.backoff The backoff function to use. Defaults to `2^retries * 100`.
1069
+ * @param options.onRetry The function to call when a retry is attempted. It will be called with the error and the attempt number.
1070
+ * @template TRes The type of the result of the function.
1071
+ * @returns A promise that resolves when the function succeeds.
1072
+ */
1073
+ declare function retry<TRes>(func: () => Promise<TRes>, options?: {
1074
+ maxRetries?: number;
1075
+ backoff?: ((retries: number) => number);
1076
+ onRetry?: (error?: unknown, attempted?: number) => void;
1077
+ }): Promise<TRes>;
1078
+
1079
+ /**
1080
+ * Sleeps for the given amount of time.
1081
+ *
1082
+ * @example
1083
+ * await sleep(1000);
1084
+ * // => Waits for 1 second.
1085
+ * @param ms Amount of time to sleep in milliseconds.
1086
+ * @returns A promise that resolves after the given amount of time.
1087
+ */
1088
+ declare function sleep(ms: number): Promise<unknown>;
1089
+
1090
+ /**
1091
+ * Returns a new promise that will reject with an error after a specified timeout.
1092
+ *
1093
+ * @example
1094
+ * try {
1095
+ * await timeout(fetch('https://example.com'), 1000);
1096
+ * } catch (error) {
1097
+ * console.log(error.message);
1098
+ * // => 'Promise timed out after 1000ms'
1099
+ * }
1100
+ * @template TRes - The type of the resolved value.
1101
+ * @param promise The promise to wrap.
1102
+ * @param timeout The timeout in milliseconds.
1103
+ *
1104
+ * @returns A new promise that will reject with an error after the specified timeout.
1105
+ */
1106
+ declare function timeout<TRes>(promise: Promise<TRes>, timeout: number): Promise<TRes>;
1107
+
1108
+ /**
1109
+ * Attempts to execute a promise and returns an array with the result or error.
1110
+ *
1111
+ * This is useful for handling errors in async functions without try/catch blocks.
1112
+ *
1113
+ * @example
1114
+ * ```typescript
1115
+ * const [data, error] = await tryCatch(fetch('https://example.com/api'));
1116
+ * if (error)
1117
+ * console.error(`Error: ${error.message}`);
1118
+ * ```
1119
+ * @param promise A Promise to be executed.
1120
+ * @returns A Promise that resolves to an array containing the result or error.
1121
+ * If the Promise executes successfully, the array contains the result and a null error.
1122
+ * If the Promise throws an error, the array contains undefined for the result and the error object.
1123
+ *
1124
+ * @template TRes The type of the result.
1125
+ */
1126
+ declare function tryCatch<TRes>(promise: Promise<TRes>): Promise<[TRes, undefined] | [undefined, Error]>;
1127
+
1128
+ /**
1129
+ * Converts `string` to camelCase.
1130
+ *
1131
+ * @example
1132
+ * camelCase('Foo Bar')
1133
+ * // => 'fooBar'
1134
+ * camelCase('--foo-bar--')
1135
+ * // => 'fooBar'
1136
+ * camelCase('__FOO_BAR__')
1137
+ * // => 'fooBar'
1138
+ * @param str The string to convert.
1139
+ * @returns Returns the camel cased string.
1140
+ */
1141
+ declare function camelCase(str: string): string;
1142
+
1143
+ /**
1144
+ * Converts the first character of a string to upper case and the remaining to lower case.
1145
+ *
1146
+ * @example
1147
+ * capitalize('FRED')
1148
+ * // => 'Fred'
1149
+ * @param str The string to capitalize.
1150
+ * @returns Returns the capitalized string.
1151
+ */
1152
+ declare function capitalize(str: string): string;
1153
+
1154
+ /**
1155
+ * Deburrs a string by converting
1156
+ * [Latin-1 Supplement](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
1157
+ * and [Latin Extended-A](https://en.wikipedia.org/wiki/Latin_Extended-A)
1158
+ * letters to basic Latin letters and removing
1159
+ * [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
1160
+ *
1161
+ * @example
1162
+ * deburr('déjà vu')
1163
+ * // => 'deja vu'
1164
+ * @param str The string to deburr.
1165
+ * @returns Returns the deburred string.
1166
+ */
1167
+ declare function deburr(str: string): string;
1168
+
1169
+ /**
1170
+ * Converts the characters `&`, `<`, `>`, `"` and `'` in a string to their corresponding HTML entities.
1171
+ *
1172
+ * @example
1173
+ * escapeHtml('fred, barney, & pebbles')
1174
+ * // => 'fred, barney, &amp; pebbles'
1175
+ * @param str The string to escape.
1176
+ * @returns Returns the escaped string.
1177
+ */
1178
+ declare function escapeHtml(str: string): string;
1179
+
1180
+ /**
1181
+ * Escapes the `RegExp` special characters `^`, `$`, `\`, `.`, `*`, `+`,
1182
+ * `?`, `(`, `)`, `[`, `]`, `{`, `}`, and `|` in a string.
1183
+ *
1184
+ * @example
1185
+ * escapeRegExp('[moderndash](https://moderndash.io/)')
1186
+ * // => '\[moderndash\]\(https://moderndash\.io/\)'
1187
+ * @param str The string to escape.
1188
+ * @returns Returns the escaped string.
1189
+ */
1190
+ declare function escapeRegExp(str: string): string;
1191
+
1192
+ /**
1193
+ * Converts a string to kebab-case.
1194
+ *
1195
+ * @example
1196
+ * kebabCase('Foo Bar')
1197
+ * // => 'foo-bar'
1198
+ * kebabCase('fooBar')
1199
+ * // => 'foo-bar'
1200
+ * kebabCase('__FOO_BAR__')
1201
+ * // => 'foo-bar'
1202
+ *
1203
+ * @param str The string to convert.
1204
+ * @returns Returns the kebab cased string.
1205
+ */
1206
+ declare function kebabCase(str: string): string;
1207
+
1208
+ /**
1209
+ * Converts a string to PascalCase.
1210
+ *
1211
+ * @example
1212
+ * pascalCase('Foo Bar')
1213
+ * // => 'FooBar'
1214
+ * pascalCase('fooBar')
1215
+ * // => 'FooBar'
1216
+ * pascalCase('__FOO_BAR__')
1217
+ * // => 'FooBar'
1218
+ *
1219
+ * @param str The string to convert.
1220
+ * @returns Returns the pascal cased string.
1221
+ */
1222
+ declare function pascalCase(str: string): string;
1223
+
1224
+ /**
1225
+ * Replaces the last occurrence of a string.
1226
+ *
1227
+ * @example
1228
+ * ```typescript
1229
+ * replaceLast("Foo Bar Bar", "Bar", "Boo");
1230
+ * // => "Foo Bar Boo"
1231
+ * ```
1232
+ *
1233
+ * @param str The string to replace in.
1234
+ * @param searchFor The string to search for.
1235
+ * @param replaceWith The string to replace with.
1236
+ * @returns The replaced string.
1237
+ */
1238
+ declare function replaceLast(str: string, searchFor: string, replaceWith: string): string;
1239
+
1240
+ /**
1241
+ * Converts a string to snake_case.
1242
+ *
1243
+ * @example
1244
+ * snakeCase('Foo Bar')
1245
+ * // => 'foo_bar'
1246
+ * snakeCase('fooBar')
1247
+ * // => 'foo_bar'
1248
+ * snakeCase('--FOO-BAR--')
1249
+ * // => 'foo_bar'
1250
+ * snakeCase('foo2bar')
1251
+ * // => 'foo_2_bar'
1252
+ *
1253
+ * @param str The string to convert.
1254
+ * @returns Returns the snake cased string.
1255
+ */
1256
+ declare function snakeCase(str: string): string;
1257
+
1258
+ /**
1259
+ * Split a string into words. Can deal with camelCase, PascalCase & snake_case.
1260
+ *
1261
+ * @example
1262
+ * splitWords('camelCase')
1263
+ * // => ['camel', 'Case']
1264
+ *
1265
+ * splitWords('PascalCase')
1266
+ * // => ['Pascal', 'Case']
1267
+ *
1268
+ * splitWords('hello_world-123')
1269
+ * // => ['hello', 'world', '123']
1270
+ *
1271
+ * @param str The string to split into words.
1272
+ * @returns An array of words.
1273
+ */
1274
+ declare function splitWords(str: string): string[];
1275
+
1276
+ /**
1277
+ * Converts a string to Title Case.
1278
+ *
1279
+ * @example
1280
+ * titleCase('--foo-bar--')
1281
+ * // => 'Foo Bar'
1282
+ * titleCase('fooBar')
1283
+ * // => 'Foo Bar'
1284
+ * titleCase('__FOO_BAR__')
1285
+ * // => 'Foo Bar'
1286
+ * titleCase('HélloWorld')
1287
+ * // => 'Hello World'
1288
+ * @param str The string to convert.
1289
+ * @returns Returns the title cased string.
1290
+ */
1291
+ declare function titleCase(str: string): string;
1292
+
1293
+ /**
1294
+ * Trim the string from the left and right by the given characters
1295
+ *
1296
+ * *Use the native [trim](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trim) method if you want to trim whitespace.*
1297
+ * @example
1298
+ * ```ts
1299
+ * trim('$$abc$', '$') // => 'abc'
1300
+ * trim('!!abc_!', '_!') // => 'abc'
1301
+ * ```
1302
+ * @param str The string to trim
1303
+ * @param chars The characters to trim
1304
+ * @returns The trimmed string
1305
+ */
1306
+ declare function trim(str: string, chars: string): string;
1307
+
1308
+ /**
1309
+ * Trims the specified characters from the end of the string.
1310
+ *
1311
+ * *Use the native [trimEnd](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimEnd) method if you want to trim whitespace.*
1312
+ * @example
1313
+ * ```ts
1314
+ * trimEnd('abc$$$', '$') // => 'abc'
1315
+ * trimEnd('abc_!!_', '_!') // => 'abc'
1316
+ * ```
1317
+ * @param str The string to trim
1318
+ * @param chars The characters to trim
1319
+ * @returns The trimmed string
1320
+ */
1321
+ declare function trimEnd(str: string, chars: string): string;
1322
+
1323
+ /**
1324
+ * Trims specified characters from the start of the string.
1325
+ *
1326
+ * *Use the native [trimStart](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimStart) method if you want to trim whitespace.*
1327
+ * @example
1328
+ * ```ts
1329
+ * trimStart('$$$abc', '$') // => 'abc'
1330
+ * trimStart('_!!_abc', '_!') // => 'abc'
1331
+ * ```
1332
+ * @param str The string to trim
1333
+ * @param chars The characters to trim
1334
+ * @returns The trimmed string
1335
+ */
1336
+ declare function trimStart(str: string, chars: string): string;
1337
+
1338
+ /**
1339
+ * Converts the HTML entities `&amp;`, `&lt;`, `&gt;`, `&quot;` and `&#39;`
1340
+ * in a string to their corresponding characters.
1341
+ *
1342
+ * @example
1343
+ * unescapeHtml('fred, barney, &amp; pebbles')
1344
+ * // => 'fred, barney, & pebbles'
1345
+ * @param str The string to unescape.
1346
+ * @returns Returns the unescaped string.
1347
+ */
1348
+ declare function unescapeHtml(str: string): string;
1349
+
1350
+ /**
1351
+ * Checks if a value is empty.
1352
+ *
1353
+ * Supports: strings, arrays, objects, maps, sets, typed arrays.
1354
+ * @example
1355
+ * isEmpty(null)
1356
+ * // => true
1357
+ *
1358
+ * isEmpty({})
1359
+ * // => true
1360
+ *
1361
+ * isEmpty("")
1362
+ * // => true
1363
+ *
1364
+ * isEmpty([1, 2, 3])
1365
+ * // => false
1366
+ *
1367
+ * isEmpty('abc')
1368
+ * // => false
1369
+ *
1370
+ * isEmpty({ 'a': 1 })
1371
+ * // => false
1372
+ * @param value The value to check.
1373
+ * @returns Returns `true` if `value` is empty, else `false`.
1374
+ */
1375
+ declare function isEmpty(value: string | object | null | undefined): boolean;
1376
+
1377
+ /**
1378
+ * Performs a deep comparison between two values to determine if they are
1379
+ * equivalent.
1380
+ *
1381
+ * Supports: primitives, arrays, objects, dates, regexes, maps, sets, buffers, typed arrays
1382
+ *
1383
+ * @example
1384
+ * const object = { a: { b: 2 } };
1385
+ * Const other = { a: { b: 2 } };
1386
+ *
1387
+ * isEqual(object, other);
1388
+ * // => true
1389
+ *
1390
+ * object === other;
1391
+ * // => false
1392
+ * @param a The value to compare.
1393
+ * @param b The other value to compare.
1394
+ * @returns Returns `true` if the values are equivalent, else `false`.
1395
+ */
1396
+ declare function isEqual(a: unknown, b: unknown): boolean;
1397
+
1398
+ /**
1399
+ * Checks if the value is a plain object.
1400
+ *
1401
+ * Refers to the {@link PlainObject} type.
1402
+ * @example
1403
+ * isPlainObject({}) // => true
1404
+ * isPlainObject({ a: 1 }) // => true
1405
+ * isPlainObject(null) // => false
1406
+ * isPlainObject('1') // => false
1407
+ * isPlainObject([]) // => false
1408
+ * isPlainObject(new Function()) // => false
1409
+ * isPlainObject(new Date()) // => false
1410
+ * @param value The value to check
1411
+ * @returns Boolean indicating if the value is a plain object
1412
+ */
1413
+ declare function isPlainObject(value: unknown): value is PlainObject;
1414
+
1415
+ /**
1416
+ * Checks if given string is a valid URL
1417
+ *
1418
+ * @example
1419
+ * isUrl('https://google.com')
1420
+ * // => true
1421
+ * isUrl('google.com')
1422
+ * // => false
1423
+ * @param str The string to check.
1424
+ * @returns Returns `true` if given string is a valid URL, else `false`.
1425
+ */
1426
+ declare function isUrl(str: string): boolean;
1427
+
1428
+ export { ArrayMinLength, GenericFunction, Jsonifiable, PlainObject, Queue, average, camelCase, capitalize, chunk, count, debounce, deburr, decDebounce, decMaxCalls, decMemoize, decMinCalls, decThrottle, difference, dropRightWhile, dropWhile, escapeHtml, escapeRegExp, flatKeys, group, hash, intersection, isEmpty, isEqual, isPlainObject, isUrl, kebabCase, maxCalls, median, memoize, merge, minCalls, move, omit, pascalCase, pick, races, randomElem, randomFloat, randomInt, randomString, range, replaceLast, retry, round, set, shuffle, sleep, snakeCase, sort, splitWords, sum, takeRightWhile, takeWhile, throttle, timeout, times, titleCase, toDecorator, trim, trimEnd, trimStart, tryCatch, unescapeHtml, unique };