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