@welshman/lib 0.0.32 → 0.0.34
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 +10 -8
- package/build/src/Context.cjs +17 -0
- package/build/src/Context.cjs.map +1 -1
- package/build/src/Context.d.ts +17 -0
- package/build/src/Context.mjs +17 -0
- package/build/src/Context.mjs.map +1 -1
- package/build/src/Deferred.cjs +9 -0
- package/build/src/Deferred.cjs.map +1 -1
- package/build/src/Deferred.d.ts +11 -0
- package/build/src/Deferred.mjs +9 -0
- package/build/src/Deferred.mjs.map +1 -1
- package/build/src/Emitter.cjs +9 -0
- package/build/src/Emitter.cjs.map +1 -1
- package/build/src/Emitter.d.ts +9 -0
- package/build/src/Emitter.mjs +9 -0
- package/build/src/Emitter.mjs.map +1 -1
- package/build/src/LRUCache.cjs +16 -0
- package/build/src/LRUCache.cjs.map +1 -1
- package/build/src/LRUCache.d.ts +16 -0
- package/build/src/LRUCache.mjs +16 -0
- package/build/src/LRUCache.mjs.map +1 -1
- package/build/src/Tools.cjs +478 -12
- package/build/src/Tools.cjs.map +1 -1
- package/build/src/Tools.d.ts +465 -18
- package/build/src/Tools.mjs +471 -9
- package/build/src/Tools.mjs.map +1 -1
- package/build/src/Worker.cjs +27 -1
- package/build/src/Worker.cjs.map +1 -1
- package/build/src/Worker.d.ts +25 -0
- package/build/src/Worker.mjs +27 -1
- package/build/src/Worker.mjs.map +1 -1
- package/build/src/index.cjs +0 -1
- package/build/src/index.cjs.map +1 -1
- package/build/src/index.d.ts +0 -1
- package/build/src/index.mjs +0 -1
- package/build/src/index.mjs.map +1 -1
- package/package.json +1 -1
- package/build/src/Fluent.cjs +0 -47
- package/build/src/Fluent.cjs.map +0 -1
- package/build/src/Fluent.d.ts +0 -34
- package/build/src/Fluent.mjs +0 -43
- package/build/src/Fluent.mjs.map +0 -1
package/build/src/Tools.d.ts
CHANGED
|
@@ -1,136 +1,583 @@
|
|
|
1
|
+
/** Type representing null or undefined */
|
|
1
2
|
export type Nil = null | undefined;
|
|
3
|
+
/** Checks if a value is null or undefined */
|
|
2
4
|
export declare const isNil: (x: any) => boolean;
|
|
5
|
+
/** Type representing an optional value */
|
|
3
6
|
export type Maybe<T> = T | undefined;
|
|
7
|
+
/**
|
|
8
|
+
* Executes a function if the value is defined
|
|
9
|
+
* @param x - The value to check
|
|
10
|
+
* @param f - Function to execute if x is defined
|
|
11
|
+
* @returns Result of f(x) if x is defined, undefined otherwise
|
|
12
|
+
*/
|
|
4
13
|
export declare const ifLet: <T>(x: T | undefined, f: (x: T) => void) => void;
|
|
14
|
+
/** Function that does nothing and returns undefined */
|
|
5
15
|
export declare const noop: (...args: unknown[]) => undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Returns the first element of an array
|
|
18
|
+
* @param xs - The array
|
|
19
|
+
* @returns First element or undefined
|
|
20
|
+
*/
|
|
6
21
|
export declare const first: <T>(xs: T[], ...args: unknown[]) => T;
|
|
22
|
+
/**
|
|
23
|
+
* Returns the first element of the first array in a nested array
|
|
24
|
+
* @param xs - Array of arrays
|
|
25
|
+
* @returns First element of first array or undefined
|
|
26
|
+
*/
|
|
7
27
|
export declare const ffirst: <T>(xs: T[][], ...args: unknown[]) => T;
|
|
28
|
+
/**
|
|
29
|
+
* Returns the last element of an array
|
|
30
|
+
* @param xs - The array
|
|
31
|
+
* @returns Last element or undefined
|
|
32
|
+
*/
|
|
8
33
|
export declare const last: <T>(xs: T[], ...args: unknown[]) => T;
|
|
34
|
+
/**
|
|
35
|
+
* Returns the input value unchanged
|
|
36
|
+
* @param x - Any value
|
|
37
|
+
* @returns The same value
|
|
38
|
+
*/
|
|
9
39
|
export declare const identity: <T>(x: T, ...args: unknown[]) => T;
|
|
40
|
+
/**
|
|
41
|
+
* Creates a function that always returns the same value
|
|
42
|
+
* @param x - Value to return
|
|
43
|
+
* @returns Function that returns x
|
|
44
|
+
*/
|
|
10
45
|
export declare const always: <T>(x: T, ...args: unknown[]) => () => T;
|
|
46
|
+
/**
|
|
47
|
+
* Returns the logical NOT of a value
|
|
48
|
+
* @param x - Value to negate
|
|
49
|
+
* @returns !x
|
|
50
|
+
*/
|
|
11
51
|
export declare const not: (x: any, ...args: unknown[]) => boolean;
|
|
52
|
+
/** Returns a function that returns the boolean negation of the given function */
|
|
53
|
+
export declare const complement: <T extends unknown[]>(f: (...args: T) => any) => (...args: T) => boolean;
|
|
54
|
+
/** Converts a Maybe<number> to a number, defaulting to 0 */
|
|
12
55
|
export declare const num: (x: Maybe<number>) => number;
|
|
56
|
+
/** Adds two numbers, handling undefined values */
|
|
13
57
|
export declare const add: (x: Maybe<number>, y: Maybe<number>) => number;
|
|
58
|
+
/** Subtracts two numbers, handling undefined values */
|
|
14
59
|
export declare const sub: (x: Maybe<number>, y: Maybe<number>) => number;
|
|
60
|
+
/** Multiplies two numbers, handling undefined values */
|
|
15
61
|
export declare const mul: (x: Maybe<number>, y: Maybe<number>) => number;
|
|
62
|
+
/** Divides two numbers, handling undefined values */
|
|
16
63
|
export declare const div: (x: Maybe<number>, y: number) => number;
|
|
64
|
+
/** Increments a number by 1, handling undefined values */
|
|
17
65
|
export declare const inc: (x: Maybe<number>) => number;
|
|
66
|
+
/** Decrements a number by 1, handling undefined values */
|
|
18
67
|
export declare const dec: (x: Maybe<number>) => number;
|
|
68
|
+
/** Less than comparison, handling undefined values */
|
|
19
69
|
export declare const lt: (x: Maybe<number>, y: Maybe<number>) => boolean;
|
|
70
|
+
/** Less than or equal comparison, handling undefined values */
|
|
20
71
|
export declare const lte: (x: Maybe<number>, y: Maybe<number>) => boolean;
|
|
72
|
+
/** Greater than comparison, handling undefined values */
|
|
21
73
|
export declare const gt: (x: Maybe<number>, y: Maybe<number>) => boolean;
|
|
74
|
+
/** Greater than or equal comparison, handling undefined values */
|
|
22
75
|
export declare const gte: (x: Maybe<number>, y: Maybe<number>) => boolean;
|
|
76
|
+
/** Returns maximum value in array, handling undefined values */
|
|
23
77
|
export declare const max: (xs: Maybe<number>[]) => number;
|
|
78
|
+
/** Returns minimum value in array, handling undefined values */
|
|
24
79
|
export declare const min: (xs: Maybe<number>[]) => number;
|
|
80
|
+
/** Returns sum of array values, handling undefined values */
|
|
25
81
|
export declare const sum: (xs: Maybe<number>[]) => number;
|
|
82
|
+
/** Returns average of array values, handling undefined values */
|
|
26
83
|
export declare const avg: (xs: Maybe<number>[]) => number;
|
|
84
|
+
/**
|
|
85
|
+
* Returns array with first n elements removed
|
|
86
|
+
* @param n - Number of elements to drop
|
|
87
|
+
* @param xs - Input array
|
|
88
|
+
* @returns Array with first n elements removed
|
|
89
|
+
*/
|
|
27
90
|
export declare const drop: <T>(n: number, xs: T[]) => T[];
|
|
91
|
+
/**
|
|
92
|
+
* Returns first n elements of array
|
|
93
|
+
* @param n - Number of elements to take
|
|
94
|
+
* @param xs - Input array
|
|
95
|
+
* @returns Array of first n elements
|
|
96
|
+
*/
|
|
28
97
|
export declare const take: <T>(n: number, xs: T[]) => T[];
|
|
98
|
+
/**
|
|
99
|
+
* Creates new object with specified keys removed
|
|
100
|
+
* @param ks - Keys to remove
|
|
101
|
+
* @param x - Source object
|
|
102
|
+
* @returns New object without specified keys
|
|
103
|
+
*/
|
|
29
104
|
export declare const omit: <T extends Record<string, any>>(ks: string[], x: T) => T;
|
|
105
|
+
/**
|
|
106
|
+
* Creates new object excluding entries with specified values
|
|
107
|
+
* @param xs - Values to exclude
|
|
108
|
+
* @param x - Source object
|
|
109
|
+
* @returns New object without entries containing specified values
|
|
110
|
+
*/
|
|
30
111
|
export declare const omitVals: <T extends Record<string, any>>(xs: any[], x: T) => T;
|
|
112
|
+
/**
|
|
113
|
+
* Creates new object with only specified keys
|
|
114
|
+
* @param ks - Keys to keep
|
|
115
|
+
* @param x - Source object
|
|
116
|
+
* @returns New object with only specified keys
|
|
117
|
+
*/
|
|
31
118
|
export declare const pick: <T extends Record<string, any>>(ks: string[], x: T) => T;
|
|
119
|
+
/**
|
|
120
|
+
* Generates sequence of numbers from a to b
|
|
121
|
+
* @param a - Start number (inclusive)
|
|
122
|
+
* @param b - End number (exclusive)
|
|
123
|
+
* @param step - Increment between numbers
|
|
124
|
+
* @yields Numbers in sequence
|
|
125
|
+
*/
|
|
32
126
|
export declare function range(a: number, b: number, step?: number): Generator<number, void, unknown>;
|
|
127
|
+
/**
|
|
128
|
+
* Creates new object with transformed keys
|
|
129
|
+
* @param f - Function to transform keys
|
|
130
|
+
* @param x - Source object
|
|
131
|
+
* @returns Object with transformed keys
|
|
132
|
+
*/
|
|
33
133
|
export declare const mapKeys: <T extends Record<string, any>>(f: (v: string) => string, x: T) => T;
|
|
134
|
+
/**
|
|
135
|
+
* Creates new object with transformed values
|
|
136
|
+
* @param f - Function to transform values
|
|
137
|
+
* @param x - Source object
|
|
138
|
+
* @returns Object with transformed values
|
|
139
|
+
*/
|
|
34
140
|
export declare const mapVals: <V, U>(f: (v: V) => U, x: Record<string, V>) => Record<string, U>;
|
|
141
|
+
/**
|
|
142
|
+
* Merges two objects, with left object taking precedence
|
|
143
|
+
* @param a - Left object
|
|
144
|
+
* @param b - Right object
|
|
145
|
+
* @returns Merged object with a's properties overriding b's
|
|
146
|
+
*/
|
|
35
147
|
export declare const mergeLeft: <T extends Record<string, any>>(a: T, b: T) => T;
|
|
148
|
+
/**
|
|
149
|
+
* Merges two objects, with right object taking precedence
|
|
150
|
+
* @param a - Left object
|
|
151
|
+
* @param b - Right object
|
|
152
|
+
* @returns Merged object with b's properties overriding a's
|
|
153
|
+
*/
|
|
36
154
|
export declare const mergeRight: <T extends Record<string, any>>(a: T, b: T) => T;
|
|
155
|
+
/**
|
|
156
|
+
* Checks if a number is between two values (exclusive)
|
|
157
|
+
* @param bounds - Lower and upper bounds
|
|
158
|
+
* @param n - Number to check
|
|
159
|
+
* @returns True if n is between low and high
|
|
160
|
+
*/
|
|
37
161
|
export declare const between: ([low, high]: [number, number], n: number) => boolean;
|
|
162
|
+
/**
|
|
163
|
+
* Checks if a number is between two values (inclusive)
|
|
164
|
+
* @param bounds - Lower and upper bounds
|
|
165
|
+
* @param n - Number to check
|
|
166
|
+
* @returns True if n is between low and high
|
|
167
|
+
*/
|
|
168
|
+
export declare const within: ([low, high]: [number, number], n: number) => boolean;
|
|
169
|
+
/**
|
|
170
|
+
* Generates random integer between min and max (inclusive)
|
|
171
|
+
* @param min - Minimum value
|
|
172
|
+
* @param max - Maximum value
|
|
173
|
+
* @returns Random integer
|
|
174
|
+
*/
|
|
38
175
|
export declare const randomInt: (min?: number, max?: number) => number;
|
|
176
|
+
/**
|
|
177
|
+
* Generates random string ID
|
|
178
|
+
* @returns Random string suitable for use as an ID
|
|
179
|
+
*/
|
|
39
180
|
export declare const randomId: () => string;
|
|
181
|
+
/**
|
|
182
|
+
* Removes protocol (http://, https://, etc) from URL
|
|
183
|
+
* @param url - URL to process
|
|
184
|
+
* @returns URL without protocol
|
|
185
|
+
*/
|
|
40
186
|
export declare const stripProtocol: (url: string) => string;
|
|
187
|
+
/**
|
|
188
|
+
* Formats URL for display by removing protocol, www, and trailing slash
|
|
189
|
+
* @param url - URL to format
|
|
190
|
+
* @returns Formatted URL
|
|
191
|
+
*/
|
|
41
192
|
export declare const displayUrl: (url: string) => string;
|
|
193
|
+
/**
|
|
194
|
+
* Extracts and formats domain from URL
|
|
195
|
+
* @param url - URL to process
|
|
196
|
+
* @returns Formatted domain name
|
|
197
|
+
*/
|
|
42
198
|
export declare const displayDomain: (url: string) => string;
|
|
199
|
+
/**
|
|
200
|
+
* Creates a promise that resolves after specified time
|
|
201
|
+
* @param t - Time in milliseconds
|
|
202
|
+
* @returns Promise that resolves after t milliseconds
|
|
203
|
+
*/
|
|
43
204
|
export declare const sleep: (t: number) => Promise<unknown>;
|
|
205
|
+
/**
|
|
206
|
+
* Concatenates multiple arrays, filtering out null/undefined
|
|
207
|
+
* @param xs - Arrays to concatenate
|
|
208
|
+
* @returns Combined array
|
|
209
|
+
*/
|
|
44
210
|
export declare const concat: <T>(...xs: T[][]) => T[];
|
|
211
|
+
/**
|
|
212
|
+
* Appends element to array
|
|
213
|
+
* @param x - Element to append
|
|
214
|
+
* @param xs - Array to append to
|
|
215
|
+
* @returns New array with element appended
|
|
216
|
+
*/
|
|
45
217
|
export declare const append: <T>(x: T, xs: T[]) => T[];
|
|
218
|
+
/**
|
|
219
|
+
* Creates union of two arrays
|
|
220
|
+
* @param a - First array
|
|
221
|
+
* @param b - Second array
|
|
222
|
+
* @returns Array containing unique elements from both arrays
|
|
223
|
+
*/
|
|
46
224
|
export declare const union: <T>(a: T[], b: T[]) => T[];
|
|
225
|
+
/**
|
|
226
|
+
* Returns elements common to both arrays
|
|
227
|
+
* @param a - First array
|
|
228
|
+
* @param b - Second array
|
|
229
|
+
* @returns Array of elements present in both inputs
|
|
230
|
+
*/
|
|
47
231
|
export declare const intersection: <T>(a: T[], b: T[]) => T[];
|
|
232
|
+
/**
|
|
233
|
+
* Returns elements in first array not present in second
|
|
234
|
+
* @param a - Source array
|
|
235
|
+
* @param b - Array of elements to exclude
|
|
236
|
+
* @returns Array containing elements unique to first array
|
|
237
|
+
*/
|
|
48
238
|
export declare const difference: <T>(a: T[], b: T[]) => T[];
|
|
239
|
+
/**
|
|
240
|
+
* Removes all instances of an element from array
|
|
241
|
+
* @param a - Element to remove
|
|
242
|
+
* @param xs - Source array
|
|
243
|
+
* @returns New array with element removed
|
|
244
|
+
*/
|
|
49
245
|
export declare const remove: <T>(a: T, xs: T[]) => T[];
|
|
246
|
+
/**
|
|
247
|
+
* Returns elements from second array not present in first
|
|
248
|
+
* @param a - Array of elements to exclude
|
|
249
|
+
* @param b - Source array
|
|
250
|
+
* @returns Filtered array
|
|
251
|
+
*/
|
|
50
252
|
export declare const without: <T>(a: T[], b: T[]) => T[];
|
|
253
|
+
/**
|
|
254
|
+
* Toggles presence of element in array
|
|
255
|
+
* @param x - Element to toggle
|
|
256
|
+
* @param xs - Source array
|
|
257
|
+
* @returns New array with element added or removed
|
|
258
|
+
*/
|
|
51
259
|
export declare const toggle: <T>(x: T, xs: T[]) => T[];
|
|
260
|
+
/**
|
|
261
|
+
* Constrains number between min and max values
|
|
262
|
+
* @param bounds - Minimum and maximum allowed values
|
|
263
|
+
* @param n - Number to clamp
|
|
264
|
+
* @returns Clamped value
|
|
265
|
+
*/
|
|
52
266
|
export declare const clamp: ([min, max]: [number, number], n: number) => number;
|
|
267
|
+
/**
|
|
268
|
+
* Safely parses JSON string
|
|
269
|
+
* @param json - JSON string to parse
|
|
270
|
+
* @returns Parsed object or null if invalid
|
|
271
|
+
*/
|
|
53
272
|
export declare const parseJson: (json: string | Nil) => any;
|
|
273
|
+
/**
|
|
274
|
+
* Gets and parses JSON from localStorage
|
|
275
|
+
* @param k - Storage key
|
|
276
|
+
* @returns Parsed value or undefined if invalid/missing
|
|
277
|
+
*/
|
|
54
278
|
export declare const getJson: (k: string) => any;
|
|
279
|
+
/**
|
|
280
|
+
* Stringifies and stores value in localStorage
|
|
281
|
+
* @param k - Storage key
|
|
282
|
+
* @param v - Value to store
|
|
283
|
+
*/
|
|
55
284
|
export declare const setJson: (k: string, v: any) => void;
|
|
285
|
+
/**
|
|
286
|
+
* Safely executes function and handles errors
|
|
287
|
+
* @param f - Function to execute
|
|
288
|
+
* @param onError - Optional error handler
|
|
289
|
+
* @returns Function result or undefined if error
|
|
290
|
+
*/
|
|
56
291
|
export declare const tryCatch: <T>(f: () => T, onError?: ((e: Error) => void) | undefined) => T | undefined;
|
|
292
|
+
/**
|
|
293
|
+
* Truncates string to length, breaking at word boundaries
|
|
294
|
+
* @param s - String to truncate
|
|
295
|
+
* @param l - Maximum length
|
|
296
|
+
* @param suffix - String to append if truncated
|
|
297
|
+
* @returns Truncated string
|
|
298
|
+
*/
|
|
57
299
|
export declare const ellipsize: (s: string, l: number, suffix?: string) => string;
|
|
300
|
+
/**
|
|
301
|
+
* Checks if value is a plain object
|
|
302
|
+
* @param obj - Value to check
|
|
303
|
+
* @returns True if value is a plain object
|
|
304
|
+
*/
|
|
58
305
|
export declare const isPojo: (obj: any) => boolean;
|
|
306
|
+
/**
|
|
307
|
+
* Deep equality comparison
|
|
308
|
+
* @param a - First value
|
|
309
|
+
* @param b - Second value
|
|
310
|
+
* @returns True if values are deeply equal
|
|
311
|
+
*/
|
|
59
312
|
export declare const equals: (a: any, b: any) => boolean;
|
|
313
|
+
/** Returns a function that gets the nth element of an array */
|
|
60
314
|
export declare const nth: (i: number) => <T>(xs: T[], ...args: unknown[]) => T;
|
|
315
|
+
/** Returns a function that checks if nth element equals value */
|
|
61
316
|
export declare const nthEq: (i: number, v: any) => (xs: any[], ...args: unknown[]) => boolean;
|
|
317
|
+
/** Returns a function that checks if nth element does not equal value */
|
|
62
318
|
export declare const nthNe: (i: number, v: any) => (xs: any[], ...args: unknown[]) => boolean;
|
|
319
|
+
/** Returns a function that checks if key/value pairs of x match all pairs in spec */
|
|
320
|
+
export declare const spec: (values: Record<string, any>) => (x: Record<string, any>) => boolean;
|
|
321
|
+
/** Returns a function that checks equality with value */
|
|
63
322
|
export declare const eq: <T>(v: T) => (x: T) => boolean;
|
|
323
|
+
/** Returns a function that checks inequality with value */
|
|
64
324
|
export declare const ne: <T>(v: T) => (x: T) => boolean;
|
|
65
|
-
|
|
325
|
+
/** Returns a function that gets property value from object */
|
|
326
|
+
export declare const prop: <T>(k: string) => (x: Record<string, unknown>) => T;
|
|
327
|
+
/** Returns a function that adds/updates property on object */
|
|
66
328
|
export declare const assoc: <K extends string, T, U>(k: K, v: T) => (o: U) => U & Record<K, T>;
|
|
329
|
+
/** Generates a hash string from input string */
|
|
67
330
|
export declare const hash: (s: string) => string;
|
|
331
|
+
/** Splits array into two parts at index */
|
|
68
332
|
export declare const splitAt: <T>(n: number, xs: T[]) => T[][];
|
|
333
|
+
/** Inserts element into array at index */
|
|
69
334
|
export declare const insert: <T>(n: number, x: T, xs: T[]) => T[];
|
|
335
|
+
/** Returns random element from array */
|
|
70
336
|
export declare const choice: <T>(xs: T[]) => T;
|
|
337
|
+
/** Returns shuffled copy of iterable */
|
|
71
338
|
export declare const shuffle: <T>(xs: Iterable<T>) => T[];
|
|
339
|
+
/** Returns n random elements from array */
|
|
72
340
|
export declare const sample: <T>(n: number, xs: T[]) => T[];
|
|
341
|
+
/** Checks if value is iterable */
|
|
73
342
|
export declare const isIterable: (x: any) => boolean;
|
|
343
|
+
/** Ensures value is iterable by wrapping in array if needed */
|
|
74
344
|
export declare const toIterable: (x: any) => any;
|
|
345
|
+
/** Ensures value is array by wrapping if needed */
|
|
75
346
|
export declare const ensurePlural: <T>(x: T | T[]) => T[];
|
|
347
|
+
/** Converts string or number to number */
|
|
76
348
|
export declare const ensureNumber: (x: number | string) => number;
|
|
349
|
+
/** Returns a function that gets property value from object */
|
|
350
|
+
export declare const pluck: <T>(k: string, xs: Record<string, unknown>[]) => T[];
|
|
351
|
+
/**
|
|
352
|
+
* Creates object from array of key-value pairs
|
|
353
|
+
* @param pairs - Array of [key, value] tuples
|
|
354
|
+
* @returns Object with keys and values from pairs
|
|
355
|
+
*/
|
|
77
356
|
export declare const fromPairs: <T>(pairs: [k?: string | undefined, v?: T | undefined, ...args: unknown[]][]) => Record<string, T>;
|
|
357
|
+
/**
|
|
358
|
+
* Flattens array of arrays into single array
|
|
359
|
+
* @param xs - Array of arrays to flatten
|
|
360
|
+
* @returns Flattened array
|
|
361
|
+
*/
|
|
78
362
|
export declare const flatten: <T>(xs: T[][]) => T[];
|
|
363
|
+
/**
|
|
364
|
+
* Splits array into two arrays based on predicate
|
|
365
|
+
* @param f - Function to test elements
|
|
366
|
+
* @param xs - Array to partition
|
|
367
|
+
* @returns Tuple of [matching, non-matching] arrays
|
|
368
|
+
*/
|
|
79
369
|
export declare const partition: <T>(f: (x: T) => boolean, xs: T[]) => T[][];
|
|
370
|
+
/**
|
|
371
|
+
* Returns array with duplicate elements removed
|
|
372
|
+
* @param xs - Array with possible duplicates
|
|
373
|
+
* @returns Array with unique elements
|
|
374
|
+
*/
|
|
80
375
|
export declare const uniq: <T>(xs: T[]) => T[];
|
|
376
|
+
/**
|
|
377
|
+
* Returns array with elements unique by key function
|
|
378
|
+
* @param f - Function to generate key for each element
|
|
379
|
+
* @param xs - Input array
|
|
380
|
+
* @returns Array with elements unique by key
|
|
381
|
+
*/
|
|
81
382
|
export declare const uniqBy: <T>(f: (x: T) => any, xs: T[]) => T[];
|
|
383
|
+
/**
|
|
384
|
+
* Returns sorted copy of array
|
|
385
|
+
* @param xs - Array to sort
|
|
386
|
+
* @returns New sorted array
|
|
387
|
+
*/
|
|
82
388
|
export declare const sort: <T>(xs: T[]) => T[];
|
|
389
|
+
/**
|
|
390
|
+
* Returns array sorted by key function
|
|
391
|
+
* @param f - Function to generate sort key
|
|
392
|
+
* @param xs - Array to sort
|
|
393
|
+
* @returns Sorted array
|
|
394
|
+
*/
|
|
83
395
|
export declare const sortBy: <T>(f: (x: T) => any, xs: T[]) => T[];
|
|
396
|
+
/**
|
|
397
|
+
* Groups array elements by key function
|
|
398
|
+
* @param f - Function to generate group key
|
|
399
|
+
* @param xs - Array to group
|
|
400
|
+
* @returns Map of groups
|
|
401
|
+
*/
|
|
84
402
|
export declare const groupBy: <T, K>(f: (x: T) => K, xs: T[]) => Map<K, T[]>;
|
|
403
|
+
/**
|
|
404
|
+
* Creates map from array using key function
|
|
405
|
+
* @param f - Function to generate key
|
|
406
|
+
* @param xs - Array to index
|
|
407
|
+
* @returns Map of values by key
|
|
408
|
+
*/
|
|
85
409
|
export declare const indexBy: <T, K>(f: (x: T) => K, xs: T[]) => Map<K, T>;
|
|
410
|
+
/**
|
|
411
|
+
* Creates array of specified length using generator function
|
|
412
|
+
* @param n - Length of array
|
|
413
|
+
* @param f - Function to generate each element
|
|
414
|
+
* @returns Generated array
|
|
415
|
+
*/
|
|
86
416
|
export declare const initArray: <T>(n: number, f: () => T) => T[];
|
|
417
|
+
/**
|
|
418
|
+
* Splits array into chunks of specified length
|
|
419
|
+
* @param chunkLength - Maximum length of each chunk
|
|
420
|
+
* @param xs - Array to split
|
|
421
|
+
* @returns Array of chunks
|
|
422
|
+
*/
|
|
87
423
|
export declare const chunk: <T>(chunkLength: number, xs: T[]) => T[][];
|
|
424
|
+
/**
|
|
425
|
+
* Splits array into specified number of chunks
|
|
426
|
+
* @param n - Number of chunks
|
|
427
|
+
* @param xs - Array to split
|
|
428
|
+
* @returns Array of n chunks
|
|
429
|
+
*/
|
|
88
430
|
export declare const chunks: <T>(n: number, xs: T[]) => T[][];
|
|
431
|
+
/**
|
|
432
|
+
* Creates function that only executes once
|
|
433
|
+
* @param f - Function to wrap
|
|
434
|
+
* @returns Function that executes f only on first call
|
|
435
|
+
*/
|
|
89
436
|
export declare const once: (f: (...args: any) => void) => (...args: any) => void;
|
|
437
|
+
/**
|
|
438
|
+
* Memoizes function results based on arguments
|
|
439
|
+
* @param f - Function to memoize
|
|
440
|
+
* @returns Memoized function
|
|
441
|
+
*/
|
|
90
442
|
export declare const memoize: <T>(f: (...args: any[]) => T) => (...args: any[]) => T;
|
|
443
|
+
/**
|
|
444
|
+
* Creates throttled version of function
|
|
445
|
+
* @param ms - Minimum time between calls
|
|
446
|
+
* @param f - Function to throttle
|
|
447
|
+
* @returns Throttled function
|
|
448
|
+
*/
|
|
91
449
|
export declare const throttle: <F extends (...args: any[]) => any>(ms: number, f: F) => F | ((...thisArgs: Parameters<F>) => void);
|
|
450
|
+
/**
|
|
451
|
+
* Creates throttled function that returns cached value
|
|
452
|
+
* @param ms - Minimum time between updates
|
|
453
|
+
* @param f - Function to throttle
|
|
454
|
+
* @returns Function returning latest value
|
|
455
|
+
*/
|
|
92
456
|
export declare const throttleWithValue: <T>(ms: number, f: () => T) => () => T;
|
|
457
|
+
/**
|
|
458
|
+
* Creates batching function that collects items
|
|
459
|
+
* @param t - Time window for batching
|
|
460
|
+
* @param f - Function to process batch
|
|
461
|
+
* @returns Function that adds items to batch
|
|
462
|
+
*/
|
|
93
463
|
export declare const batch: <T>(t: number, f: (xs: T[]) => void) => (x: T) => void;
|
|
464
|
+
/**
|
|
465
|
+
* Creates batching function that returns results
|
|
466
|
+
* @param t - Time window for batching
|
|
467
|
+
* @param execute - Function to process batch
|
|
468
|
+
* @returns Function that returns promise of result
|
|
469
|
+
*/
|
|
94
470
|
export declare const batcher: <T, U>(t: number, execute: (request: T[]) => U[] | Promise<U[]>) => (request: T) => Promise<U>;
|
|
471
|
+
/**
|
|
472
|
+
* Adds value to Set at key in object
|
|
473
|
+
* @param m - Object mapping keys to Sets
|
|
474
|
+
* @param k - Key to add to
|
|
475
|
+
* @param v - Value to add
|
|
476
|
+
*/
|
|
95
477
|
export declare const addToKey: <T>(m: Record<string, Set<T>>, k: string, v: T) => void;
|
|
478
|
+
/**
|
|
479
|
+
* Pushes value to array at key in object
|
|
480
|
+
* @param m - Object mapping keys to arrays
|
|
481
|
+
* @param k - Key to push to
|
|
482
|
+
* @param v - Value to push
|
|
483
|
+
*/
|
|
96
484
|
export declare const pushToKey: <T>(m: Record<string, T[]>, k: string, v: T) => void;
|
|
485
|
+
/**
|
|
486
|
+
* Adds value to Set at key in Map
|
|
487
|
+
* @param m - Map of Sets
|
|
488
|
+
* @param k - Key to add to
|
|
489
|
+
* @param v - Value to add
|
|
490
|
+
*/
|
|
97
491
|
export declare const addToMapKey: <K, T>(m: Map<K, Set<T>>, k: K, v: T) => void;
|
|
492
|
+
/**
|
|
493
|
+
* Pushes value to array at key in Map
|
|
494
|
+
* @param m - Map of arrays
|
|
495
|
+
* @param k - Key to push to
|
|
496
|
+
* @param v - Value to push
|
|
497
|
+
*/
|
|
98
498
|
export declare const pushToMapKey: <K, T>(m: Map<K, T[]>, k: K, v: T) => void;
|
|
499
|
+
/**
|
|
500
|
+
* Switches on key in object, with default fallback
|
|
501
|
+
* @param k - Key to look up
|
|
502
|
+
* @param m - Object with values and optional default
|
|
503
|
+
* @returns Value at key or default value
|
|
504
|
+
*/
|
|
99
505
|
export declare const switcher: <T>(k: string, m: Record<string, T>) => T;
|
|
506
|
+
/** One minute in seconds */
|
|
100
507
|
export declare const MINUTE = 60;
|
|
508
|
+
/** One hour in seconds */
|
|
101
509
|
export declare const HOUR: number;
|
|
510
|
+
/** One day in seconds */
|
|
102
511
|
export declare const DAY: number;
|
|
512
|
+
/** One week in seconds */
|
|
103
513
|
export declare const WEEK: number;
|
|
514
|
+
/** One month in seconds (approximate) */
|
|
104
515
|
export declare const MONTH: number;
|
|
516
|
+
/** One quarter in seconds (approximate) */
|
|
105
517
|
export declare const QUARTER: number;
|
|
518
|
+
/** One year in seconds (approximate) */
|
|
106
519
|
export declare const YEAR: number;
|
|
520
|
+
/**
|
|
521
|
+
* Multiplies time unit by count
|
|
522
|
+
* @param unit - Time unit in seconds
|
|
523
|
+
* @param count - Number of units
|
|
524
|
+
* @returns Total seconds
|
|
525
|
+
*/
|
|
107
526
|
export declare const int: (unit: number, count?: number) => number;
|
|
527
|
+
/** Returns current Unix timestamp in seconds */
|
|
108
528
|
export declare const now: () => number;
|
|
529
|
+
/**
|
|
530
|
+
* Returns Unix timestamp from specified time ago
|
|
531
|
+
* @param unit - Time unit in seconds
|
|
532
|
+
* @param count - Number of units
|
|
533
|
+
* @returns Timestamp in seconds
|
|
534
|
+
*/
|
|
109
535
|
export declare const ago: (unit: number, count?: number) => number;
|
|
536
|
+
/**
|
|
537
|
+
* Converts seconds to milliseconds
|
|
538
|
+
* @param seconds - Time in seconds
|
|
539
|
+
* @returns Time in milliseconds
|
|
540
|
+
*/
|
|
110
541
|
export declare const ms: (seconds: number) => number;
|
|
542
|
+
/** Options for fetch requests */
|
|
111
543
|
type FetchOpts = {
|
|
112
544
|
method?: string;
|
|
113
545
|
headers?: Record<string, string | boolean>;
|
|
114
546
|
body?: string | FormData;
|
|
115
547
|
};
|
|
548
|
+
/**
|
|
549
|
+
* Fetches JSON from URL with options
|
|
550
|
+
* @param url - URL to fetch from
|
|
551
|
+
* @param opts - Fetch options
|
|
552
|
+
* @returns Promise of parsed JSON response
|
|
553
|
+
*/
|
|
116
554
|
export declare const fetchJson: (url: string, opts?: FetchOpts) => Promise<any>;
|
|
555
|
+
/**
|
|
556
|
+
* Posts JSON data to URL
|
|
557
|
+
* @param url - URL to post to
|
|
558
|
+
* @param data - Data to send
|
|
559
|
+
* @param opts - Additional fetch options
|
|
560
|
+
* @returns Promise of parsed JSON response
|
|
561
|
+
*/
|
|
117
562
|
export declare const postJson: <T>(url: string, data: T, opts?: FetchOpts) => Promise<any>;
|
|
118
|
-
|
|
119
|
-
|
|
563
|
+
/**
|
|
564
|
+
* Uploads file to URL
|
|
565
|
+
* @param url - Upload URL
|
|
566
|
+
* @param file - File to upload
|
|
567
|
+
* @returns Promise of parsed JSON response
|
|
568
|
+
*/
|
|
569
|
+
export declare const uploadFile: (url: string, file: File) => Promise<any>;
|
|
570
|
+
/**
|
|
571
|
+
* Converts hex string to bech32 format
|
|
572
|
+
* @param prefix - Bech32 prefix
|
|
573
|
+
* @param hex - Hex string to convert
|
|
574
|
+
* @returns Bech32 encoded string
|
|
575
|
+
*/
|
|
576
|
+
export declare const hexToBech32: (prefix: string, hex: string) => `${Lowercase<string>}1${string}`;
|
|
577
|
+
/**
|
|
578
|
+
* Converts bech32 string to hex format
|
|
579
|
+
* @param b32 - Bech32 string to convert
|
|
580
|
+
* @returns Hex encoded string
|
|
581
|
+
*/
|
|
120
582
|
export declare const bech32ToHex: (b32: string) => string;
|
|
121
|
-
export type OmitStatics<T, S extends string> = T extends {
|
|
122
|
-
new (...args: infer A): infer R;
|
|
123
|
-
} ? {
|
|
124
|
-
new (...args: A): R;
|
|
125
|
-
} & Omit<T, S> : Omit<T, S>;
|
|
126
|
-
export type OmitAllStatics<T extends {
|
|
127
|
-
new (...args: any[]): any;
|
|
128
|
-
prototype: any;
|
|
129
|
-
}> = T extends {
|
|
130
|
-
new (...args: infer A): infer R;
|
|
131
|
-
prototype: infer P;
|
|
132
|
-
} ? {
|
|
133
|
-
new (...args: A): R;
|
|
134
|
-
prototype: P;
|
|
135
|
-
} : never;
|
|
136
583
|
export {};
|