@welshman/lib 0.1.0 → 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.
Files changed (45) hide show
  1. package/LICENSE +21 -0
  2. package/{build/src → dist}/Deferred.d.ts +1 -0
  3. package/dist/Deferred.d.ts.map +1 -0
  4. package/dist/Deferred.js.map +1 -0
  5. package/{build/src → dist}/Emitter.d.ts +1 -0
  6. package/dist/Emitter.d.ts.map +1 -0
  7. package/dist/Emitter.js.map +1 -0
  8. package/{build/src → dist}/LRUCache.d.ts +1 -0
  9. package/dist/LRUCache.d.ts.map +1 -0
  10. package/dist/LRUCache.js.map +1 -0
  11. package/dist/TaskQueue.d.ts +18 -0
  12. package/dist/TaskQueue.d.ts.map +1 -0
  13. package/dist/TaskQueue.js +47 -0
  14. package/dist/TaskQueue.js.map +1 -0
  15. package/{build/src → dist}/Tools.d.ts +352 -335
  16. package/dist/Tools.d.ts.map +1 -0
  17. package/{build/src → dist}/Tools.js +582 -494
  18. package/dist/Tools.js.map +1 -0
  19. package/{build/src → dist}/index.d.ts +2 -6
  20. package/dist/index.d.ts.map +1 -0
  21. package/{build/src → dist}/index.js +1 -2
  22. package/dist/index.js.map +1 -0
  23. package/dist/normalize-url/index.d.ts +286 -0
  24. package/dist/normalize-url/index.d.ts.map +1 -0
  25. package/{build/src → dist}/normalize-url/index.js +53 -51
  26. package/dist/normalize-url/index.js.map +1 -0
  27. package/package.json +17 -17
  28. package/README.md +0 -13
  29. package/build/src/Context.d.ts +0 -20
  30. package/build/src/Context.js +0 -20
  31. package/build/src/Context.js.map +0 -1
  32. package/build/src/Deferred.js.map +0 -1
  33. package/build/src/Emitter.js.map +0 -1
  34. package/build/src/LRUCache.js.map +0 -1
  35. package/build/src/Tools.js.map +0 -1
  36. package/build/src/Worker.d.ts +0 -55
  37. package/build/src/Worker.js +0 -119
  38. package/build/src/Worker.js.map +0 -1
  39. package/build/src/index.js.map +0 -1
  40. package/build/src/normalize-url/index.d.ts +0 -285
  41. package/build/src/normalize-url/index.js.map +0 -1
  42. package/build/tsconfig.tsbuildinfo +0 -1
  43. /package/{build/src → dist}/Deferred.js +0 -0
  44. /package/{build/src → dist}/Emitter.js +0 -0
  45. /package/{build/src → dist}/LRUCache.js +0 -0
@@ -1,38 +1,6 @@
1
- /** Type representing null or undefined */
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
- /** Returns a function that returns the boolean negation of the given function */
55
- export declare const complement: <T extends unknown[]>(f: (...args: T) => any) => (...args: T) => boolean;
56
- /** Converts a `Maybe<number>` to a number, defaulting to 0 */
57
- export declare const num: (x: Maybe<number>) => number;
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: Maybe<number>, y: Maybe<number>) => number;
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: Maybe<number>, y: Maybe<number>) => number;
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: Maybe<number>, y: Maybe<number>) => number;
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: Maybe<number>, y: number) => number;
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: Maybe<number>) => number;
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: Maybe<number>) => number;
44
+ export declare const dec: (x: number | undefined) => number;
70
45
  /** Less than comparison, handling undefined values */
71
- export declare const lt: (x: Maybe<number>, y: Maybe<number>) => boolean;
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: Maybe<number>, y: Maybe<number>) => boolean;
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: Maybe<number>, y: Maybe<number>) => boolean;
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: Maybe<number>, y: Maybe<number>) => boolean;
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: Maybe<number>[]) => number;
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: Maybe<number>[]) => number;
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: Maybe<number>[]) => number;
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: Maybe<number>[]) => number;
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,41 +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
- * Generates random integer between min and max (inclusive)
183
- * @param min - Minimum value
184
- * @param max - Maximum value
185
- * @returns Random integer
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 randomInt: (min?: number, max?: number) => number;
81
+ export declare const clamp: ([min, max]: [number, number], n: number) => number;
188
82
  /**
189
- * Generates random string ID
190
- * @returns Random string suitable for use as an ID
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 randomId: () => string;
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
- * Removes protocol (http://, https://, etc) from URL
195
- * @param url - URL to process
196
- * @returns URL without protocol
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 stripProtocol: (url: string) => string;
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
- * Formats URL for display by removing protocol, www, and trailing slash
201
- * @param url - URL to format
202
- * @returns Formatted URL
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 displayUrl: (url: string) => string;
118
+ export declare const ago: (unit: number, count?: number) => number;
205
119
  /**
206
- * Extracts and formats domain from URL
207
- * @param url - URL to process
208
- * @returns Formatted domain name
120
+ * Converts seconds to milliseconds
121
+ * @param seconds - Time in seconds
122
+ * @returns Time in milliseconds
209
123
  */
