@welshman/lib 0.1.1 → 0.1.2
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/LICENSE +21 -0
- package/{build/src → dist}/Deferred.d.ts +1 -0
- package/dist/Deferred.d.ts.map +1 -0
- package/dist/Deferred.js.map +1 -0
- package/{build/src → dist}/Emitter.d.ts +1 -0
- package/dist/Emitter.d.ts.map +1 -0
- package/dist/Emitter.js.map +1 -0
- package/{build/src → dist}/LRUCache.d.ts +1 -0
- package/dist/LRUCache.d.ts.map +1 -0
- package/dist/LRUCache.js.map +1 -0
- package/{build/src → dist}/TaskQueue.d.ts +1 -0
- package/dist/TaskQueue.d.ts.map +1 -0
- package/dist/TaskQueue.js.map +1 -0
- package/{build/src → dist}/Tools.d.ts +343 -350
- package/dist/Tools.d.ts.map +1 -0
- package/{build/src → dist}/Tools.js +575 -522
- package/dist/Tools.js.map +1 -0
- package/{build/src → dist}/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js.map +1 -0
- package/dist/normalize-url/index.d.ts +286 -0
- package/dist/normalize-url/index.d.ts.map +1 -0
- package/{build/src → dist}/normalize-url/index.js +53 -51
- package/dist/normalize-url/index.js.map +1 -0
- package/package.json +14 -17
- package/README.md +0 -13
- package/build/src/Deferred.js.map +0 -1
- package/build/src/Emitter.js.map +0 -1
- package/build/src/LRUCache.js.map +0 -1
- package/build/src/TaskQueue.js.map +0 -1
- package/build/src/Tools.js.map +0 -1
- package/build/src/index.js.map +0 -1
- package/build/src/normalize-url/index.d.ts +0 -285
- package/build/src/normalize-url/index.js.map +0 -1
- package/build/tsconfig.tsbuildinfo +0 -1
- /package/{build/src → dist}/Deferred.js +0 -0
- /package/{build/src → dist}/Emitter.js +0 -0
- /package/{build/src → dist}/LRUCache.js +0 -0
- /package/{build/src → dist}/TaskQueue.js +0 -0
- /package/{build/src → dist}/index.js +0 -0
|
@@ -1,38 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
export type Nil = null | undefined;
|
|
3
|
-
/** Checks if a value is null or undefined */
|
|
4
|
-
export declare const isNil: (x: any) => boolean;
|
|
5
|
-
/** Type representing an optional value */
|
|
6
|
-
export type Maybe<T> = T | undefined;
|
|
7
|
-
/** Type that is shorthand for Record<string, T> */
|
|
8
|
-
export type Obj<T = any> = Record<string, T>;
|
|
9
|
-
/**
|
|
10
|
-
* Executes a function if the value is defined
|
|
11
|
-
* @param x - The value to check
|
|
12
|
-
* @param f - Function to execute if x is defined
|
|
13
|
-
* @returns Result of f(x) if x is defined, undefined otherwise
|
|
14
|
-
*/
|
|
15
|
-
export declare const ifLet: <T>(x: T | undefined, f: (x: T) => void) => void;
|
|
1
|
+
type Obj<T = any> = Record<string, T>;
|
|
16
2
|
/** Function that does nothing and returns undefined */
|
|
17
3
|
export declare const noop: (...args: unknown[]) => undefined;
|
|
18
|
-
/**
|
|
19
|
-
* Returns the first element of an array
|
|
20
|
-
* @param xs - The array
|
|
21
|
-
* @returns First element or undefined
|
|
22
|
-
*/
|
|
23
|
-
export declare const first: <T>(xs: T[], ...args: unknown[]) => T;
|
|
24
|
-
/**
|
|
25
|
-
* Returns the first element of the first array in a nested array
|
|
26
|
-
* @param xs - Array of arrays
|
|
27
|
-
* @returns First element of first array or undefined
|
|
28
|
-
*/
|
|
29
|
-
export declare const ffirst: <T>(xs: T[][], ...args: unknown[]) => T;
|
|
30
|
-
/**
|
|
31
|
-
* Returns the last element of an array
|
|
32
|
-
* @param xs - The array
|
|
33
|
-
* @returns Last element or undefined
|
|
34
|
-
*/
|
|
35
|
-
export declare const last: <T>(xs: T[], ...args: unknown[]) => T;
|
|
36
4
|
/**
|
|
37
5
|
* Returns the input value unchanged
|
|
38
6
|
* @param x - Any value
|
|
@@ -51,119 +19,45 @@ export declare const always: <T>(x: T, ...args: unknown[]) => () => T;
|
|
|
51
19
|
* @returns !x
|
|
52
20
|
*/
|
|
53
21
|
export declare const not: (x: any, ...args: unknown[]) => boolean;
|
|
54
|
-
/**
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Deep equality comparison
|
|
24
|
+
* @param a - First value
|
|
25
|
+
* @param b - Second value
|
|
26
|
+
* @returns True if values are deeply equal
|
|
27
|
+
*/
|
|
28
|
+
export declare const equals: (a: any, b: any) => boolean;
|
|
29
|
+
/** Converts string or number to number */
|
|
30
|
+
export declare const ensureNumber: (x: number | string) => number;
|
|
31
|
+
/** Converts a `number | undefined` to a number, defaulting to 0 */
|
|
32
|
+
export declare const num: (x: number | undefined) => number;
|
|
58
33
|
/** Adds two numbers, handling undefined values */
|
|
59
|
-
export declare const add: (x:
|
|
34
|
+
export declare const add: (x: number | undefined, y: number | undefined) => number;
|
|
60
35
|
/** Subtracts two numbers, handling undefined values */
|
|
61
|
-
export declare const sub: (x:
|
|
36
|
+
export declare const sub: (x: number | undefined, y: number | undefined) => number;
|
|
62
37
|
/** Multiplies two numbers, handling undefined values */
|
|
63
|
-
export declare const mul: (x:
|
|
38
|
+
export declare const mul: (x: number | undefined, y: number | undefined) => number;
|
|
64
39
|
/** Divides two numbers, handling undefined values */
|
|
65
|
-
export declare const div: (x:
|
|
40
|
+
export declare const div: (x: number | undefined, y: number) => number;
|
|
66
41
|
/** Increments a number by 1, handling undefined values */
|
|
67
|
-
export declare const inc: (x:
|
|
42
|
+
export declare const inc: (x: number | undefined) => number;
|
|
68
43
|
/** Decrements a number by 1, handling undefined values */
|
|
69
|
-
export declare const dec: (x:
|
|
44
|
+
export declare const dec: (x: number | undefined) => number;
|
|
70
45
|
/** Less than comparison, handling undefined values */
|
|
71
|
-
export declare const lt: (x:
|
|
46
|
+
export declare const lt: (x: number | undefined, y: number | undefined) => boolean;
|
|
72
47
|
/** Less than or equal comparison, handling undefined values */
|
|
73
|
-
export declare const lte: (x:
|
|
48
|
+
export declare const lte: (x: number | undefined, y: number | undefined) => boolean;
|
|
74
49
|
/** Greater than comparison, handling undefined values */
|
|
75
|
-
export declare const gt: (x:
|
|
50
|
+
export declare const gt: (x: number | undefined, y: number | undefined) => boolean;
|
|
76
51
|
/** Greater than or equal comparison, handling undefined values */
|
|
77
|
-
export declare const gte: (x:
|
|
52
|
+
export declare const gte: (x: number | undefined, y: number | undefined) => boolean;
|
|
78
53
|
/** Returns maximum value in array, handling undefined values */
|
|
79
|
-
export declare const max: (xs:
|
|
54
|
+
export declare const max: (xs: (number | undefined)[]) => number;
|
|
80
55
|
/** Returns minimum value in array, handling undefined values */
|
|
81
|
-
export declare const min: (xs:
|
|
56
|
+
export declare const min: (xs: (number | undefined)[]) => number;
|
|
82
57
|
/** Returns sum of array values, handling undefined values */
|
|
83
|
-
export declare const sum: (xs:
|
|
58
|
+
export declare const sum: (xs: (number | undefined)[]) => number;
|
|
84
59
|
/** Returns average of array values, handling undefined values */
|
|
85
|
-
export declare const avg: (xs:
|
|
86
|
-
/**
|
|
87
|
-
* Returns array with first n elements removed
|
|
88
|
-
* @param n - Number of elements to drop
|
|
89
|
-
* @param xs - Input array
|
|
90
|
-
* @returns Array with first n elements removed
|
|
91
|
-
*/
|
|
92
|
-
export declare const drop: <T>(n: number, xs: T[]) => T[];
|
|
93
|
-
/**
|
|
94
|
-
* Returns first n elements of array
|
|
95
|
-
* @param n - Number of elements to take
|
|
96
|
-
* @param xs - Input array
|
|
97
|
-
* @returns Array of first n elements
|
|
98
|
-
*/
|
|
99
|
-
export declare const take: <T>(n: number, xs: T[]) => T[];
|
|
100
|
-
/**
|
|
101
|
-
* Creates new object with specified keys removed
|
|
102
|
-
* @param ks - Keys to remove
|
|
103
|
-
* @param x - Source object
|
|
104
|
-
* @returns New object without specified keys
|
|
105
|
-
*/
|
|
106
|
-
export declare const omit: <T extends Obj>(ks: string[], x: T) => T;
|
|
107
|
-
/**
|
|
108
|
-
* Creates new object excluding entries with specified values
|
|
109
|
-
* @param xs - Values to exclude
|
|
110
|
-
* @param x - Source object
|
|
111
|
-
* @returns New object without entries containing specified values
|
|
112
|
-
*/
|
|
113
|
-
export declare const omitVals: <T extends Obj>(xs: any[], x: T) => T;
|
|
114
|
-
/**
|
|
115
|
-
* Creates new object with only specified keys
|
|
116
|
-
* @param ks - Keys to keep
|
|
117
|
-
* @param x - Source object
|
|
118
|
-
* @returns New object with only specified keys
|
|
119
|
-
*/
|
|
120
|
-
export declare const pick: <T extends Obj>(ks: string[], x: T) => T;
|
|
121
|
-
/**
|
|
122
|
-
* Generates sequence of numbers from a to b
|
|
123
|
-
* @param a - Start number (inclusive)
|
|
124
|
-
* @param b - End number (exclusive)
|
|
125
|
-
* @param step - Increment between numbers
|
|
126
|
-
* @yields Numbers in sequence
|
|
127
|
-
*/
|
|
128
|
-
export declare function range(a: number, b: number, step?: number): Generator<number, void, unknown>;
|
|
129
|
-
/**
|
|
130
|
-
* Yields indexed items
|
|
131
|
-
* @param items - A collection of items
|
|
132
|
-
* @yields tuples of [index, item]
|
|
133
|
-
*/
|
|
134
|
-
export declare function enumerate<T>(items: T[]): Generator<[number, T], void, unknown>;
|
|
135
|
-
/**
|
|
136
|
-
* Creates new object with transformed keys
|
|
137
|
-
* @param f - Function to transform keys
|
|
138
|
-
* @param x - Source object
|
|
139
|
-
* @returns Object with transformed keys
|
|
140
|
-
*/
|
|
141
|
-
export declare const mapKeys: <T extends Obj>(f: (v: string) => string, x: T) => T;
|
|
142
|
-
/**
|
|
143
|
-
* Creates new object with transformed values
|
|
144
|
-
* @param f - Function to transform values
|
|
145
|
-
* @param x - Source object
|
|
146
|
-
* @returns Object with transformed values
|
|
147
|
-
*/
|
|
148
|
-
export declare const mapVals: <V, U>(f: (v: V) => U, x: Record<string, V>) => Record<string, U>;
|
|
149
|
-
/**
|
|
150
|
-
* Merges two objects, with left object taking precedence
|
|
151
|
-
* @param a - Left object
|
|
152
|
-
* @param b - Right object
|
|
153
|
-
* @returns Merged object with a"s properties overriding b"s
|
|
154
|
-
*/
|
|
155
|
-
export declare const mergeLeft: <T extends Obj>(a: T, b: T) => T;
|
|
156
|
-
/**
|
|
157
|
-
* Merges two objects, with right object taking precedence
|
|
158
|
-
* @param a - Left object
|
|
159
|
-
* @param b - Right object
|
|
160
|
-
* @returns Merged object with b"s properties overriding a"s
|
|
161
|
-
*/
|
|
162
|
-
export declare const mergeRight: <T extends Obj>(a: T, b: T) => T;
|
|
163
|
-
/** Deep merge two objects, prioritizing the first argument. */
|
|
164
|
-
export declare const deepMergeLeft: (a: Obj, b: Obj) => Obj<any>;
|
|
165
|
-
/** Deep merge two objects, prioritizing the second argument. */
|
|
166
|
-
export declare const deepMergeRight: (a: Obj, b: Obj) => Obj<any>;
|
|
60
|
+
export declare const avg: (xs: (number | undefined)[]) => number;
|
|
167
61
|
/**
|
|
168
62
|
* Checks if a number is between two values (exclusive)
|
|
169
63
|
* @param bounds - Lower and upper bounds
|
|
@@ -179,46 +73,87 @@ export declare const between: ([low, high]: [number, number], n: number) => bool
|
|
|
179
73
|
*/
|
|
180
74
|
export declare const within: ([low, high]: [number, number], n: number) => boolean;
|
|
181
75
|
/**
|
|
182
|
-
*
|
|
183
|
-
* @param
|
|
184
|
-
* @param
|
|
185
|
-
* @returns
|
|
76
|
+
* Constrains number between min and max values
|
|
77
|
+
* @param bounds - Minimum and maximum allowed values
|
|
78
|
+
* @param n - Number to clamp
|
|
79
|
+
* @returns Clamped value
|
|
186
80
|
*/
|
|
187
|
-
export declare const
|
|
81
|
+
export declare const clamp: ([min, max]: [number, number], n: number) => number;
|
|
188
82
|
/**
|
|
189
|
-
*
|
|
190
|
-
* @
|
|
83
|
+
* Round a number to the nearest float precision
|
|
84
|
+
* @param precision - Number of decimal places
|
|
85
|
+
* @param x - Number to round
|
|
86
|
+
* @returns Formatted number
|
|
191
87
|
*/
|
|
192
|
-
export declare const
|
|
88
|
+
export declare const round: (precision: number, x: number) => number;
|
|
89
|
+
/** One minute in seconds */
|
|
90
|
+
export declare const MINUTE = 60;
|
|
91
|
+
/** One hour in seconds */
|
|
92
|
+
export declare const HOUR: number;
|
|
93
|
+
/** One day in seconds */
|
|
94
|
+
export declare const DAY: number;
|
|
95
|
+
/** One week in seconds */
|
|
96
|
+
export declare const WEEK: number;
|
|
97
|
+
/** One month in seconds (approximate) */
|
|
98
|
+
export declare const MONTH: number;
|
|
99
|
+
/** One quarter in seconds (approximate) */
|
|
100
|
+
export declare const QUARTER: number;
|
|
101
|
+
/** One year in seconds (approximate) */
|
|
102
|
+
export declare const YEAR: number;
|
|
193
103
|
/**
|
|
194
|
-
*
|
|
195
|
-
* @param
|
|
196
|
-
* @
|
|
104
|
+
* Multiplies time unit by count
|
|
105
|
+
* @param unit - Time unit in seconds
|
|
106
|
+
* @param count - Number of units
|
|
107
|
+
* @returns Total seconds
|
|
197
108
|
*/
|
|
198
|
-
export declare const
|
|
109
|
+
export declare const int: (unit: number, count?: number) => number;
|
|
110
|
+
/** Returns current Unix timestamp in seconds */
|
|
111
|
+
export declare const now: () => number;
|
|
199
112
|
/**
|
|
200
|
-
*
|
|
201
|
-
* @param
|
|
202
|
-
* @
|
|
113
|
+
* Returns Unix timestamp from specified time ago
|
|
114
|
+
* @param unit - Time unit in seconds
|
|
115
|
+
* @param count - Number of units
|
|
116
|
+
* @returns Timestamp in seconds
|
|
203
117
|
*/
|
|
204
|
-
export declare const
|
|
118
|
+
export declare const ago: (unit: number, count?: number) => number;
|
|
205
119
|
/**
|
|
206
|
-
*
|
|
207
|
-
* @param
|
|
208
|
-
* @returns
|
|
120
|
+
* Converts seconds to milliseconds
|
|
121
|
+
* @param seconds - Time in seconds
|
|
122
|
+
* @returns Time in milliseconds
|
|
209
123
|
*/
|
|
210
|
-
export declare const
|
|
124
|
+
export declare const ms: (seconds: number) => number;
|
|
211
125
|
/**
|
|
212
|
-
*
|
|
213
|
-
* @param
|
|
214
|
-
* @returns
|
|
126
|
+
* Returns the first element of an array
|
|
127
|
+
* @param xs - The array
|
|
128
|
+
* @returns First element or undefined
|
|
215
129
|
*/
|
|
216
|
-
export declare const
|
|
130
|
+
export declare const first: <T>(xs: Iterable<T>, ...args: unknown[]) => T | undefined;
|
|
217
131
|
/**
|
|
218
|
-
*
|
|
219
|
-
* @
|
|
132
|
+
* Returns the first element of the first array in a nested array
|
|
133
|
+
* @param xs - Array of arrays
|
|
134
|
+
* @returns First element of first array or undefined
|
|
220
135
|
*/
|
|
221
|
-
export declare const
|
|
136
|
+
export declare const ffirst: <T>(xs: Iterable<Iterable<T>>, ...args: unknown[]) => T | undefined;
|
|
137
|
+
/**
|
|
138
|
+
* Returns the last element of an array
|
|
139
|
+
* @param xs - The array
|
|
140
|
+
* @returns Last element or undefined
|
|
141
|
+
*/
|
|
142
|
+
export declare const last: <T>(xs: Iterable<T>, ...args: unknown[]) => T;
|
|
143
|
+
/**
|
|
144
|
+
* Returns array with first n elements removed
|
|
145
|
+
* @param n - Number of elements to drop
|
|
146
|
+
* @param xs - Input array
|
|
147
|
+
* @returns Array with first n elements removed
|
|
148
|
+
*/
|
|
149
|
+
export declare const drop: <T>(n: number, xs: Iterable<T>) => T[];
|
|
150
|
+
/**
|
|
151
|
+
* Returns first n elements of array
|
|
152
|
+
* @param n - Number of elements to take
|
|
153
|
+
* @param xs - Input array
|
|
154
|
+
* @returns Array of first n elements
|
|
155
|
+
*/
|
|
156
|
+
export declare const take: <T>(n: number, xs: Iterable<T>) => T[];
|
|
222
157
|
/**
|
|
223
158
|
* Concatenates multiple arrays, filtering out null/undefined
|
|
224
159
|
* @param xs - Arrays to concatenate
|
|
@@ -275,135 +210,44 @@ export declare const without: <T>(a: T[], b: T[]) => T[];
|
|
|
275
210
|
*/
|
|
276
211
|
export declare const toggle: <T>(x: T, xs: T[]) => T[];
|
|
277
212
|
/**
|
|
278
|
-
*
|
|
279
|
-
* @param
|
|
280
|
-
* @param
|
|
281
|
-
* @
|
|
213
|
+
* Generates sequence of numbers from a to b
|
|
214
|
+
* @param a - Start number (inclusive)
|
|
215
|
+
* @param b - End number (exclusive)
|
|
216
|
+
* @param step - Increment between numbers
|
|
217
|
+
* @yields Numbers in sequence
|
|
282
218
|
*/
|
|
283
|
-
export declare
|
|
219
|
+
export declare function range(a: number, b: number, step?: number): Generator<number, void, unknown>;
|
|
284
220
|
/**
|
|
285
|
-
*
|
|
286
|
-
* @param
|
|
287
|
-
* @
|
|
288
|
-
* @returns Formatted number
|
|
221
|
+
* Yields indexed items
|
|
222
|
+
* @param items - A collection of items
|
|
223
|
+
* @yields tuples of [index, item]
|
|
289
224
|
*/
|
|
290
|
-
export declare
|
|
225
|
+
export declare function enumerate<T>(items: T[]): Generator<[number, T], void, unknown>;
|
|
226
|
+
/** Returns a function that gets property value from object */
|
|
227
|
+
export declare const pluck: <T>(k: string, xs: Record<string, unknown>[]) => T[];
|
|
291
228
|
/**
|
|
292
|
-
*
|
|
293
|
-
* @param
|
|
294
|
-
* @returns
|
|
229
|
+
* Creates object from array of key-value pairs
|
|
230
|
+
* @param pairs - Array of [key, value] tuples
|
|
231
|
+
* @returns Object with keys and values from pairs
|
|
295
232
|
*/
|
|
296
|
-
export declare const
|
|
233
|
+
export declare const fromPairs: <T>(pairs: [k?: string, v?: T, ...args: unknown[]][]) => Record<string, T>;
|
|
297
234
|
/**
|
|
298
|
-
*
|
|
299
|
-
* @param
|
|
300
|
-
* @returns
|
|
235
|
+
* Flattens array of arrays into single array
|
|
236
|
+
* @param xs - Array of arrays to flatten
|
|
237
|
+
* @returns Flattened array
|
|
301
238
|
*/
|
|
302
|
-
export declare const
|
|
239
|
+
export declare const flatten: <T>(xs: T[][]) => T[];
|
|
303
240
|
/**
|
|
304
|
-
*
|
|
305
|
-
* @param
|
|
306
|
-
* @param
|
|
241
|
+
* Splits array into two arrays based on predicate
|
|
242
|
+
* @param f - Function to test elements
|
|
243
|
+
* @param xs - Array to partition
|
|
244
|
+
* @returns Tuple of [matching, non-matching] arrays
|
|
307
245
|
*/
|
|
308
|
-
export declare const
|
|
246
|
+
export declare const partition: <T>(f: (x: T) => boolean, xs: T[]) => T[][];
|
|
309
247
|
/**
|
|
310
|
-
*
|
|
311
|
-
* @param
|
|
312
|
-
* @
|
|
313
|
-
* @returns Function result or undefined if error
|
|
314
|
-
*/
|
|
315
|
-
export declare const tryCatch: <T>(f: () => T, onError?: (e: Error) => void) => T | undefined;
|
|
316
|
-
/**
|
|
317
|
-
* Truncates string to length, breaking at word boundaries
|
|
318
|
-
* @param s - String to truncate
|
|
319
|
-
* @param l - Maximum length
|
|
320
|
-
* @param suffix - String to append if truncated
|
|
321
|
-
* @returns Truncated string
|
|
322
|
-
*/
|
|
323
|
-
export declare const ellipsize: (s: string, l: number, suffix?: string) => string;
|
|
324
|
-
/**
|
|
325
|
-
* Checks if value is a plain object
|
|
326
|
-
* @param obj - Value to check
|
|
327
|
-
* @returns True if value is a plain object
|
|
328
|
-
*/
|
|
329
|
-
export declare const isPojo: (obj: any) => boolean;
|
|
330
|
-
/**
|
|
331
|
-
* Deep equality comparison
|
|
332
|
-
* @param a - First value
|
|
333
|
-
* @param b - Second value
|
|
334
|
-
* @returns True if values are deeply equal
|
|
335
|
-
*/
|
|
336
|
-
export declare const equals: (a: any, b: any) => boolean;
|
|
337
|
-
/** Returns a function that gets the nth element of an array */
|
|
338
|
-
export declare const nth: (i: number) => <T>(xs: T[], ...args: unknown[]) => T;
|
|
339
|
-
/** Returns a function that checks if nth element equals value */
|
|
340
|
-
export declare const nthEq: (i: number, v: any) => (xs: any[], ...args: unknown[]) => boolean;
|
|
341
|
-
/** Returns a function that checks if nth element does not equal value */
|
|
342
|
-
export declare const nthNe: (i: number, v: any) => (xs: any[], ...args: unknown[]) => boolean;
|
|
343
|
-
/** Returns a function that checks if key/value pairs of x match all pairs in spec */
|
|
344
|
-
export declare const spec: (values: Obj | Array<any>) => (x: Obj | Array<any>, ...args: unknown[]) => boolean;
|
|
345
|
-
/** Returns a function that checks equality with value */
|
|
346
|
-
export declare const eq: <T>(v: T) => (x: T) => boolean;
|
|
347
|
-
/** Returns a function that checks inequality with value */
|
|
348
|
-
export declare const ne: <T>(v: T) => (x: T) => boolean;
|
|
349
|
-
/** Returns a function that gets property value from object */
|
|
350
|
-
export declare const prop: <T>(k: string) => (x: Record<string, unknown>) => T;
|
|
351
|
-
/** Returns a function that adds/updates a property on object */
|
|
352
|
-
export declare const assoc: <K extends string, T, U>(k: K, v: T) => (o: U) => U & Record<K, T>;
|
|
353
|
-
/** Returns a function that removes a property on object */
|
|
354
|
-
export declare const dissoc: <K extends string, T extends Obj>(k: K) => (o: T) => T;
|
|
355
|
-
/** Generates a hash string from input string */
|
|
356
|
-
export declare const hash: (s: string) => string;
|
|
357
|
-
/** Splits array into two parts at index */
|
|
358
|
-
export declare const splitAt: <T>(n: number, xs: T[]) => T[][];
|
|
359
|
-
/** Inserts element into array at index */
|
|
360
|
-
export declare const insert: <T>(n: number, x: T, xs: T[]) => T[];
|
|
361
|
-
/** Returns random element from array */
|
|
362
|
-
export declare const choice: <T>(xs: T[]) => T;
|
|
363
|
-
/** Returns shuffled copy of iterable */
|
|
364
|
-
export declare const shuffle: <T>(xs: Iterable<T>) => T[];
|
|
365
|
-
/** Returns n random elements from array */
|
|
366
|
-
export declare const sample: <T>(n: number, xs: T[]) => T[];
|
|
367
|
-
/** Checks if value is iterable */
|
|
368
|
-
export declare const isIterable: (x: any) => boolean;
|
|
369
|
-
/** Ensures value is iterable by wrapping in array if needed */
|
|
370
|
-
export declare const toIterable: (x: any) => any;
|
|
371
|
-
/** Ensures value is array by wrapping if needed */
|
|
372
|
-
export declare const ensurePlural: <T>(x: T | T[]) => T[];
|
|
373
|
-
/** Converts string or number to number */
|
|
374
|
-
export declare const ensureNumber: (x: number | string) => number;
|
|
375
|
-
/** Returns a function that gets property value from object */
|
|
376
|
-
export declare const pluck: <T>(k: string, xs: Record<string, unknown>[]) => T[];
|
|
377
|
-
/**
|
|
378
|
-
* Creates object from array of key-value pairs
|
|
379
|
-
* @param pairs - Array of [key, value] tuples
|
|
380
|
-
* @returns Object with keys and values from pairs
|
|
381
|
-
*/
|
|
382
|
-
export declare const fromPairs: <T>(pairs: [k?: string, v?: T, ...args: unknown[]][]) => Record<string, T>;
|
|
383
|
-
/**
|
|
384
|
-
* Filters object values based on predicate
|
|
385
|
-
* @param f - Function to test values
|
|
386
|
-
* @param x - Object to filter
|
|
387
|
-
* @returns Object with only values that pass predicate
|
|
388
|
-
*/
|
|
389
|
-
export declare const filterVals: <T extends Record<string, any>>(f: (v: any) => boolean, x: T) => T;
|
|
390
|
-
/**
|
|
391
|
-
* Flattens array of arrays into single array
|
|
392
|
-
* @param xs - Array of arrays to flatten
|
|
393
|
-
* @returns Flattened array
|
|
394
|
-
*/
|
|
395
|
-
export declare const flatten: <T>(xs: T[][]) => T[];
|
|
396
|
-
/**
|
|
397
|
-
* Splits array into two arrays based on predicate
|
|
398
|
-
* @param f - Function to test elements
|
|
399
|
-
* @param xs - Array to partition
|
|
400
|
-
* @returns Tuple of [matching, non-matching] arrays
|
|
401
|
-
*/
|
|
402
|
-
export declare const partition: <T>(f: (x: T) => boolean, xs: T[]) => T[][];
|
|
403
|
-
/**
|
|
404
|
-
* Returns array with duplicate elements removed
|
|
405
|
-
* @param xs - Array with possible duplicates
|
|
406
|
-
* @returns Array with unique elements
|
|
248
|
+
* Returns array with duplicate elements removed
|
|
249
|
+
* @param xs - Array with possible duplicates
|
|
250
|
+
* @returns Array with unique elements
|
|
407
251
|
*/
|
|
408
252
|
export declare const uniq: <T>(xs: T[]) => T[];
|
|
409
253
|
/**
|
|
@@ -461,6 +305,104 @@ export declare const chunk: <T>(chunkLength: number, xs: T[]) => T[][];
|
|
|
461
305
|
* @returns Array of n chunks
|
|
462
306
|
*/
|
|
463
307
|
export declare const chunks: <T>(n: number, xs: T[]) => T[][];
|
|
308
|
+
/** Splits array into two parts at index */
|
|
309
|
+
export declare const splitAt: <T>(n: number, xs: T[]) => T[][];
|
|
310
|
+
/** Inserts element into array at index */
|
|
311
|
+
export declare const insert: <T>(n: number, x: T, xs: T[]) => T[];
|
|
312
|
+
/** Returns random element from array */
|
|
313
|
+
export declare const choice: <T>(xs: T[]) => T;
|
|
314
|
+
/** Returns shuffled copy of iterable */
|
|
315
|
+
export declare const shuffle: <T>(xs: Iterable<T>) => T[];
|
|
316
|
+
/** Returns n random elements from array */
|
|
317
|
+
export declare const sample: <T>(n: number, xs: T[]) => T[];
|
|
318
|
+
/** Checks if value is iterable */
|
|
319
|
+
export declare const isIterable: (x: any) => boolean;
|
|
320
|
+
/** Ensures value is iterable by wrapping in array if needed */
|
|
321
|
+
export declare const toIterable: (x: any) => any;
|
|
322
|
+
/** Ensures value is array by wrapping if needed */
|
|
323
|
+
export declare const ensurePlural: <T>(x: T | T[]) => T[];
|
|
324
|
+
/**
|
|
325
|
+
* Checks if value is a plain object
|
|
326
|
+
* @param obj - Value to check
|
|
327
|
+
* @returns True if value is a plain object
|
|
328
|
+
*/
|
|
329
|
+
export declare const isPojo: (obj: any) => boolean;
|
|
330
|
+
/**
|
|
331
|
+
* Creates new object with only specified keys
|
|
332
|
+
* @param ks - Keys to keep
|
|
333
|
+
* @param x - Source object
|
|
334
|
+
* @returns New object with only specified keys
|
|
335
|
+
*/
|
|
336
|
+
export declare const pick: <T extends Obj>(ks: string[], x: T) => T;
|
|
337
|
+
/**
|
|
338
|
+
* Creates new object with specified keys removed
|
|
339
|
+
* @param ks - Keys to remove
|
|
340
|
+
* @param x - Source object
|
|
341
|
+
* @returns New object without specified keys
|
|
342
|
+
*/
|
|
343
|
+
export declare const omit: <T extends Obj>(ks: string[], x: T) => T;
|
|
344
|
+
/**
|
|
345
|
+
* Creates new object excluding entries with specified values
|
|
346
|
+
* @param xs - Values to exclude
|
|
347
|
+
* @param x - Source object
|
|
348
|
+
* @returns New object without entries containing specified values
|
|
349
|
+
*/
|
|
350
|
+
export declare const omitVals: <T extends Obj>(xs: any[], x: T) => T;
|
|
351
|
+
/**
|
|
352
|
+
* Filters object values based on predicate
|
|
353
|
+
* @param f - Function to test values
|
|
354
|
+
* @param x - Object to filter
|
|
355
|
+
* @returns Object with only values that pass predicate
|
|
356
|
+
*/
|
|
357
|
+
export declare const filterVals: <T extends Record<string, any>>(f: (v: any) => boolean, x: T) => T;
|
|
358
|
+
/**
|
|
359
|
+
* Creates new object with transformed keys
|
|
360
|
+
* @param f - Function to transform keys
|
|
361
|
+
* @param x - Source object
|
|
362
|
+
* @returns Object with transformed keys
|
|
363
|
+
*/
|
|
364
|
+
export declare const mapKeys: <T extends Obj>(f: (v: string) => string, x: T) => T;
|
|
365
|
+
/**
|
|
366
|
+
* Creates new object with transformed values
|
|
367
|
+
* @param f - Function to transform values
|
|
368
|
+
* @param x - Source object
|
|
369
|
+
* @returns Object with transformed values
|
|
370
|
+
*/
|
|
371
|
+
export declare const mapVals: <V, U>(f: (v: V) => U, x: Record<string, V>) => Record<string, U>;
|
|
372
|
+
/**
|
|
373
|
+
* Merges two objects, with left object taking precedence
|
|
374
|
+
* @param a - Left object
|
|
375
|
+
* @param b - Right object
|
|
376
|
+
* @returns Merged object with a"s properties overriding b"s
|
|
377
|
+
*/
|
|
378
|
+
export declare const mergeLeft: <T extends Obj>(a: T, b: T) => T;
|
|
379
|
+
/**
|
|
380
|
+
* Merges two objects, with right object taking precedence
|
|
381
|
+
* @param a - Left object
|
|
382
|
+
* @param b - Right object
|
|
383
|
+
* @returns Merged object with b"s properties overriding a"s
|
|
384
|
+
*/
|
|
385
|
+
export declare const mergeRight: <T extends Obj>(a: T, b: T) => T;
|
|
386
|
+
/** Deep merge two objects, prioritizing the first argument. */
|
|
387
|
+
export declare const deepMergeLeft: (a: Obj, b: Obj) => Obj<any>;
|
|
388
|
+
/** Deep merge two objects, prioritizing the second argument. */
|
|
389
|
+
export declare const deepMergeRight: (a: Obj, b: Obj) => Obj<any>;
|
|
390
|
+
/**
|
|
391
|
+
* Switches on key in object, with default fallback
|
|
392
|
+
* @param k - Key to look up
|
|
393
|
+
* @param m - Object with values and optional default
|
|
394
|
+
* @returns Value at key or default value
|
|
395
|
+
*/
|
|
396
|
+
export declare const switcher: <T>(k: string, m: Record<string, T>) => T;
|
|
397
|
+
/** Returns a function that returns the boolean negation of the given function */
|
|
398
|
+
export declare const complement: <T extends unknown[]>(f: (...args: T) => any) => (...args: T) => boolean;
|
|
399
|
+
/**
|
|
400
|
+
* Safely executes function and handles errors
|
|
401
|
+
* @param f - Function to execute
|
|
402
|
+
* @param onError - Optional error handler
|
|
403
|
+
* @returns Function result or undefined if error
|
|
404
|
+
*/
|
|
405
|
+
export declare const tryCatch: <T>(f: () => T, onError?: (e: Error) => void) => T | undefined;
|
|
464
406
|
/**
|
|
465
407
|
* Creates function that only executes once
|
|
466
408
|
* @param f - Function to wrap
|
|
@@ -479,6 +421,36 @@ export declare const call: <T>(f: () => T, ...args: unknown[]) => T;
|
|
|
479
421
|
* @returns Memoized function
|
|
480
422
|
*/
|
|
481
423
|
export declare const memoize: <T>(f: (...args: any[]) => T) => (...args: any[]) => T;
|
|
424
|
+
/**
|
|
425
|
+
* Executes a function if the value is defined
|
|
426
|
+
* @param x - The value to check
|
|
427
|
+
* @param f - Function to execute if x is defined
|
|
428
|
+
* @returns Result of f(x) if x is defined, undefined otherwise
|
|
429
|
+
*/
|
|
430
|
+
export declare const ifLet: <T>(x: T | undefined, f: (x: T) => void) => void;
|
|
431
|
+
/**
|
|
432
|
+
* Generates random integer between min and max (inclusive)
|
|
433
|
+
* @param min - Minimum value
|
|
434
|
+
* @param max - Maximum value
|
|
435
|
+
* @returns Random integer
|
|
436
|
+
*/
|
|
437
|
+
export declare const randomInt: (min?: number, max?: number) => number;
|
|
438
|
+
/**
|
|
439
|
+
* Generates random string ID
|
|
440
|
+
* @returns Random string suitable for use as an ID
|
|
441
|
+
*/
|
|
442
|
+
export declare const randomId: () => string;
|
|
443
|
+
/**
|
|
444
|
+
* Creates a promise that resolves after specified time
|
|
445
|
+
* @param t - Time in milliseconds
|
|
446
|
+
* @returns Promise that resolves after t milliseconds
|
|
447
|
+
*/
|
|
448
|
+
export declare const sleep: (t: number) => Promise<unknown>;
|
|
449
|
+
/**
|
|
450
|
+
* Creates a microtask that yields to other tasks in the event loop
|
|
451
|
+
* @returns Promise that resolves after yielding
|
|
452
|
+
*/
|
|
453
|
+
export declare const yieldThread: () => any;
|
|
482
454
|
/**
|
|
483
455
|
* Creates throttled version of function
|
|
484
456
|
* @param ms - Minimum time between calls
|
|
@@ -510,89 +482,41 @@ export declare const batch: <T>(t: number, f: (xs: T[]) => void) => (x: T) => vo
|
|
|
510
482
|
*/
|
|
511
483
|
export declare const batcher: <T, U>(t: number, execute: (request: T[]) => U[] | Promise<U[]>) => (request: T) => Promise<U>;
|
|
512
484
|
/**
|
|
513
|
-
*
|
|
514
|
-
* @param
|
|
515
|
-
* @
|
|
516
|
-
* @param v - Value to add
|
|
517
|
-
*/
|
|
518
|
-
export declare const addToKey: <T>(m: Record<string, Set<T>>, k: string, v: T) => void;
|
|
519
|
-
/**
|
|
520
|
-
* Pushes value to array at key in object
|
|
521
|
-
* @param m - Object mapping keys to arrays
|
|
522
|
-
* @param k - Key to push to
|
|
523
|
-
* @param v - Value to push
|
|
524
|
-
*/
|
|
525
|
-
export declare const pushToKey: <T>(m: Record<string, T[]>, k: string, v: T) => void;
|
|
526
|
-
/**
|
|
527
|
-
* Adds value to Set at key in Map
|
|
528
|
-
* @param m - Map of Sets
|
|
529
|
-
* @param k - Key to add to
|
|
530
|
-
* @param v - Value to add
|
|
531
|
-
*/
|
|
532
|
-
export declare const addToMapKey: <K, T>(m: Map<K, Set<T>>, k: K, v: T) => void;
|
|
533
|
-
/**
|
|
534
|
-
* Pushes value to array at key in Map
|
|
535
|
-
* @param m - Map of arrays
|
|
536
|
-
* @param k - Key to push to
|
|
537
|
-
* @param v - Value to push
|
|
485
|
+
* Removes protocol (http://, https://, etc) from URL
|
|
486
|
+
* @param url - URL to process
|
|
487
|
+
* @returns URL without protocol
|
|
538
488
|
*/
|
|
539
|
-
export declare const
|
|
489
|
+
export declare const stripProtocol: (url: string) => string;
|
|
540
490
|
/**
|
|
541
|
-
*
|
|
542
|
-
*
|
|
543
|
-
*
|
|
544
|
-
* @param target - The event target object with add/remove listener methods
|
|
545
|
-
* @param eventName - The name of the event to listen for
|
|
546
|
-
* @param callback - The callback function to execute when the event occurs
|
|
547
|
-
* @returns A function that removes the event listener when called
|
|
491
|
+
* Formats URL for display by removing protocol, www, and trailing slash
|
|
492
|
+
* @param url - URL to format
|
|
493
|
+
* @returns Formatted URL
|
|
548
494
|
*/
|
|
549
|
-
export declare const
|
|
550
|
-
on: (event: EventName, handler: (...args: Args) => any, ...rest: any[]) => any;
|
|
551
|
-
off: (event: EventName, handler: (...args: Args) => any, ...rest: any[]) => any;
|
|
552
|
-
}, eventName: EventName, callback: (...args: Args) => void) => (() => void);
|
|
495
|
+
export declare const displayUrl: (url: string) => string;
|
|
553
496
|
/**
|
|
554
|
-
*
|
|
555
|
-
* @param
|
|
556
|
-
* @
|
|
557
|
-
* @returns Value at key or default value
|
|
497
|
+
* Extracts and formats domain from URL
|
|
498
|
+
* @param url - URL to process
|
|
499
|
+
* @returns Formatted domain name
|
|
558
500
|
*/
|
|
559
|
-
export declare const
|
|
560
|
-
/** One minute in seconds */
|
|
561
|
-
export declare const MINUTE = 60;
|
|
562
|
-
/** One hour in seconds */
|
|
563
|
-
export declare const HOUR: number;
|
|
564
|
-
/** One day in seconds */
|
|
565
|
-
export declare const DAY: number;
|
|
566
|
-
/** One week in seconds */
|
|
567
|
-
export declare const WEEK: number;
|
|
568
|
-
/** One month in seconds (approximate) */
|
|
569
|
-
export declare const MONTH: number;
|
|
570
|
-
/** One quarter in seconds (approximate) */
|
|
571
|
-
export declare const QUARTER: number;
|
|
572
|
-
/** One year in seconds (approximate) */
|
|
573
|
-
export declare const YEAR: number;
|
|
501
|
+
export declare const displayDomain: (url: string) => string;
|
|
574
502
|
/**
|
|
575
|
-
*
|
|
576
|
-
* @param
|
|
577
|
-
* @
|
|
578
|
-
* @returns Total seconds
|
|
503
|
+
* Safely parses JSON string
|
|
504
|
+
* @param json - JSON string to parse
|
|
505
|
+
* @returns Parsed object or null if invalid
|
|
579
506
|
*/
|
|
580
|
-
export declare const
|
|
581
|
-
/** Returns current Unix timestamp in seconds */
|
|
582
|
-
export declare const now: () => number;
|
|
507
|
+
export declare const parseJson: (json: string | undefined) => any;
|
|
583
508
|
/**
|
|
584
|
-
*
|
|
585
|
-
* @param
|
|
586
|
-
* @
|
|
587
|
-
* @returns Timestamp in seconds
|
|
509
|
+
* Gets and parses JSON from localStorage
|
|
510
|
+
* @param k - Storage key
|
|
511
|
+
* @returns Parsed value or undefined if invalid/missing
|
|
588
512
|
*/
|
|
589
|
-
export declare const
|
|
513
|
+
export declare const getJson: (k: string) => any;
|
|
590
514
|
/**
|
|
591
|
-
*
|
|
592
|
-
* @param
|
|
593
|
-
* @
|
|
515
|
+
* Stringifies and stores value in localStorage
|
|
516
|
+
* @param k - Storage key
|
|
517
|
+
* @param v - Value to store
|
|
594
518
|
*/
|
|
595
|
-
export declare const
|
|
519
|
+
export declare const setJson: (k: string, v: any) => void;
|
|
596
520
|
/** Options for fetch requests */
|
|
597
521
|
type FetchOpts = {
|
|
598
522
|
method?: string;
|
|
@@ -621,6 +545,74 @@ export declare const postJson: <T>(url: string, data: T, opts?: FetchOpts) => Pr
|
|
|
621
545
|
* @returns Promise of parsed JSON response
|
|
622
546
|
*/
|
|
623
547
|
export declare const uploadFile: (url: string, file: File) => Promise<any>;
|
|
548
|
+
/**
|
|
549
|
+
* A generic type-safe event listener function that works with event emitters.
|
|
550
|
+
*
|
|
551
|
+
* @param target - The event target object with add/remove listener methods
|
|
552
|
+
* @param eventName - The name of the event to listen for
|
|
553
|
+
* @param callback - The callback function to execute when the event occurs
|
|
554
|
+
* @returns A function that removes the event listener when called
|
|
555
|
+
*/
|
|
556
|
+
export declare const on: <EventMap extends Record<string | symbol, any[]>, E extends keyof EventMap>(target: {
|
|
557
|
+
on(event: E, listener: (...args: EventMap[E]) => any): any;
|
|
558
|
+
off(event: E, listener: (...args: EventMap[E]) => any): any;
|
|
559
|
+
}, eventName: E, callback: (...args: EventMap[E]) => void) => (() => void);
|
|
560
|
+
/**
|
|
561
|
+
* Truncates string to length, breaking at word boundaries
|
|
562
|
+
* @param s - String to truncate
|
|
563
|
+
* @param l - Maximum length
|
|
564
|
+
* @param suffix - String to append if truncated
|
|
565
|
+
* @returns Truncated string
|
|
566
|
+
*/
|
|
567
|
+
export declare const ellipsize: (s: string, l: number, suffix?: string) => string;
|
|
568
|
+
/** Generates a hash string from input string */
|
|
569
|
+
export declare const hash: (s: string) => string;
|
|
570
|
+
/** Returns a function that gets the nth element of an array */
|
|
571
|
+
export declare const nth: (i: number) => <T>(xs: T[], ...args: unknown[]) => T;
|
|
572
|
+
/** Returns a function that checks if nth element equals value */
|
|
573
|
+
export declare const nthEq: (i: number, v: any) => (xs: any[], ...args: unknown[]) => boolean;
|
|
574
|
+
/** Returns a function that checks if nth element does not equal value */
|
|
575
|
+
export declare const nthNe: (i: number, v: any) => (xs: any[], ...args: unknown[]) => boolean;
|
|
576
|
+
/** Returns a function that checks if key/value pairs of x match all pairs in spec */
|
|
577
|
+
export declare const spec: (values: Obj | Array<any>) => (x: Obj | Array<any>, ...args: unknown[]) => boolean;
|
|
578
|
+
/** Returns a function that checks equality with value */
|
|
579
|
+
export declare const eq: <T>(v: T) => (x: T) => boolean;
|
|
580
|
+
/** Returns a function that checks inequality with value */
|
|
581
|
+
export declare const ne: <T>(v: T) => (x: T) => boolean;
|
|
582
|
+
/** Returns a function that gets property value from object */
|
|
583
|
+
export declare const prop: <T>(k: string) => (x: Record<string, unknown>) => T;
|
|
584
|
+
/** Returns a function that adds/updates a property on object */
|
|
585
|
+
export declare const assoc: <K extends string, T, U>(k: K, v: T) => (o: U) => U & Record<K, T>;
|
|
586
|
+
/** Returns a function that removes a property on object */
|
|
587
|
+
export declare const dissoc: <K extends string, T extends Obj>(k: K) => (o: T) => T;
|
|
588
|
+
/**
|
|
589
|
+
* Adds value to Set at key in object
|
|
590
|
+
* @param m - Object mapping keys to Sets
|
|
591
|
+
* @param k - Key to add to
|
|
592
|
+
* @param v - Value to add
|
|
593
|
+
*/
|
|
594
|
+
export declare const addToKey: <T>(m: Record<string, Set<T>>, k: string, v: T) => void;
|
|
595
|
+
/**
|
|
596
|
+
* Pushes value to array at key in object
|
|
597
|
+
* @param m - Object mapping keys to arrays
|
|
598
|
+
* @param k - Key to push to
|
|
599
|
+
* @param v - Value to push
|
|
600
|
+
*/
|
|
601
|
+
export declare const pushToKey: <T>(m: Record<string, T[]>, k: string, v: T) => void;
|
|
602
|
+
/**
|
|
603
|
+
* Adds value to Set at key in Map
|
|
604
|
+
* @param m - Map of Sets
|
|
605
|
+
* @param k - Key to add to
|
|
606
|
+
* @param v - Value to add
|
|
607
|
+
*/
|
|
608
|
+
export declare const addToMapKey: <K, T>(m: Map<K, Set<T>>, k: K, v: T) => void;
|
|
609
|
+
/**
|
|
610
|
+
* Pushes value to array at key in Map
|
|
611
|
+
* @param m - Map of arrays
|
|
612
|
+
* @param k - Key to push to
|
|
613
|
+
* @param v - Value to push
|
|
614
|
+
*/
|
|
615
|
+
export declare const pushToMapKey: <K, T>(m: Map<K, T[]>, k: K, v: T) => void;
|
|
624
616
|
/**
|
|
625
617
|
* Converts hex string to bech32 format
|
|
626
618
|
* @param prefix - Bech32 prefix
|
|
@@ -635,3 +627,4 @@ export declare const hexToBech32: (prefix: string, hex: string) => `${Lowercase<
|
|
|
635
627
|
*/
|
|
636
628
|
export declare const bech32ToHex: (b32: string) => string;
|
|
637
629
|
export {};
|
|
630
|
+
//# sourceMappingURL=Tools.d.ts.map
|