qznt 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +138 -0
- package/dist/index.cjs +1107 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.mts +952 -0
- package/dist/index.d.ts +952 -0
- package/dist/index.js +1059 -0
- package/dist/index.js.map +1 -0
- package/dist/metafile-cjs.json +1 -0
- package/dist/metafile-esm.json +1 -0
- package/package.json +35 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,952 @@
|
|
|
1
|
+
type SequentialMapContext<T, U> = {
|
|
2
|
+
index: number;
|
|
3
|
+
lastElement: U | undefined;
|
|
4
|
+
newArray: ReadonlyArray<U>;
|
|
5
|
+
originalArray: ReadonlyArray<T>;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Splits an array into sub-arrays (chunks) of a maximum size.
|
|
9
|
+
* @param array Array to process.
|
|
10
|
+
* @param size The maximum size of each chunk.
|
|
11
|
+
*/
|
|
12
|
+
declare function chunk<T>(array: ReadonlyArray<T>, size: number): T[][];
|
|
13
|
+
/**
|
|
14
|
+
* Groups adjacent elements of an array together based on a predicate.
|
|
15
|
+
* @param array Array to process.
|
|
16
|
+
* @param predicate A function that returns true if two adjacent elements belong in the same chunk.
|
|
17
|
+
* @example
|
|
18
|
+
* // Group consecutive identical numbers
|
|
19
|
+
* chunkBy([1, 1, 2, 3, 3, 3], (a, b) => a === b);
|
|
20
|
+
* // [[1, 1], [2], [3, 3, 3]]
|
|
21
|
+
*/
|
|
22
|
+
declare function chunkAdj<T>(array: ReadonlyArray<T>, predicate: (prev: T, curr: T) => boolean): T[][];
|
|
23
|
+
/**
|
|
24
|
+
* Groups elements by a key.
|
|
25
|
+
* @param array Array to process.
|
|
26
|
+
* @param iteratee Function to determine the key to group by.
|
|
27
|
+
* @param maxChunkSize Optionally chunk groups and flatten them (useful for pagination).
|
|
28
|
+
*/
|
|
29
|
+
declare function cluster<T>(array: ReadonlyArray<T>, iteratee: (item: T) => string | number, maxChunkSize?: number): T[][];
|
|
30
|
+
/**
|
|
31
|
+
* Removes unwanted values from an array.
|
|
32
|
+
* @param array Array to process.
|
|
33
|
+
* @param mode 'nullable' (default) removes null/undefined. 'falsy' removes null, undefined, 0, "", false, and NaN.
|
|
34
|
+
*/
|
|
35
|
+
declare function compact<T>(array: ReadonlyArray<T>, mode?: "nullable"): NonNullable<T>[];
|
|
36
|
+
declare function compact<T>(array: ReadonlyArray<T>, mode: "falsy"): Exclude<T, null | undefined | false | 0 | "">[];
|
|
37
|
+
/**
|
|
38
|
+
* Forces a given item to be an array.
|
|
39
|
+
* @param item The item to force into an array.
|
|
40
|
+
*/
|
|
41
|
+
declare function forceArray<T>(item: T): T[];
|
|
42
|
+
/**
|
|
43
|
+
* Searches a sorted array for a value using the binary search method.
|
|
44
|
+
* Returns the index if found, or the bitwise complement (~index) of the
|
|
45
|
+
* position where the value should be inserted to keep it sorted.
|
|
46
|
+
* @param array The array to process.
|
|
47
|
+
* @param target The value to search for.
|
|
48
|
+
* @param comparator Optional comparator function.
|
|
49
|
+
*/
|
|
50
|
+
declare function search<T>(array: T[], target: T, comparator?: (a: T, b: T) => number): number;
|
|
51
|
+
/**
|
|
52
|
+
* Maps over an array with access to the previously mapped elements.
|
|
53
|
+
* @param array Array to process.
|
|
54
|
+
* @param callback Function to map over the array.
|
|
55
|
+
*/
|
|
56
|
+
declare function seqMap<T, U>(array: ReadonlyArray<T>, callback: (item: T, context: SequentialMapContext<T, U>) => U): U[];
|
|
57
|
+
/**
|
|
58
|
+
* Shuffles an array using the Fisher-Yates algorithm.
|
|
59
|
+
* @param array The array to shuffle.
|
|
60
|
+
* @param seed Optional seed for RNG.
|
|
61
|
+
*/
|
|
62
|
+
declare function shuffle<T>(array: ReadonlyArray<T>, seed?: number): T[];
|
|
63
|
+
/**
|
|
64
|
+
* Sorts an array by a single property in order.
|
|
65
|
+
* @param order 'asc' for ascending (default) or 'desc' for descending.
|
|
66
|
+
* @param array Array to process.
|
|
67
|
+
* @param selector Function to determine the key to sort by.
|
|
68
|
+
*/
|
|
69
|
+
declare function sortBy<T>(array: ReadonlyArray<T>, selector: (item: T) => any, order?: "asc" | "desc"): T[];
|
|
70
|
+
/**
|
|
71
|
+
* Sorts an array by one or more properties in order.
|
|
72
|
+
* @param order 'asc' for ascending (default) or 'desc' for descending.
|
|
73
|
+
* @param array Array to process.
|
|
74
|
+
* @param selectors Functions to determine the keys to sort by.
|
|
75
|
+
*/
|
|
76
|
+
declare function sortBy<T>(array: ReadonlyArray<T>, selectors: (item: T) => any[], order?: "asc" | "desc"): T[];
|
|
77
|
+
/**
|
|
78
|
+
* Returns an array of unique elements from the given array.
|
|
79
|
+
* Uniqueness is determined by the given key function.
|
|
80
|
+
* @param array Array to process.
|
|
81
|
+
* @param key Function to determine the keys to filter by
|
|
82
|
+
*/
|
|
83
|
+
declare function unique<T>(array: T[], key: (item: T) => any): T[];
|
|
84
|
+
declare const arr: {
|
|
85
|
+
chunk: typeof chunk;
|
|
86
|
+
chunkAdj: typeof chunkAdj;
|
|
87
|
+
cluster: typeof cluster;
|
|
88
|
+
compact: typeof compact;
|
|
89
|
+
forceArray: typeof forceArray;
|
|
90
|
+
search: typeof search;
|
|
91
|
+
seqMap: typeof seqMap;
|
|
92
|
+
shuffle: typeof shuffle;
|
|
93
|
+
sortBy: typeof sortBy;
|
|
94
|
+
unique: typeof unique;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
interface MemoizedFunction<T extends (...args: any[]) => any> {
|
|
98
|
+
(...args: Parameters<T>): ReturnType<T>;
|
|
99
|
+
/** Clears the cache. */
|
|
100
|
+
clear: () => void;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Memoizes a function by caching its results based on the input arguments.
|
|
104
|
+
* A resolver function can be provided to customize the key generation.
|
|
105
|
+
* If no resolver is provided, the key will be generated by JSON stringify-ing the input arguments.
|
|
106
|
+
* @param fn The function to memoize.
|
|
107
|
+
* @param resolver An optional resolver function to customize the key generation.
|
|
108
|
+
* @example
|
|
109
|
+
* // 1. Basic usage
|
|
110
|
+
* const heavyCalc = memoize((n: number) => {
|
|
111
|
+
* console.log('Calculating...');
|
|
112
|
+
* return n * 2;
|
|
113
|
+
* });
|
|
114
|
+
* heavyCalc(5); // Logs 'Calculating...' and returns 10
|
|
115
|
+
* heavyCalc(5); // Returns 10 immediately from cache
|
|
116
|
+
* @example
|
|
117
|
+
* // 2. Using maxAge (TTL)
|
|
118
|
+
* const getStockPrice = memoize(fetchPrice, { maxAge: 60000 }); // 1 minute cache
|
|
119
|
+
* @example
|
|
120
|
+
* // 3. Using a custom resolver
|
|
121
|
+
* const getUser = memoize(
|
|
122
|
+
* (user, theme) => render(user, theme),
|
|
123
|
+
* { resolver: (user) => user.id } // Only cache based on ID, ignore theme
|
|
124
|
+
* );
|
|
125
|
+
* @example
|
|
126
|
+
* // 4. Manual cache clearing
|
|
127
|
+
* heavyCalc.clear();
|
|
128
|
+
*/
|
|
129
|
+
declare function memoize<T extends (...args: any[]) => any>(fn: T, options?: {
|
|
130
|
+
/** Function to generate a cache key from the input arguments. */
|
|
131
|
+
resolver?: (...args: Parameters<T>) => string;
|
|
132
|
+
/** The time to wait in milliseconds before expiring a cache entry. */
|
|
133
|
+
maxAge?: number;
|
|
134
|
+
}): MemoizedFunction<T>;
|
|
135
|
+
declare const fn: {
|
|
136
|
+
memoize: typeof memoize;
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
interface DateOptions {
|
|
140
|
+
/** The reference timestamp to calculate from. Defaults to Date.now() */
|
|
141
|
+
since?: number | Date;
|
|
142
|
+
/** If true, returns null if the target time is in the past. */
|
|
143
|
+
nullIfPast?: boolean;
|
|
144
|
+
/** If true, omits the " ago" suffix for past dates. */
|
|
145
|
+
ignorePast?: boolean;
|
|
146
|
+
}
|
|
147
|
+
interface ParseOptions {
|
|
148
|
+
/** Return value in seconds instead of milliseconds. */
|
|
149
|
+
unit?: "ms" | "s";
|
|
150
|
+
/** If true, returns the absolute Unix timestamp (Date.now() + result). */
|
|
151
|
+
fromNow?: boolean;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Duration formatter.
|
|
155
|
+
*
|
|
156
|
+
* Available styles:
|
|
157
|
+
* - Digital (00:00)
|
|
158
|
+
* - HMS
|
|
159
|
+
* - YMDHMS.
|
|
160
|
+
* @param target The target time to calculate from.
|
|
161
|
+
* @param style The output style to use.
|
|
162
|
+
* @param options Formatting options.
|
|
163
|
+
*/
|
|
164
|
+
declare function duration(target: number | Date, style?: "digital" | "hms" | "ymdhms", options?: DateOptions): string | null;
|
|
165
|
+
/**
|
|
166
|
+
* Formats a date or timestamp into a human-readable relative string (e.g., "3 days ago").
|
|
167
|
+
* @param date - The Date object or timestamp to compare.
|
|
168
|
+
* @param locale - The BCP 47 language tag.
|
|
169
|
+
*/
|
|
170
|
+
declare function eta(date: Date | number, locale?: Intl.LocalesArgument): string;
|
|
171
|
+
/**
|
|
172
|
+
* Parses shorthand strings (1h 30m) into milliseconds or seconds.
|
|
173
|
+
*/
|
|
174
|
+
declare function parse(str: string | number, options?: ParseOptions): number;
|
|
175
|
+
declare const date: {
|
|
176
|
+
duration: typeof duration;
|
|
177
|
+
eta: typeof eta;
|
|
178
|
+
parse: typeof parse;
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
type AlphaCasing = "lower" | "upper" | "mixed";
|
|
182
|
+
interface RndStrOptions {
|
|
183
|
+
casing?: AlphaCasing;
|
|
184
|
+
seed?: number;
|
|
185
|
+
customChars?: string;
|
|
186
|
+
exclude?: string | string[];
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Returns true based on a percentage probability.
|
|
190
|
+
* @param percent A value between 0 and 1. [default: 0.5]
|
|
191
|
+
* @param seed Optional seed for RNG.
|
|
192
|
+
*/
|
|
193
|
+
declare function chance(percent?: number, seed?: number): boolean;
|
|
194
|
+
/**
|
|
195
|
+
* Returns a random item from the given array.
|
|
196
|
+
* @param array Array of items to choose from.
|
|
197
|
+
* @param seed Optional seed for RNG.
|
|
198
|
+
*/
|
|
199
|
+
declare function choice<T>(array: T[], seed?: number): T;
|
|
200
|
+
/**
|
|
201
|
+
* Returns a random item from the given array based on their corresponding weights.
|
|
202
|
+
* @param array Array of items to choose from.
|
|
203
|
+
* @param selector Function that selects the item's weight.
|
|
204
|
+
* @param seed Optional seed for RNG.
|
|
205
|
+
*/
|
|
206
|
+
declare function weighted<T>(array: T[], selector: (item: T) => number, seed?: number): T;
|
|
207
|
+
/**
|
|
208
|
+
* Returns an object with a single method, `pick`, which returns a random item from the given array in O(1) time.
|
|
209
|
+
* The probability of each item being picked is determined by the corresponding weight in the `weights` array.
|
|
210
|
+
* @param items Array of items to choose from.
|
|
211
|
+
* @param selector Function that selects the item's weight.
|
|
212
|
+
* @param seed Optional seed for RNG.
|
|
213
|
+
*/
|
|
214
|
+
declare function sampler<T>(items: T[], selector: (item: T) => number, seed?: number): {
|
|
215
|
+
/**
|
|
216
|
+
* Returns a random item from the given array in O(1) time.
|
|
217
|
+
* @param seed Optional seed for RNG.
|
|
218
|
+
*/
|
|
219
|
+
pick: (seed?: number) => T | undefined;
|
|
220
|
+
};
|
|
221
|
+
/**
|
|
222
|
+
* Creates a deterministic pseudo-random number generator (PRNG) using the Mulberry32 algorithm.
|
|
223
|
+
* @param seed An integer seed value.
|
|
224
|
+
* @example
|
|
225
|
+
* const rng = prng(123);
|
|
226
|
+
* const val1 = rng(); // Always the same for seed 123
|
|
227
|
+
*/
|
|
228
|
+
declare function prng(seed: number): () => number;
|
|
229
|
+
/**
|
|
230
|
+
* Generates a random float between the given minimum and maximum values.
|
|
231
|
+
* @param min The minimum value (inclusive) for the random float.
|
|
232
|
+
* @param max The maximum value (inclusive) for the random float.
|
|
233
|
+
* @param seed Optional seed for RNG.
|
|
234
|
+
*/
|
|
235
|
+
declare function float(min: number, max: number, seed?: number): number;
|
|
236
|
+
/**
|
|
237
|
+
* Returns a random index from the given array.
|
|
238
|
+
* @param array The array to generate an index for.
|
|
239
|
+
* @param seed Optional seed for RNG.
|
|
240
|
+
*/
|
|
241
|
+
declare function index(array: any[], seed?: number): number;
|
|
242
|
+
/**
|
|
243
|
+
* Generates a random integer between the given minimum and maximum values.
|
|
244
|
+
* @param min The minimum value (inclusive) for the random integer.
|
|
245
|
+
* @param max The maximum value (inclusive) for the random integer.
|
|
246
|
+
* @param seed Optional seed for RNG.
|
|
247
|
+
*/
|
|
248
|
+
declare function int(min: number, max: number, seed?: number): number;
|
|
249
|
+
/**
|
|
250
|
+
* Generates a random string of the given length using the specified character pool.
|
|
251
|
+
* @param len The length of the random string.
|
|
252
|
+
* @param mode The character pool to use. Can be "number", "alpha", "alphanumeric", or "custom".
|
|
253
|
+
* @param options Options for the rndStr function.
|
|
254
|
+
*/
|
|
255
|
+
declare function str$1(len: number, mode: "number" | "alpha" | "alphanumeric" | "custom", options?: RndStrOptions): string;
|
|
256
|
+
declare const rnd: {
|
|
257
|
+
chance: typeof chance;
|
|
258
|
+
choice: typeof choice;
|
|
259
|
+
weighted: typeof weighted;
|
|
260
|
+
sampler: typeof sampler;
|
|
261
|
+
prng: typeof prng;
|
|
262
|
+
float: typeof float;
|
|
263
|
+
index: typeof index;
|
|
264
|
+
int: typeof int;
|
|
265
|
+
str: typeof str$1;
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
interface DebouncedFunction<T extends (...args: any[]) => any> {
|
|
269
|
+
(...args: Parameters<T>): void;
|
|
270
|
+
/** Cancels the debounced function. */
|
|
271
|
+
cancel: () => void;
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Only executes after 'wait' ms have passed since the last call.
|
|
275
|
+
* @param fn The function to debounce.
|
|
276
|
+
* @param wait The time to wait in milliseconds.
|
|
277
|
+
* @param options Options for the debounce function.
|
|
278
|
+
* @example
|
|
279
|
+
* const search = debounce((str) => console.log("Searching:", str), 500);
|
|
280
|
+
* // Even if called rapidly, it only logs once 500ms after the last call.
|
|
281
|
+
* search('a');
|
|
282
|
+
* search('ab');
|
|
283
|
+
* search('abc'); // Only 'abc' will be logged.
|
|
284
|
+
* // Cancel a pending execution
|
|
285
|
+
* search.cancel();
|
|
286
|
+
*/
|
|
287
|
+
declare function debounce<T extends (...args: any[]) => any>(fn: T, wait: number, options?: {
|
|
288
|
+
/** Calls the function immediately on the leading edge. */
|
|
289
|
+
immediate?: boolean;
|
|
290
|
+
}): DebouncedFunction<T>;
|
|
291
|
+
/**
|
|
292
|
+
* Executes at most once every 'limit' ms.
|
|
293
|
+
* @param fn The function to throttle.
|
|
294
|
+
* @param limit The time to wait in milliseconds.
|
|
295
|
+
* @example
|
|
296
|
+
* const handleScroll = throttle(() => console.log('Scroll position:', window.scrollY), 200);
|
|
297
|
+
* // Even if the browser fires 100 scroll events per second,
|
|
298
|
+
* // this function will only execute once every 200ms.
|
|
299
|
+
* window.addEventListener('scroll', handleScroll);
|
|
300
|
+
*/
|
|
301
|
+
declare function throttle<T extends (...args: any[]) => any>(fn: T, limit: number): (...args: Parameters<T>) => void;
|
|
302
|
+
/**
|
|
303
|
+
* Returns a promise that resolves after the given number of milliseconds.
|
|
304
|
+
* @param ms The time to wait in milliseconds.
|
|
305
|
+
*/
|
|
306
|
+
declare function wait(ms: number): Promise<boolean>;
|
|
307
|
+
declare const timing: {
|
|
308
|
+
debounce: typeof debounce;
|
|
309
|
+
throttle: typeof throttle;
|
|
310
|
+
wait: typeof wait;
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
type ToRecordContext<T, V> = {
|
|
314
|
+
index: number;
|
|
315
|
+
lastValue: V | undefined;
|
|
316
|
+
newRecord: Readonly<Record<string | number, V>>;
|
|
317
|
+
originalArray: ReadonlyArray<T>;
|
|
318
|
+
};
|
|
319
|
+
/**
|
|
320
|
+
* Transforms an array into a object record with access to the object as it's being built.
|
|
321
|
+
* @param array Array to process.
|
|
322
|
+
* @param callback Function to map over the array.
|
|
323
|
+
*/
|
|
324
|
+
declare function record<T, V>(array: ReadonlyArray<T>, callback: (item: T, context: ToRecordContext<T, V>) => {
|
|
325
|
+
key: string | number;
|
|
326
|
+
value: V;
|
|
327
|
+
}): Record<string | number, V>;
|
|
328
|
+
declare const to: {
|
|
329
|
+
record: typeof record;
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* Pipes a value through a series of functions.
|
|
334
|
+
* Each function takes the output of the previous one.
|
|
335
|
+
*/
|
|
336
|
+
declare function Pipe<A>(value: A): A;
|
|
337
|
+
declare function Pipe<A, B>(value: A, fn1: (arg: A) => B): B;
|
|
338
|
+
declare function Pipe<A, B, C>(value: A, fn1: (arg: A) => B, fn2: (arg: B) => C): C;
|
|
339
|
+
declare function Pipe<A, B, C, D>(value: A, fn1: (arg: A) => B, fn2: (arg: B) => C, fn3: (arg: C) => D): D;
|
|
340
|
+
declare function Pipe<A, B, C, D, E>(value: A, fn1: (arg: A) => B, fn2: (arg: B) => C, fn3: (arg: C) => D, fn4: (arg: D) => E): E;
|
|
341
|
+
declare function Pipe<A, B, C, D, E, F>(value: A, fn1: (arg: A) => B, fn2: (arg: B) => C, fn3: (arg: C) => D, fn4: (arg: D) => E, fn5: (arg: E) => F): F;
|
|
342
|
+
declare function Pipe<A, B, C, D, E, F, G>(value: A, fn1: (arg: A) => B, fn2: (arg: B) => C, fn3: (arg: C) => D, fn4: (arg: D) => E, fn5: (arg: E) => F, fn6: (arg: F) => G): G;
|
|
343
|
+
declare function Pipe<A, B, C, D, E, F, G, H>(value: A, fn1: (arg: A) => B, fn2: (arg: B) => C, fn3: (arg: C) => D, fn4: (arg: D) => E, fn5: (arg: E) => F, fn6: (arg: F) => G, fn7: (arg: G) => H): H;
|
|
344
|
+
declare function Pipe<A, B, C, D, E, F, G, H, I>(value: A, fn1: (arg: A) => B, fn2: (arg: B) => C, fn3: (arg: C) => D, fn4: (arg: D) => E, fn5: (arg: E) => F, fn6: (arg: F) => G, fn7: (arg: G) => H, fn8: (arg: H) => I): I;
|
|
345
|
+
declare function Pipe<A, B, C, D, E, F, G, H, I, J>(value: A, fn1: (arg: A) => B, fn2: (arg: B) => C, fn3: (arg: C) => D, fn4: (arg: D) => E, fn5: (arg: E) => F, fn6: (arg: F) => G, fn7: (arg: G) => H, fn8: (arg: H) => I, fn9: (arg: I) => J): J;
|
|
346
|
+
declare function Pipe<A, B, C, D, E, F, G, H, I, J, K>(value: A, fn1: (arg: A) => B, fn2: (arg: B) => C, fn3: (arg: C) => D, fn4: (arg: D) => E, fn5: (arg: E) => F, fn6: (arg: F) => G, fn7: (arg: G) => H, fn8: (arg: H) => I, fn9: (arg: I) => J, fn10: (arg: J) => K): K;
|
|
347
|
+
|
|
348
|
+
declare class Storage {
|
|
349
|
+
private isNode;
|
|
350
|
+
private filePath;
|
|
351
|
+
private memoryCache;
|
|
352
|
+
private loadFromFile;
|
|
353
|
+
private persist;
|
|
354
|
+
/**
|
|
355
|
+
* A lightweight, high-performant persistent storage system.
|
|
356
|
+
* Uses JSON files in Node.js, localStorage in the browser.
|
|
357
|
+
* @param fileName Only used in Node.js to create a persistent .json file.
|
|
358
|
+
* @param directory The directory for the file. Defaults to current working directory.
|
|
359
|
+
*/
|
|
360
|
+
constructor(fileName?: string, directory?: string);
|
|
361
|
+
has(key: string): boolean;
|
|
362
|
+
get<T>(key: string): T | null;
|
|
363
|
+
set<T>(key: string, value: T, ttl?: number): void;
|
|
364
|
+
remove(key: string): void;
|
|
365
|
+
clear(): void;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
declare class Cache<T> {
|
|
369
|
+
private cache;
|
|
370
|
+
private interval;
|
|
371
|
+
/**
|
|
372
|
+
* A lightweight, high-performant in-memory cache.
|
|
373
|
+
* Uses Map for O(1) lookups and an optional cleanup interval.
|
|
374
|
+
* @param cleanupMs The interval in milliseconds to run the cleanup function. [default: 60000 (1 minute)]
|
|
375
|
+
*/
|
|
376
|
+
constructor(cleanupMs?: number);
|
|
377
|
+
set(key: string | number, value: T, ttlMs?: number): void;
|
|
378
|
+
get(key: string | number): T | null;
|
|
379
|
+
private cleanup;
|
|
380
|
+
clear(): void;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
type AnyFunc = (...args: any) => any;
|
|
384
|
+
type DeepPartial<T> = {
|
|
385
|
+
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
|
|
386
|
+
};
|
|
387
|
+
type TypedEmitter<TEvents extends Record<string, any>> = {
|
|
388
|
+
on<K extends keyof TEvents>(event: K, listener: (...args: TEvents[K]) => void): any;
|
|
389
|
+
once<K extends keyof TEvents>(event: K, listener: (...args: TEvents[K]) => void): any;
|
|
390
|
+
off<K extends keyof TEvents>(event: K, listener: (...args: TEvents[K]) => void): any;
|
|
391
|
+
emit<K extends keyof TEvents>(event: K, ...args: TEvents[K]): boolean;
|
|
392
|
+
};
|
|
393
|
+
|
|
394
|
+
type LoopState = "running" | "paused" | "stopped";
|
|
395
|
+
interface LoopEvents<T> {
|
|
396
|
+
start: [];
|
|
397
|
+
tick: [result: T];
|
|
398
|
+
pause: [{
|
|
399
|
+
remaining: number;
|
|
400
|
+
}];
|
|
401
|
+
resume: [];
|
|
402
|
+
stop: [];
|
|
403
|
+
error: [error: any];
|
|
404
|
+
}
|
|
405
|
+
declare const TypedEmitterBase: {
|
|
406
|
+
new <T>(): TypedEmitter<LoopEvents<T>>;
|
|
407
|
+
};
|
|
408
|
+
declare class Loop<T = any> extends TypedEmitterBase<T> {
|
|
409
|
+
private _state;
|
|
410
|
+
private timeoutId;
|
|
411
|
+
private delay;
|
|
412
|
+
private fn;
|
|
413
|
+
private startTime;
|
|
414
|
+
private remaining;
|
|
415
|
+
private run;
|
|
416
|
+
private clearTimer;
|
|
417
|
+
/**
|
|
418
|
+
* Creates an interval. If the function is async, it will wait for it to complete before scheduling the next run.
|
|
419
|
+
* @param fn The function to run.
|
|
420
|
+
* @param delay The delay between runs in milliseconds.
|
|
421
|
+
* @param immediate Whether to start the loop immediately. [default: true]
|
|
422
|
+
*/
|
|
423
|
+
constructor(fn: (loop: Loop<T>) => Promise<T> | T, delay: number, immediate?: boolean);
|
|
424
|
+
get state(): LoopState;
|
|
425
|
+
/** Starts the loop. */
|
|
426
|
+
start(): void;
|
|
427
|
+
/** Resumes a paused loop. */
|
|
428
|
+
resume(): void;
|
|
429
|
+
/** Stops the loop. */
|
|
430
|
+
stop(): void;
|
|
431
|
+
/** Pauses the execution. */
|
|
432
|
+
pause(): void;
|
|
433
|
+
/**
|
|
434
|
+
* Sets the delay between runs
|
|
435
|
+
* @param ms The new delay in milliseconds.
|
|
436
|
+
*/
|
|
437
|
+
setDelay(ms: number): void;
|
|
438
|
+
/** Manually trigger the function once without affecting the loop. */
|
|
439
|
+
execute(): Promise<void>;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* Retries an async function with exponential backoff.
|
|
444
|
+
* @param fn The async function to attempt.
|
|
445
|
+
* @param retries Maximum number of retry attempts. [default: 3]
|
|
446
|
+
* @param delay Initial delay in milliseconds. [default: 500ms]
|
|
447
|
+
*/
|
|
448
|
+
declare function retry<T>(fn: () => Promise<T>, retries?: number, delay?: number): Promise<T>;
|
|
449
|
+
declare const async: {
|
|
450
|
+
retry: typeof retry;
|
|
451
|
+
};
|
|
452
|
+
|
|
453
|
+
/**
|
|
454
|
+
* Formats a number as a currency string using international standards.
|
|
455
|
+
* @param num - The number to process.
|
|
456
|
+
* @param options - Formatting options.
|
|
457
|
+
* @example
|
|
458
|
+
* currency(1234.5); // "$1,234.50"
|
|
459
|
+
* currency(1234.5, 'EUR', 'de-DE'); // "1.234,50 €"
|
|
460
|
+
* currency(500, 'JPY'); // "¥500" (Yen has no decimals)
|
|
461
|
+
*/
|
|
462
|
+
declare function currency(num: number, options?: {
|
|
463
|
+
/** The ISO currency code (e.g., 'USD', 'EUR', 'GBP'). */
|
|
464
|
+
currency?: string;
|
|
465
|
+
/** The BCP 47 language tag. */
|
|
466
|
+
locale?: Intl.LocalesArgument;
|
|
467
|
+
}): string;
|
|
468
|
+
/**
|
|
469
|
+
* Formats a number with thousands separators and optional decimal precision.
|
|
470
|
+
* @param num - The number to process.
|
|
471
|
+
* @param options - Formatting options.
|
|
472
|
+
* @example
|
|
473
|
+
* num(1000000); // "1,000,000" (en-US default)
|
|
474
|
+
* num(1000, { locale: 'de-DE' }); // "1.000"
|
|
475
|
+
* num(1234.567, { precision: 2 }); // "1,234.57"
|
|
476
|
+
*/
|
|
477
|
+
declare function number(num: number, options?: {
|
|
478
|
+
/** The BCP 47 language tag. */
|
|
479
|
+
locale?: Intl.LocalesArgument;
|
|
480
|
+
precision?: number;
|
|
481
|
+
}): string;
|
|
482
|
+
declare function memory(bytes: number, decimals?: number, units?: string[]): string;
|
|
483
|
+
/**
|
|
484
|
+
* Formats a number to an ordinal (e.g., 1st, 2nd, 3rd).
|
|
485
|
+
* @param num The number to process.
|
|
486
|
+
* @param locale The BCP 47 language tag.
|
|
487
|
+
*/
|
|
488
|
+
declare function ordinal(num: number | string, locale?: Intl.LocalesArgument): string;
|
|
489
|
+
/**
|
|
490
|
+
* Formats a number into a compact, human-readable string (e.g., 1.2k, 1M).
|
|
491
|
+
* @param num - The number to process.
|
|
492
|
+
* @param locale - The BCP 47 language tag.
|
|
493
|
+
*/
|
|
494
|
+
declare function compactNumber(num: number, locale?: Intl.LocalesArgument): string;
|
|
495
|
+
declare const format: {
|
|
496
|
+
currency: typeof currency;
|
|
497
|
+
number: typeof number;
|
|
498
|
+
memory: typeof memory;
|
|
499
|
+
ordinal: typeof ordinal;
|
|
500
|
+
compactNumber: typeof compactNumber;
|
|
501
|
+
};
|
|
502
|
+
|
|
503
|
+
/**
|
|
504
|
+
* Checks if a value is defined (not null or undefined).
|
|
505
|
+
*/
|
|
506
|
+
declare function defined<T>(val: T | undefined | null): val is T;
|
|
507
|
+
/**
|
|
508
|
+
* Checks if a value is an empty object, array, or string.
|
|
509
|
+
*/
|
|
510
|
+
declare function empty(val: unknown): boolean;
|
|
511
|
+
/**
|
|
512
|
+
* Checks if a number is within a specified range.
|
|
513
|
+
* @param num The number to check.
|
|
514
|
+
* @param min The minimum or maximum value of the range.
|
|
515
|
+
* @param max The maximum value of the range (optional).
|
|
516
|
+
*/
|
|
517
|
+
declare function inRange(num: number, max: number): boolean;
|
|
518
|
+
declare function inRange(num: number, min: number, max: number): boolean;
|
|
519
|
+
/**
|
|
520
|
+
* Checks if a value is a plain object (not an array, null, or function).
|
|
521
|
+
*/
|
|
522
|
+
declare function object(val: unknown): val is Record<string, any>;
|
|
523
|
+
/**
|
|
524
|
+
* Checks if an array is sorted.
|
|
525
|
+
*/
|
|
526
|
+
declare function sorted<T>(arr: T[], comparator?: (a: T, b: T) => number): boolean;
|
|
527
|
+
/**
|
|
528
|
+
* Checks if a value is a string.
|
|
529
|
+
*/
|
|
530
|
+
declare function string(val: unknown): val is string;
|
|
531
|
+
/**
|
|
532
|
+
* Checks if a date is today.
|
|
533
|
+
*/
|
|
534
|
+
declare function today(date: number | Date): boolean;
|
|
535
|
+
declare const is: {
|
|
536
|
+
defined: typeof defined;
|
|
537
|
+
empty: typeof empty;
|
|
538
|
+
inRange: typeof inRange;
|
|
539
|
+
object: typeof object;
|
|
540
|
+
sorted: typeof sorted;
|
|
541
|
+
string: typeof string;
|
|
542
|
+
today: typeof today;
|
|
543
|
+
};
|
|
544
|
+
|
|
545
|
+
/**
|
|
546
|
+
* Calculates the interpolation factor (0-1) of a value between two points.
|
|
547
|
+
* @param start - The starting value (0%).
|
|
548
|
+
* @param end - The ending value (100%).
|
|
549
|
+
* @param value - The value to interpolate.
|
|
550
|
+
* @example
|
|
551
|
+
* invLerp(0, 100, 50); // 0.5
|
|
552
|
+
*/
|
|
553
|
+
declare function invLerp(start: number, end: number, value: number): number;
|
|
554
|
+
/**
|
|
555
|
+
* Linearly interpolates between two values.
|
|
556
|
+
* @param start - The starting value (0%).
|
|
557
|
+
* @param end - The ending value (100%).
|
|
558
|
+
* @param t - The interpolation factor (0 to 1).
|
|
559
|
+
* @example
|
|
560
|
+
* lerp(0, 100, 0.5); // 50
|
|
561
|
+
* lerp(10, 20, 0.2); // 12
|
|
562
|
+
*/
|
|
563
|
+
declare function lerp(start: number, end: number, t: number): number;
|
|
564
|
+
/**
|
|
565
|
+
* Converts seconds to milliseconds and rounds it to the nearest integer.
|
|
566
|
+
* @param num The number of seconds to convert.
|
|
567
|
+
*/
|
|
568
|
+
declare function ms(num: number): number;
|
|
569
|
+
/**
|
|
570
|
+
* Calculates the percentage value between two numbers.
|
|
571
|
+
* @param a The numerator.
|
|
572
|
+
* @param b The denominator.
|
|
573
|
+
* @param round Whether to round the result to the nearest integer.
|
|
574
|
+
* @example
|
|
575
|
+
* percent(50, 100) --> 50 // 50%
|
|
576
|
+
* percent(30, 40) --> 75 // 75%
|
|
577
|
+
*/
|
|
578
|
+
declare function percent(a: number, b: number, round?: boolean): number;
|
|
579
|
+
/**
|
|
580
|
+
* Maps a value from one range to another.
|
|
581
|
+
* @param value - The value to map.
|
|
582
|
+
* @param inMin - The minimum value of the input range.
|
|
583
|
+
* @param inMax - The maximum value of the input range.
|
|
584
|
+
* @param outMin - The minimum value of the output range.
|
|
585
|
+
* @param outMax - The maximum value of the output range.
|
|
586
|
+
* @example
|
|
587
|
+
* // Convert mouse X position (0-1920) to a volume level (0-1)
|
|
588
|
+
* const volume = remap(mouseX, 0, 1920, 0, 1);
|
|
589
|
+
*/
|
|
590
|
+
declare function remap(value: number, inMin: number, inMax: number, outMin: number, outMax: number): number;
|
|
591
|
+
/**
|
|
592
|
+
* Converts milliseconds to seconds and rounds it to the nearest integer.
|
|
593
|
+
* @param num The number of milliseconds to convert.
|
|
594
|
+
*/
|
|
595
|
+
declare function secs(num: number): number;
|
|
596
|
+
/**
|
|
597
|
+
* Returns the sum of an array of numbers. Negative values subtract from the total.
|
|
598
|
+
* @param array The array to sum.
|
|
599
|
+
* @param selector Function that selects the item's weight.
|
|
600
|
+
* @param ignoreNaN If true, NaN values will not throw an error.
|
|
601
|
+
*/
|
|
602
|
+
declare function sum<T>(array: T[], selector: (item: T) => number, ignoreNaN?: boolean): number;
|
|
603
|
+
declare const math: {
|
|
604
|
+
invLerp: typeof invLerp;
|
|
605
|
+
lerp: typeof lerp;
|
|
606
|
+
ms: typeof ms;
|
|
607
|
+
percent: typeof percent;
|
|
608
|
+
remap: typeof remap;
|
|
609
|
+
secs: typeof secs;
|
|
610
|
+
sum: typeof sum;
|
|
611
|
+
};
|
|
612
|
+
|
|
613
|
+
/**
|
|
614
|
+
* Clamps a number within a specified range.
|
|
615
|
+
* @param num The number to check.
|
|
616
|
+
* @param min The minimum or maximum value of the range.
|
|
617
|
+
* @param max The maximum value of the range (optional).
|
|
618
|
+
*/
|
|
619
|
+
declare function clamp(num: number, max: number): number;
|
|
620
|
+
declare function clamp(num: number, min: number, max: number): number;
|
|
621
|
+
declare const num: {
|
|
622
|
+
clamp: typeof clamp;
|
|
623
|
+
};
|
|
624
|
+
|
|
625
|
+
/**
|
|
626
|
+
* Retrieves a nested property.
|
|
627
|
+
* @param obj The object to process.
|
|
628
|
+
* @param path The path to retrieve (e.g., 'data.users[0].id').
|
|
629
|
+
* @param defaultValue The default value to return if the property does not exist.
|
|
630
|
+
*/
|
|
631
|
+
declare function get<T = any>(obj: Record<string, any>, path: string, defaultValue?: T): T;
|
|
632
|
+
/**
|
|
633
|
+
* Checks if a nested path exists within an object.
|
|
634
|
+
* @param obj The object to process.
|
|
635
|
+
* @param path The path string (e.g., 'data.users[0].id').
|
|
636
|
+
*/
|
|
637
|
+
declare function has(obj: Record<string, any>, path: string): boolean;
|
|
638
|
+
/**
|
|
639
|
+
* Sets a nested property value. Creates missing objects/arrays along the path.
|
|
640
|
+
* @param obj The object to process.
|
|
641
|
+
* @param path The path to set (e.g., 'data.users[0].id').
|
|
642
|
+
* @param value The value to inject.
|
|
643
|
+
*/
|
|
644
|
+
declare function set(obj: Record<string, any>, path: string, value: any): void;
|
|
645
|
+
/**
|
|
646
|
+
* Deep merges multiple objects.
|
|
647
|
+
* @param target - The base object to merge into.
|
|
648
|
+
* @param sources - One or more objects to merge.
|
|
649
|
+
*/
|
|
650
|
+
declare function merge<T, S1>(target: T, s1: S1): T & S1;
|
|
651
|
+
declare function merge<T, S1, S2>(target: T, s1: S1, s2: S2): T & S1 & S2;
|
|
652
|
+
declare function merge<T, S1, S2, S3>(target: T, s1: S1, s2: S2, s3: S3): T & S1 & S2 & S3;
|
|
653
|
+
declare function merge(target: any, ...sources: any[]): any;
|
|
654
|
+
/**
|
|
655
|
+
* Creates an object composed of the picked object properties.
|
|
656
|
+
* @param obj The object to process.
|
|
657
|
+
* @param keys The keys to pick from the object.
|
|
658
|
+
*/
|
|
659
|
+
declare function pick<T extends object, K extends keyof T>(obj: T, keys: K[]): Pick<T, K>;
|
|
660
|
+
/**
|
|
661
|
+
* Creates an object composed of the omitted object properties.
|
|
662
|
+
* @param obj The object to process.
|
|
663
|
+
* @param keys The keys to omit from the object.
|
|
664
|
+
*/
|
|
665
|
+
declare function omit<T extends object, K extends keyof T>(obj: T, keys: K[]): Omit<T, K>;
|
|
666
|
+
declare const obj: {
|
|
667
|
+
get: typeof get;
|
|
668
|
+
has: typeof has;
|
|
669
|
+
set: typeof set;
|
|
670
|
+
merge: typeof merge;
|
|
671
|
+
pick: typeof pick;
|
|
672
|
+
omit: typeof omit;
|
|
673
|
+
};
|
|
674
|
+
|
|
675
|
+
/**
|
|
676
|
+
* Escapes regex characters in the given string.
|
|
677
|
+
* @param str - The string to process.
|
|
678
|
+
*/
|
|
679
|
+
declare function escapeRegex(str: string): string;
|
|
680
|
+
/**
|
|
681
|
+
* Retrieves a substring following a specific flag.
|
|
682
|
+
* @param str The string to process.
|
|
683
|
+
* @param flag A string or regex to look for.
|
|
684
|
+
*/
|
|
685
|
+
declare function getFlag(str: string, flag: string | RegExp, length?: number): string | null;
|
|
686
|
+
/**
|
|
687
|
+
* Checks if a string contains a specific flag.
|
|
688
|
+
* @param str The string to process.
|
|
689
|
+
* @param flag A string or regex to look for.
|
|
690
|
+
*/
|
|
691
|
+
declare function hasFlag(str: string, flag: string | RegExp): boolean;
|
|
692
|
+
/**
|
|
693
|
+
* Formats a string to Title Case, optionally keeping acronyms and skipping minor words (the, and, of, etc.).
|
|
694
|
+
* @param str The string to process.
|
|
695
|
+
* @param smart If true, will keep acronyms and skip minor words. [default: true]
|
|
696
|
+
*/
|
|
697
|
+
declare function toTitleCase(str: string, smart?: boolean): string;
|
|
698
|
+
declare const str: {
|
|
699
|
+
escapeRegex: typeof escapeRegex;
|
|
700
|
+
getFlag: typeof getFlag;
|
|
701
|
+
hasFlag: typeof hasFlag;
|
|
702
|
+
toTitleCase: typeof toTitleCase;
|
|
703
|
+
};
|
|
704
|
+
|
|
705
|
+
declare const $: {
|
|
706
|
+
Pipe: typeof Pipe;
|
|
707
|
+
Storage: typeof Storage;
|
|
708
|
+
Cache: typeof Cache;
|
|
709
|
+
Loop: typeof Loop;
|
|
710
|
+
to: {
|
|
711
|
+
record: <T, V>(array: ReadonlyArray<T>, callback: (item: T, context: ToRecordContext<T, V>) => {
|
|
712
|
+
key: string | number;
|
|
713
|
+
value: V;
|
|
714
|
+
}) => Record<string | number, V>;
|
|
715
|
+
};
|
|
716
|
+
str: {
|
|
717
|
+
escapeRegex: (str: string) => string;
|
|
718
|
+
getFlag: (str: string, flag: string | RegExp, length?: number) => string | null;
|
|
719
|
+
hasFlag: (str: string, flag: string | RegExp) => boolean;
|
|
720
|
+
toTitleCase: (str: string, smart?: boolean) => string;
|
|
721
|
+
};
|
|
722
|
+
rnd: {
|
|
723
|
+
chance: (percent?: number, seed?: number) => boolean;
|
|
724
|
+
choice: <T>(array: T[], seed?: number) => T;
|
|
725
|
+
weighted: <T>(array: T[], selector: (item: T) => number, seed?: number) => T;
|
|
726
|
+
sampler: <T>(items: T[], selector: (item: T) => number, seed?: number) => {
|
|
727
|
+
pick: (seed?: number) => T | undefined;
|
|
728
|
+
};
|
|
729
|
+
prng: (seed: number) => () => number;
|
|
730
|
+
float: (min: number, max: number, seed?: number) => number;
|
|
731
|
+
index: (array: any[], seed?: number) => number;
|
|
732
|
+
int: (min: number, max: number, seed?: number) => number;
|
|
733
|
+
str: (len: number, mode: "number" | "alpha" | "alphanumeric" | "custom", options?: RndStrOptions) => string;
|
|
734
|
+
};
|
|
735
|
+
timing: {
|
|
736
|
+
debounce: <T extends (...args: any[]) => any>(fn: T, wait: number, options?: {
|
|
737
|
+
immediate?: boolean;
|
|
738
|
+
}) => DebouncedFunction<T>;
|
|
739
|
+
throttle: <T extends (...args: any[]) => any>(fn: T, limit: number) => (...args: Parameters<T>) => void;
|
|
740
|
+
wait: (ms: number) => Promise<boolean>;
|
|
741
|
+
};
|
|
742
|
+
obj: {
|
|
743
|
+
get: <T = any>(obj: Record<string, any>, path: string, defaultValue?: T) => T;
|
|
744
|
+
has: (obj: Record<string, any>, path: string) => boolean;
|
|
745
|
+
set: (obj: Record<string, any>, path: string, value: any) => void;
|
|
746
|
+
merge: {
|
|
747
|
+
<T, S1>(target: T, s1: S1): T & S1;
|
|
748
|
+
<T, S1, S2>(target: T, s1: S1, s2: S2): T & S1 & S2;
|
|
749
|
+
<T, S1, S2, S3>(target: T, s1: S1, s2: S2, s3: S3): T & S1 & S2 & S3;
|
|
750
|
+
(target: any, ...sources: any[]): any;
|
|
751
|
+
};
|
|
752
|
+
pick: <T extends object, K extends keyof T>(obj: T, keys: K[]) => Pick<T, K>;
|
|
753
|
+
omit: <T extends object, K extends keyof T>(obj: T, keys: K[]) => Omit<T, K>;
|
|
754
|
+
};
|
|
755
|
+
num: {
|
|
756
|
+
clamp: {
|
|
757
|
+
(num: number, max: number): number;
|
|
758
|
+
(num: number, min: number, max: number): number;
|
|
759
|
+
};
|
|
760
|
+
};
|
|
761
|
+
math: {
|
|
762
|
+
invLerp: (start: number, end: number, value: number) => number;
|
|
763
|
+
lerp: (start: number, end: number, t: number) => number;
|
|
764
|
+
ms: (num: number) => number;
|
|
765
|
+
percent: (a: number, b: number, round?: boolean) => number;
|
|
766
|
+
remap: (value: number, inMin: number, inMax: number, outMin: number, outMax: number) => number;
|
|
767
|
+
secs: (num: number) => number;
|
|
768
|
+
sum: <T>(array: T[], selector: (item: T) => number, ignoreNaN?: boolean) => number;
|
|
769
|
+
};
|
|
770
|
+
is: {
|
|
771
|
+
defined: <T>(val: T | undefined | null) => val is T;
|
|
772
|
+
empty: (val: unknown) => boolean;
|
|
773
|
+
inRange: {
|
|
774
|
+
(num: number, max: number): boolean;
|
|
775
|
+
(num: number, min: number, max: number): boolean;
|
|
776
|
+
};
|
|
777
|
+
object: (val: unknown) => val is Record<string, any>;
|
|
778
|
+
sorted: <T>(arr: T[], comparator?: (a: T, b: T) => number) => boolean;
|
|
779
|
+
string: (val: unknown) => val is string;
|
|
780
|
+
today: (date: number | Date) => boolean;
|
|
781
|
+
};
|
|
782
|
+
format: {
|
|
783
|
+
currency: (num: number, options?: {
|
|
784
|
+
currency?: string;
|
|
785
|
+
locale?: Intl.LocalesArgument;
|
|
786
|
+
}) => string;
|
|
787
|
+
number: (num: number, options?: {
|
|
788
|
+
locale?: Intl.LocalesArgument;
|
|
789
|
+
precision?: number;
|
|
790
|
+
}) => string;
|
|
791
|
+
memory: (bytes: number, decimals?: number, units?: string[]) => string;
|
|
792
|
+
ordinal: (num: number | string, locale?: Intl.LocalesArgument) => string;
|
|
793
|
+
compactNumber: (num: number, locale?: Intl.LocalesArgument) => string;
|
|
794
|
+
};
|
|
795
|
+
date: {
|
|
796
|
+
duration: (target: number | Date, style?: "digital" | "hms" | "ymdhms", options?: DateOptions) => string | null;
|
|
797
|
+
eta: (date: Date | number, locale?: Intl.LocalesArgument) => string;
|
|
798
|
+
parse: (str: string | number, options?: ParseOptions) => number;
|
|
799
|
+
};
|
|
800
|
+
fn: {
|
|
801
|
+
memoize: <T extends (...args: any[]) => any>(fn: T, options?: {
|
|
802
|
+
resolver?: (...args: Parameters<T>) => string;
|
|
803
|
+
maxAge?: number;
|
|
804
|
+
}) => MemoizedFunction<T>;
|
|
805
|
+
};
|
|
806
|
+
async: {
|
|
807
|
+
retry: <T>(fn: () => Promise<T>, retries?: number, delay?: number) => Promise<T>;
|
|
808
|
+
};
|
|
809
|
+
arr: {
|
|
810
|
+
chunk: <T>(array: ReadonlyArray<T>, size: number) => T[][];
|
|
811
|
+
chunkAdj: <T>(array: ReadonlyArray<T>, predicate: (prev: T, curr: T) => boolean) => T[][];
|
|
812
|
+
cluster: <T>(array: ReadonlyArray<T>, iteratee: (item: T) => string | number, maxChunkSize?: number) => T[][];
|
|
813
|
+
compact: {
|
|
814
|
+
<T>(array: ReadonlyArray<T>, mode?: "nullable"): NonNullable<T>[];
|
|
815
|
+
<T>(array: ReadonlyArray<T>, mode: "falsy"): Exclude<T, null | undefined | false | 0 | "">[];
|
|
816
|
+
};
|
|
817
|
+
forceArray: <T>(item: T) => T[];
|
|
818
|
+
search: <T>(array: T[], target: T, comparator?: (a: T, b: T) => number) => number;
|
|
819
|
+
seqMap: <T, U>(array: ReadonlyArray<T>, callback: (item: T, context: SequentialMapContext<T, U>) => U) => U[];
|
|
820
|
+
shuffle: <T>(array: ReadonlyArray<T>, seed?: number) => T[];
|
|
821
|
+
sortBy: {
|
|
822
|
+
<T>(array: ReadonlyArray<T>, selector: (item: T) => any, order?: "asc" | "desc"): T[];
|
|
823
|
+
<T>(array: ReadonlyArray<T>, selectors: (item: T) => any[], order?: "asc" | "desc"): T[];
|
|
824
|
+
};
|
|
825
|
+
unique: <T>(array: T[], key: (item: T) => any) => T[];
|
|
826
|
+
};
|
|
827
|
+
};
|
|
828
|
+
declare const qznt: {
|
|
829
|
+
Pipe: typeof Pipe;
|
|
830
|
+
Storage: typeof Storage;
|
|
831
|
+
Cache: typeof Cache;
|
|
832
|
+
Loop: typeof Loop;
|
|
833
|
+
to: {
|
|
834
|
+
record: <T, V>(array: ReadonlyArray<T>, callback: (item: T, context: ToRecordContext<T, V>) => {
|
|
835
|
+
key: string | number;
|
|
836
|
+
value: V;
|
|
837
|
+
}) => Record<string | number, V>;
|
|
838
|
+
};
|
|
839
|
+
str: {
|
|
840
|
+
escapeRegex: (str: string) => string;
|
|
841
|
+
getFlag: (str: string, flag: string | RegExp, length?: number) => string | null;
|
|
842
|
+
hasFlag: (str: string, flag: string | RegExp) => boolean;
|
|
843
|
+
toTitleCase: (str: string, smart?: boolean) => string;
|
|
844
|
+
};
|
|
845
|
+
rnd: {
|
|
846
|
+
chance: (percent?: number, seed?: number) => boolean;
|
|
847
|
+
choice: <T>(array: T[], seed?: number) => T;
|
|
848
|
+
weighted: <T>(array: T[], selector: (item: T) => number, seed?: number) => T;
|
|
849
|
+
sampler: <T>(items: T[], selector: (item: T) => number, seed?: number) => {
|
|
850
|
+
pick: (seed?: number) => T | undefined;
|
|
851
|
+
};
|
|
852
|
+
prng: (seed: number) => () => number;
|
|
853
|
+
float: (min: number, max: number, seed?: number) => number;
|
|
854
|
+
index: (array: any[], seed?: number) => number;
|
|
855
|
+
int: (min: number, max: number, seed?: number) => number;
|
|
856
|
+
str: (len: number, mode: "number" | "alpha" | "alphanumeric" | "custom", options?: RndStrOptions) => string;
|
|
857
|
+
};
|
|
858
|
+
timing: {
|
|
859
|
+
debounce: <T extends (...args: any[]) => any>(fn: T, wait: number, options?: {
|
|
860
|
+
immediate?: boolean;
|
|
861
|
+
}) => DebouncedFunction<T>;
|
|
862
|
+
throttle: <T extends (...args: any[]) => any>(fn: T, limit: number) => (...args: Parameters<T>) => void;
|
|
863
|
+
wait: (ms: number) => Promise<boolean>;
|
|
864
|
+
};
|
|
865
|
+
obj: {
|
|
866
|
+
get: <T = any>(obj: Record<string, any>, path: string, defaultValue?: T) => T;
|
|
867
|
+
has: (obj: Record<string, any>, path: string) => boolean;
|
|
868
|
+
set: (obj: Record<string, any>, path: string, value: any) => void;
|
|
869
|
+
merge: {
|
|
870
|
+
<T, S1>(target: T, s1: S1): T & S1;
|
|
871
|
+
<T, S1, S2>(target: T, s1: S1, s2: S2): T & S1 & S2;
|
|
872
|
+
<T, S1, S2, S3>(target: T, s1: S1, s2: S2, s3: S3): T & S1 & S2 & S3;
|
|
873
|
+
(target: any, ...sources: any[]): any;
|
|
874
|
+
};
|
|
875
|
+
pick: <T extends object, K extends keyof T>(obj: T, keys: K[]) => Pick<T, K>;
|
|
876
|
+
omit: <T extends object, K extends keyof T>(obj: T, keys: K[]) => Omit<T, K>;
|
|
877
|
+
};
|
|
878
|
+
num: {
|
|
879
|
+
clamp: {
|
|
880
|
+
(num: number, max: number): number;
|
|
881
|
+
(num: number, min: number, max: number): number;
|
|
882
|
+
};
|
|
883
|
+
};
|
|
884
|
+
math: {
|
|
885
|
+
invLerp: (start: number, end: number, value: number) => number;
|
|
886
|
+
lerp: (start: number, end: number, t: number) => number;
|
|
887
|
+
ms: (num: number) => number;
|
|
888
|
+
percent: (a: number, b: number, round?: boolean) => number;
|
|
889
|
+
remap: (value: number, inMin: number, inMax: number, outMin: number, outMax: number) => number;
|
|
890
|
+
secs: (num: number) => number;
|
|
891
|
+
sum: <T>(array: T[], selector: (item: T) => number, ignoreNaN?: boolean) => number;
|
|
892
|
+
};
|
|
893
|
+
is: {
|
|
894
|
+
defined: <T>(val: T | undefined | null) => val is T;
|
|
895
|
+
empty: (val: unknown) => boolean;
|
|
896
|
+
inRange: {
|
|
897
|
+
(num: number, max: number): boolean;
|
|
898
|
+
(num: number, min: number, max: number): boolean;
|
|
899
|
+
};
|
|
900
|
+
object: (val: unknown) => val is Record<string, any>;
|
|
901
|
+
sorted: <T>(arr: T[], comparator?: (a: T, b: T) => number) => boolean;
|
|
902
|
+
string: (val: unknown) => val is string;
|
|
903
|
+
today: (date: number | Date) => boolean;
|
|
904
|
+
};
|
|
905
|
+
format: {
|
|
906
|
+
currency: (num: number, options?: {
|
|
907
|
+
currency?: string;
|
|
908
|
+
locale?: Intl.LocalesArgument;
|
|
909
|
+
}) => string;
|
|
910
|
+
number: (num: number, options?: {
|
|
911
|
+
locale?: Intl.LocalesArgument;
|
|
912
|
+
precision?: number;
|
|
913
|
+
}) => string;
|
|
914
|
+
memory: (bytes: number, decimals?: number, units?: string[]) => string;
|
|
915
|
+
ordinal: (num: number | string, locale?: Intl.LocalesArgument) => string;
|
|
916
|
+
compactNumber: (num: number, locale?: Intl.LocalesArgument) => string;
|
|
917
|
+
};
|
|
918
|
+
date: {
|
|
919
|
+
duration: (target: number | Date, style?: "digital" | "hms" | "ymdhms", options?: DateOptions) => string | null;
|
|
920
|
+
eta: (date: Date | number, locale?: Intl.LocalesArgument) => string;
|
|
921
|
+
parse: (str: string | number, options?: ParseOptions) => number;
|
|
922
|
+
};
|
|
923
|
+
fn: {
|
|
924
|
+
memoize: <T extends (...args: any[]) => any>(fn: T, options?: {
|
|
925
|
+
resolver?: (...args: Parameters<T>) => string;
|
|
926
|
+
maxAge?: number;
|
|
927
|
+
}) => MemoizedFunction<T>;
|
|
928
|
+
};
|
|
929
|
+
async: {
|
|
930
|
+
retry: <T>(fn: () => Promise<T>, retries?: number, delay?: number) => Promise<T>;
|
|
931
|
+
};
|
|
932
|
+
arr: {
|
|
933
|
+
chunk: <T>(array: ReadonlyArray<T>, size: number) => T[][];
|
|
934
|
+
chunkAdj: <T>(array: ReadonlyArray<T>, predicate: (prev: T, curr: T) => boolean) => T[][];
|
|
935
|
+
cluster: <T>(array: ReadonlyArray<T>, iteratee: (item: T) => string | number, maxChunkSize?: number) => T[][];
|
|
936
|
+
compact: {
|
|
937
|
+
<T>(array: ReadonlyArray<T>, mode?: "nullable"): NonNullable<T>[];
|
|
938
|
+
<T>(array: ReadonlyArray<T>, mode: "falsy"): Exclude<T, null | undefined | false | 0 | "">[];
|
|
939
|
+
};
|
|
940
|
+
forceArray: <T>(item: T) => T[];
|
|
941
|
+
search: <T>(array: T[], target: T, comparator?: (a: T, b: T) => number) => number;
|
|
942
|
+
seqMap: <T, U>(array: ReadonlyArray<T>, callback: (item: T, context: SequentialMapContext<T, U>) => U) => U[];
|
|
943
|
+
shuffle: <T>(array: ReadonlyArray<T>, seed?: number) => T[];
|
|
944
|
+
sortBy: {
|
|
945
|
+
<T>(array: ReadonlyArray<T>, selector: (item: T) => any, order?: "asc" | "desc"): T[];
|
|
946
|
+
<T>(array: ReadonlyArray<T>, selectors: (item: T) => any[], order?: "asc" | "desc"): T[];
|
|
947
|
+
};
|
|
948
|
+
unique: <T>(array: T[], key: (item: T) => any) => T[];
|
|
949
|
+
};
|
|
950
|
+
};
|
|
951
|
+
|
|
952
|
+
export { type AlphaCasing, type AnyFunc, Cache, type DateOptions, type DebouncedFunction, type DeepPartial, Loop, type MemoizedFunction, type ParseOptions, Pipe, type RndStrOptions, type SequentialMapContext, Storage, type ToRecordContext, type TypedEmitter, arr, async, date, $ as default, fn, format, is, math, num, obj, qznt, rnd, str, timing, to };
|