210
- export declare const displayDomain: (url: string) => string;
124
+ export declare const ms: (seconds: number) => number;
211
125
  /**
212
- * Creates a promise that resolves after specified time
213
- * @param t - Time in milliseconds
214
- * @returns Promise that resolves after t milliseconds
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 sleep: (t: number) => Promise<unknown>;
130
+ export declare const first: <T>(xs: Iterable<T>, ...args: unknown[]) => T | undefined;
131
+ /**
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
135
+ */
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[];
217
157
  /**
218
158
  * Concatenates multiple arrays, filtering out null/undefined
219
159
  * @param xs - Arrays to concatenate
@@ -270,137 +210,46 @@ export declare const without: <T>(a: T[], b: T[]) => T[];
270
210
  */
271
211
  export declare const toggle: <T>(x: T, xs: T[]) => T[];
272
212
  /**
273
- * Constrains number between min and max values
274
- * @param bounds - Minimum and maximum allowed values
275
- * @param n - Number to clamp
276
- * @returns Clamped value
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
277
218
  */
278
- export declare const clamp: ([min, max]: [number, number], n: number) => number;
219
+ export declare function range(a: number, b: number, step?: number): Generator<number, void, unknown>;
279
220
  /**
280
- * Round a number to the nearest float precision
281
- * @param precision - Number of decimal places
282
- * @param x - Number to round
283
- * @returns Formatted number
221
+ * Yields indexed items
222
+ * @param items - A collection of items
223
+ * @yields tuples of [index, item]
284
224
  */
285
- export declare const round: (precision: number, x: number) => number;
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[];
286
228
  /**
287
- * Safely parses JSON string
288
- * @param json - JSON string to parse
289
- * @returns Parsed object or null if invalid
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
290
232
  */
291
- export declare const parseJson: (json: string | Nil) => any;
233
+ export declare const fromPairs: <T>(pairs: [k?: string, v?: T, ...args: unknown[]][]) => Record<string, T>;
292
234
  /**
293
- * Gets and parses JSON from localStorage
294
- * @param k - Storage key
295
- * @returns Parsed value or undefined if invalid/missing
235
+ * Flattens array of arrays into single array
236
+ * @param xs - Array of arrays to flatten
237
+ * @returns Flattened array
296
238
  */
297
- export declare const getJson: (k: string) => any;
239
+ export declare const flatten: <T>(xs: T[][]) => T[];
298
240
  /**
299
- * Stringifies and stores value in localStorage
300
- * @param k - Storage key
301
- * @param v - Value to store
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
302
245
  */
303
- export declare const setJson: (k: string, v: any) => void;
246
+ export declare const partition: <T>(f: (x: T) => boolean, xs: T[]) => T[][];
304
247
  /**
305
- * Safely executes function and handles errors
306
- * @param f - Function to execute
307
- * @param onError - Optional error handler
308
- * @returns Function result or undefined if error
248
+ * Returns array with duplicate elements removed
249
+ * @param xs - Array with possible duplicates
250
+ * @returns Array with unique elements
309
251
  */
310
- export declare const tryCatch: <T>(f: () => T, onError?: (e: Error) => void) => T | undefined;
311
- /**
312
- * Truncates string to length, breaking at word boundaries
313
- * @param s - String to truncate
314
- * @param l - Maximum length
315
- * @param suffix - String to append if truncated
316
- * @returns Truncated string
317
- */
318
- export declare const ellipsize: (s: string, l: number, suffix?: string) => string;
319
- /**
320
- * Checks if value is a plain object
321
- * @param obj - Value to check
322
- * @returns True if value is a plain object
323
- */
324
- export declare const isPojo: (obj: any) => boolean;
325
- /**
326
- * Deep equality comparison
327
- * @param a - First value
328
- * @param b - Second value
329
- * @returns True if values are deeply equal
330
- */
331
- export declare const equals: (a: any, b: any) => boolean;
332
- /** Returns a function that gets the nth element of an array */
333
- export declare const nth: (i: number) => <T>(xs: T[], ...args: unknown[]) => T;
334
- /** Returns a function that checks if nth element equals value */
335
- export declare const nthEq: (i: number, v: any) => (xs: any[], ...args: unknown[]) => boolean;
336
- /** Returns a function that checks if nth element does not equal value */
337
- export declare const nthNe: (i: number, v: any) => (xs: any[], ...args: unknown[]) => boolean;
338
- /** Returns a function that checks if key/value pairs of x match all pairs in spec */
339
- export declare const spec: (values: Obj | Array<any>) => (x: Obj | Array<any>, ...args: unknown[]) => boolean;
340
- /** Returns a function that checks equality with value */
341
- export declare const eq: <T>(v: T) => (x: T) => boolean;
342
- /** Returns a function that checks inequality with value */
343
- export declare const ne: <T>(v: T) => (x: T) => boolean;
344
- /** Returns a function that gets property value from object */
345
- export declare const prop: <T>(k: string) => (x: Record<string, unknown>) => T;
346
- /** Returns a function that adds/updates a property on object */
347
- export declare const assoc: <K extends string, T, U>(k: K, v: T) => (o: U) => U & Record<K, T>;
348
- /** Returns a function that removes a property on object */
349
- export declare const dissoc: <K extends string, T extends Obj>(k: K) => (o: T) => T;
350
- /** Generates a hash string from input string */
351
- export declare const hash: (s: string) => string;
352
- /** Splits array into two parts at index */
353
- export declare const splitAt: <T>(n: number, xs: T[]) => T[][];
354
- /** Inserts element into array at index */
355
- export declare const insert: <T>(n: number, x: T, xs: T[]) => T[];
356
- /** Returns random element from array */
357
- export declare const choice: <T>(xs: T[]) => T;
358
- /** Returns shuffled copy of iterable */
359
- export declare const shuffle: <T>(xs: Iterable<T>) => T[];
360
- /** Returns n random elements from array */
361
- export declare const sample: <T>(n: number, xs: T[]) => T[];
362
- /** Checks if value is iterable */
363
- export declare const isIterable: (x: any) => boolean;
364
- /** Ensures value is iterable by wrapping in array if needed */
365
- export declare const toIterable: (x: any) => any;
366
- /** Ensures value is array by wrapping if needed */
367
- export declare const ensurePlural: <T>(x: T | T[]) => T[];
368
- /** Converts string or number to number */
369
- export declare const ensureNumber: (x: number | string) => number;
370
- /** Returns a function that gets property value from object */
371
- export declare const pluck: <T>(k: string, xs: Record<string, unknown>[]) => T[];
372
- /**
373
- * Creates object from array of key-value pairs
374
- * @param pairs - Array of [key, value] tuples
375
- * @returns Object with keys and values from pairs
376
- */
377
- export declare const fromPairs: <T>(pairs: [k?: string, v?: T, ...args: unknown[]][]) => Record<string, T>;
378
- /**
379
- * Filters object values based on predicate
380
- * @param f - Function to test values
381
- * @param x - Object to filter
382
- * @returns Object with only values that pass predicate
383
- */
384
- export declare const filterVals: <T extends Record<string, any>>(f: (v: any) => boolean, x: T) => T;
385
- /**
386
- * Flattens array of arrays into single array
387
- * @param xs - Array of arrays to flatten
388
- * @returns Flattened array
389
- */
390
- export declare const flatten: <T>(xs: T[][]) => T[];
391
- /**
392
- * Splits array into two arrays based on predicate
393
- * @param f - Function to test elements
394
- * @param xs - Array to partition
395
- * @returns Tuple of [matching, non-matching] arrays
396
- */
397
- export declare const partition: <T>(f: (x: T) => boolean, xs: T[]) => T[][];
398
- /**
399
- * Returns array with duplicate elements removed
400
- * @param xs - Array with possible duplicates
401
- * @returns Array with unique elements
402
- */
403
- export declare const uniq: <T>(xs: T[]) => T[];
252
+ export declare const uniq: <T>(xs: T[]) => T[];
404
253
  /**
405
254
  * Returns array with elements unique by key function
406
255
  * @param f - Function to generate key for each element
@@ -456,18 +305,152 @@ export declare const chunk: <T>(chunkLength: number, xs: T[]) => T[][];
456
305
  * @returns Array of n chunks
457
306
  */
458
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;
459
406
  /**
460
407
  * Creates function that only executes once
461
408
  * @param f - Function to wrap
462
409
  * @returns Function that executes f only on first call
463
410
  */
464
411
  export declare const once: (f: (...args: any) => void) => (...args: any) => void;
412
+ /**
413
+ * Calls a function
414
+ * @param f - Function to call
415
+ * @returns Whatever f returns
416
+ */
417
+ export declare const call: <T>(f: () => T, ...args: unknown[]) => T;
465
418
  /**
466
419
  * Memoizes function results based on arguments
467
420
  * @param f - Function to memoize
468
421
  * @returns Memoized function
469
422
  */
470
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;
471
454
  /**
472
455
  * Creates throttled version of function
473
456
  * @param ms - Minimum time between calls
@@ -499,76 +482,41 @@ export declare const batch: <T>(t: number, f: (xs: T[]) => void) => (x: T) => vo
499
482
  */
500
483
  export declare const batcher: <T, U>(t: number, execute: (request: T[]) => U[] | Promise<U[]>) => (request: T) => Promise<U>;
501
484
  /**
502
- * Adds value to Set at key in object
503
- * @param m - Object mapping keys to Sets
504
- * @param k - Key to add to
505
- * @param v - Value to add
506
- */
507
- export declare const addToKey: <T>(m: Record<string, Set<T>>, k: string, v: T) => void;
508
- /**
509
- * Pushes value to array at key in object
510
- * @param m - Object mapping keys to arrays
511
- * @param k - Key to push to
512
- * @param v - Value to push
513
- */
514
- export declare const pushToKey: <T>(m: Record<string, T[]>, k: string, v: T) => void;
515
- /**
516
- * Adds value to Set at key in Map
517
- * @param m - Map of Sets
518
- * @param k - Key to add to
519
- * @param v - Value to add
485
+ * Removes protocol (http://, https://, etc) from URL
486
+ * @param url - URL to process
487
+ * @returns URL without protocol
520
488
  */
521
- export declare const addToMapKey: <K, T>(m: Map<K, Set<T>>, k: K, v: T) => void;
489
+ export declare const stripProtocol: (url: string) => string;
522
490
  /**
523
- * Pushes value to array at key in Map
524
- * @param m - Map of arrays
525
- * @param k - Key to push to
526
- * @param v - Value to push
491
+ * Formats URL for display by removing protocol, www, and trailing slash
492
+ * @param url - URL to format
493
+ * @returns Formatted URL
527
494
  */
528
- export declare const pushToMapKey: <K, T>(m: Map<K, T[]>, k: K, v: T) => void;
495
+ export declare const displayUrl: (url: string) => string;
529
496
  /**
530
- * Switches on key in object, with default fallback
531
- * @param k - Key to look up
532
- * @param m - Object with values and optional default
533
- * @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
534
500
  */
535
- export declare const switcher: <T>(k: string, m: Record<string, T>) => T;
536
- /** One minute in seconds */
537
- export declare const MINUTE = 60;
538
- /** One hour in seconds */
539
- export declare const HOUR: number;
540
- /** One day in seconds */
541
- export declare const DAY: number;
542
- /** One week in seconds */
543
- export declare const WEEK: number;
544
- /** One month in seconds (approximate) */
545
- export declare const MONTH: number;
546
- /** One quarter in seconds (approximate) */
547
- export declare const QUARTER: number;
548
- /** One year in seconds (approximate) */
549
- export declare const YEAR: number;
501
+ export declare const displayDomain: (url: string) => string;
550
502
  /**
551
- * Multiplies time unit by count
552
- * @param unit - Time unit in seconds
553
- * @param count - Number of units
554
- * @returns Total seconds
503
+ * Safely parses JSON string
504
+ * @param json - JSON string to parse
505
+ * @returns Parsed object or null if invalid
555
506
  */
556
- export declare const int: (unit: number, count?: number) => number;
557
- /** Returns current Unix timestamp in seconds */
558
- export declare const now: () => number;
507
+ export declare const parseJson: (json: string | undefined) => any;
559
508
  /**
560
- * Returns Unix timestamp from specified time ago
561
- * @param unit - Time unit in seconds
562
- * @param count - Number of units
563
- * @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
564
512
  */
565
- export declare const ago: (unit: number, count?: number) => number;
513
+ export declare const getJson: (k: string) => any;
566
514
  /**
567
- * Converts seconds to milliseconds
568
- * @param seconds - Time in seconds
569
- * @returns Time in milliseconds
515
+ * Stringifies and stores value in localStorage
516
+ * @param k - Storage key
517
+ * @param v - Value to store
570
518
  */
571
- export declare const ms: (seconds: number) => number;
519
+ export declare const setJson: (k: string, v: any) => void;
572
520
  /** Options for fetch requests */
573
521
  type FetchOpts = {
574
522
  method?: string;
@@ -597,6 +545,74 @@ export declare const postJson: <T>(url: string, data: T, opts?: FetchOpts) => Pr
597
545
  * @returns Promise of parsed JSON response
598
546
  */
599
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;
600
616
  /**
601
617
  * Converts hex string to bech32 format
602
618
  * @param prefix - Bech32 prefix
@@ -611,3 +627,4 @@ export declare const hexToBech32: (prefix: string, hex: string) => `${Lowercase<
611
627
  */
612
628
  export declare const bech32ToHex: (b32: string) => string;
613
629
  export {};
630
+ //# sourceMappingURL=Tools.d.ts.map