@welshman/util 0.1.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/LICENSE +21 -0
  2. package/dist/lib/src/Deferred.d.ts +21 -0
  3. package/dist/lib/src/Deferred.d.ts.map +1 -0
  4. package/dist/lib/src/Deferred.js +21 -0
  5. package/dist/lib/src/Deferred.js.map +1 -0
  6. package/dist/lib/src/Emitter.d.ts +14 -0
  7. package/dist/lib/src/Emitter.d.ts.map +1 -0
  8. package/dist/lib/src/Emitter.js +18 -0
  9. package/dist/lib/src/Emitter.js.map +1 -0
  10. package/dist/lib/src/LRUCache.d.ts +42 -0
  11. package/dist/lib/src/LRUCache.d.ts.map +1 -0
  12. package/dist/lib/src/LRUCache.js +62 -0
  13. package/dist/lib/src/LRUCache.js.map +1 -0
  14. package/dist/lib/src/TaskQueue.d.ts +20 -0
  15. package/dist/lib/src/TaskQueue.d.ts.map +1 -0
  16. package/dist/lib/src/TaskQueue.js +57 -0
  17. package/dist/lib/src/TaskQueue.js.map +1 -0
  18. package/dist/lib/src/Tools.d.ts +727 -0
  19. package/dist/lib/src/Tools.d.ts.map +1 -0
  20. package/dist/lib/src/Tools.js +1224 -0
  21. package/dist/lib/src/Tools.js.map +1 -0
  22. package/dist/lib/src/index.d.ts +7 -0
  23. package/dist/lib/src/index.d.ts.map +1 -0
  24. package/dist/lib/src/index.js +7 -0
  25. package/dist/lib/src/index.js.map +1 -0
  26. package/dist/lib/src/normalize-url/index.d.ts +286 -0
  27. package/dist/lib/src/normalize-url/index.d.ts.map +1 -0
  28. package/dist/lib/src/normalize-url/index.js +252 -0
  29. package/dist/lib/src/normalize-url/index.js.map +1 -0
  30. package/dist/tsconfig.build.tsbuildinfo +1 -0
  31. package/{build → dist/util}/src/Address.d.ts +1 -0
  32. package/dist/util/src/Address.d.ts.map +1 -0
  33. package/dist/util/src/Address.js.map +1 -0
  34. package/{build → dist/util}/src/Encryptable.d.ts +1 -0
  35. package/dist/util/src/Encryptable.d.ts.map +1 -0
  36. package/dist/util/src/Encryptable.js.map +1 -0
  37. package/{build → dist/util}/src/Events.d.ts +5 -4
  38. package/dist/util/src/Events.d.ts.map +1 -0
  39. package/{build → dist/util}/src/Events.js +5 -4
  40. package/dist/util/src/Events.js.map +1 -0
  41. package/{build → dist/util}/src/Filters.d.ts +1 -0
  42. package/dist/util/src/Filters.d.ts.map +1 -0
  43. package/dist/util/src/Filters.js.map +1 -0
  44. package/{build → dist/util}/src/Handler.d.ts +2 -1
  45. package/dist/util/src/Handler.d.ts.map +1 -0
  46. package/dist/util/src/Handler.js.map +1 -0
  47. package/{build → dist/util}/src/Kinds.d.ts +1 -0
  48. package/dist/util/src/Kinds.d.ts.map +1 -0
  49. package/dist/util/src/Kinds.js.map +1 -0
  50. package/{build → dist/util}/src/Links.d.ts +1 -0
  51. package/dist/util/src/Links.d.ts.map +1 -0
  52. package/dist/util/src/Links.js.map +1 -0
  53. package/{build → dist/util}/src/List.d.ts +3 -0
  54. package/dist/util/src/List.d.ts.map +1 -0
  55. package/{build → dist/util}/src/List.js +10 -3
  56. package/dist/util/src/List.js.map +1 -0
  57. package/{build → dist/util}/src/Profile.d.ts +4 -10
  58. package/dist/util/src/Profile.d.ts.map +1 -0
  59. package/{build → dist/util}/src/Profile.js +1 -0
  60. package/dist/util/src/Profile.js.map +1 -0
  61. package/{build → dist/util}/src/Relay.d.ts +7 -0
  62. package/dist/util/src/Relay.d.ts.map +1 -0
  63. package/{build → dist/util}/src/Relay.js +9 -2
  64. package/dist/util/src/Relay.js.map +1 -0
  65. package/{build → dist/util}/src/Tags.d.ts +1 -0
  66. package/dist/util/src/Tags.d.ts.map +1 -0
  67. package/dist/util/src/Tags.js.map +1 -0
  68. package/{build → dist/util}/src/Zaps.d.ts +1 -0
  69. package/dist/util/src/Zaps.d.ts.map +1 -0
  70. package/dist/util/src/Zaps.js.map +1 -0
  71. package/{build → dist/util}/src/index.d.ts +1 -0
  72. package/dist/util/src/index.d.ts.map +1 -0
  73. package/dist/util/src/index.js.map +1 -0
  74. package/package.json +16 -22
  75. package/README.md +0 -15
  76. package/build/src/Address.js.map +0 -1
  77. package/build/src/Encryptable.js.map +0 -1
  78. package/build/src/Events.js.map +0 -1
  79. package/build/src/Filters.js.map +0 -1
  80. package/build/src/Handler.js.map +0 -1
  81. package/build/src/Kinds.js.map +0 -1
  82. package/build/src/Links.js.map +0 -1
  83. package/build/src/List.js.map +0 -1
  84. package/build/src/Profile.js.map +0 -1
  85. package/build/src/Relay.js.map +0 -1
  86. package/build/src/Tags.js.map +0 -1
  87. package/build/src/Zaps.js.map +0 -1
  88. package/build/src/index.js.map +0 -1
  89. package/build/tsconfig.tsbuildinfo +0 -1
  90. /package/{build → dist/util}/src/Address.js +0 -0
  91. /package/{build → dist/util}/src/Encryptable.js +0 -0
  92. /package/{build → dist/util}/src/Filters.js +0 -0
  93. /package/{build → dist/util}/src/Handler.js +0 -0
  94. /package/{build → dist/util}/src/Kinds.js +0 -0
  95. /package/{build → dist/util}/src/Links.js +0 -0
  96. /package/{build → dist/util}/src/Tags.js +0 -0
  97. /package/{build → dist/util}/src/Zaps.js +0 -0
  98. /package/{build → dist/util}/src/index.js +0 -0
@@ -0,0 +1,727 @@
1
+ type Obj<T = any> = Record<string, T>;
2
+ export type Nil = null | undefined;
3
+ export declare const isNil: <T>(x: T, ...args: unknown[]) => boolean;
4
+ export declare const isNotNil: <T>(x: T, ...args: unknown[]) => x is T & {};
5
+ export declare const assertNotNil: <T>(x: T, ...args: unknown[]) => NonNullable<T>;
6
+ /** Function that does nothing and returns undefined */
7
+ export declare const noop: (...args: unknown[]) => undefined;
8
+ /**
9
+ * Returns the input value unchanged
10
+ * @param x - Any value
11
+ * @returns The same value
12
+ */
13
+ export declare const identity: <T>(x: T, ...args: unknown[]) => T;
14
+ /**
15
+ * Creates a function that always returns the same value
16
+ * @param x - Value to return
17
+ * @returns Function that returns x
18
+ */
19
+ export declare const always: <T>(x: T, ...args: unknown[]) => () => T;
20
+ /**
21
+ * Returns the logical NOT of a value
22
+ * @param x - Value to negate
23
+ * @returns !x
24
+ */
25
+ export declare const not: (x: any, ...args: unknown[]) => boolean;
26
+ /**
27
+ * Deep equality comparison
28
+ * @param a - First value
29
+ * @param b - Second value
30
+ * @returns True if values are deeply equal
31
+ */
32
+ export declare const equals: (a: any, b: any) => boolean;
33
+ /** Converts string or number to number */
34
+ export declare const ensureNumber: (x: number | string) => number;
35
+ /** Converts a `number | undefined` to a number, defaulting to 0 */
36
+ export declare const num: (x: number | undefined) => number;
37
+ /** Adds two numbers, handling undefined values */
38
+ export declare const add: (x: number | undefined, y: number | undefined) => number;
39
+ /** Subtracts two numbers, handling undefined values */
40
+ export declare const sub: (x: number | undefined, y: number | undefined) => number;
41
+ /** Multiplies two numbers, handling undefined values */
42
+ export declare const mul: (x: number | undefined, y: number | undefined) => number;
43
+ /** Divides two numbers, handling undefined values */
44
+ export declare const div: (x: number | undefined, y: number) => number;
45
+ /** Increments a number by 1, handling undefined values */
46
+ export declare const inc: (x: number | undefined) => number;
47
+ /** Decrements a number by 1, handling undefined values */
48
+ export declare const dec: (x: number | undefined) => number;
49
+ /** Less than comparison, handling undefined values */
50
+ export declare const lt: (x: number | undefined, y: number | undefined) => boolean;
51
+ /** Less than or equal comparison, handling undefined values */
52
+ export declare const lte: (x: number | undefined, y: number | undefined) => boolean;
53
+ /** Greater than comparison, handling undefined values */
54
+ export declare const gt: (x: number | undefined, y: number | undefined) => boolean;
55
+ /** Greater than or equal comparison, handling undefined values */
56
+ export declare const gte: (x: number | undefined, y: number | undefined) => boolean;
57
+ /** Returns maximum value in array, handling undefined values */
58
+ export declare const max: (xs: (number | undefined)[]) => number;
59
+ /** Returns minimum value in array, handling undefined values */
60
+ export declare const min: (xs: (number | undefined)[]) => number;
61
+ /** Returns sum of array values, handling undefined values */
62
+ export declare const sum: (xs: (number | undefined)[]) => number;
63
+ /** Returns average of array values, handling undefined values */
64
+ export declare const avg: (xs: (number | undefined)[]) => number;
65
+ /**
66
+ * Checks if a number is between two values (exclusive)
67
+ * @param bounds - Lower and upper bounds
68
+ * @param n - Number to check
69
+ * @returns True if n is between low and high
70
+ */
71
+ export declare const between: ([low, high]: [number, number], n: number) => boolean;
72
+ /**
73
+ * Checks if a number is between two values (inclusive)
74
+ * @param bounds - Lower and upper bounds
75
+ * @param n - Number to check
76
+ * @returns True if n is between low and high
77
+ */
78
+ export declare const within: ([low, high]: [number, number], n: number) => boolean;
79
+ /**
80
+ * Constrains number between min and max values
81
+ * @param bounds - Minimum and maximum allowed values
82
+ * @param n - Number to clamp
83
+ * @returns Clamped value
84
+ */
85
+ export declare const clamp: ([min, max]: [number, number], n: number) => number;
86
+ /**
87
+ * Round a number to the nearest float precision
88
+ * @param precision - Number of decimal places
89
+ * @param x - Number to round
90
+ * @returns Formatted number
91
+ */
92
+ export declare const round: (precision: number, x: number) => number;
93
+ /** One minute in seconds */
94
+ export declare const MINUTE = 60;
95
+ /** One hour in seconds */
96
+ export declare const HOUR: number;
97
+ /** One day in seconds */
98
+ export declare const DAY: number;
99
+ /** One week in seconds */
100
+ export declare const WEEK: number;
101
+ /** One month in seconds (approximate) */
102
+ export declare const MONTH: number;
103
+ /** One quarter in seconds (approximate) */
104
+ export declare const QUARTER: number;
105
+ /** One year in seconds (approximate) */
106
+ export declare const YEAR: number;
107
+ /** User's default locale */
108
+ export declare const LOCALE: string;
109
+ /** User's default timezone */
110
+ export declare const TIMEZONE: string;
111
+ /**
112
+ * Multiplies time unit by count
113
+ * @param unit - Time unit in seconds
114
+ * @param count - Number of units
115
+ * @returns Total seconds
116
+ */
117
+ export declare const int: (unit: number, count?: number) => number;
118
+ /** Returns current Unix timestamp in seconds */
119
+ export declare const now: () => number;
120
+ /**
121
+ * Returns Unix timestamp from specified time ago
122
+ * @param unit - Time unit in seconds
123
+ * @param count - Number of units
124
+ * @returns Timestamp in seconds
125
+ */
126
+ export declare const ago: (unit: number, count?: number) => number;
127
+ /**
128
+ * Converts seconds to milliseconds
129
+ * @param seconds - Time in seconds
130
+ * @returns Time in milliseconds
131
+ */
132
+ export declare const ms: (seconds: number) => number;
133
+ /**
134
+ * Converts seconds to date
135
+ * @param seconds - Time in seconds
136
+ * @returns Date object
137
+ */
138
+ export declare const secondsToDate: (seconds: number) => Date;
139
+ /**
140
+ * Converts date object to seconds
141
+ * @param date - Date object
142
+ * @returns timestamp in seconds
143
+ */
144
+ export declare const dateToSeconds: (date: Date) => number;
145
+ /**
146
+ * Creates a local date from a date string
147
+ * @param dateString - date string
148
+ * @param timezone - timezone string
149
+ * @returns timezone-aware Date object
150
+ */
151
+ export declare const createLocalDate: (dateString: any, timezone?: string) => Date;
152
+ /** Formatter for date+time */
153
+ export declare const dateTimeFormatter: Intl.DateTimeFormat;
154
+ /**
155
+ * Formats seconds as a datetime
156
+ * @param seconds - timestamp in seconds
157
+ * @returns datetime string
158
+ */
159
+ export declare const formatTimestamp: (seconds: number) => string;
160
+ /** Formatter for date */
161
+ export declare const dateFormatter: Intl.DateTimeFormat;
162
+ /**
163
+ * Formats seconds as a date
164
+ * @param seconds - timestamp in seconds
165
+ * @returns date string
166
+ */
167
+ export declare const formatTimestampAsDate: (ts: number) => string;
168
+ /** Formatter for time */
169
+ export declare const timeFormatter: Intl.DateTimeFormat;
170
+ /**
171
+ * Formats seconds as a time
172
+ * @param seconds - timestamp in seconds
173
+ * @returns time string
174
+ */
175
+ export declare const formatTimestampAsTime: (ts: number) => string;
176
+ /**
177
+ * Formats seconds as a relative date (x minutes ago)
178
+ * @param seconds - timestamp in seconds
179
+ * @returns relative date string
180
+ */
181
+ export declare const formatTimestampRelative: (ts: number) => string;
182
+ /**
183
+ * Returns the first element of an array
184
+ * @param xs - The array
185
+ * @returns First element or undefined
186
+ */
187
+ export declare const first: <T>(xs: Iterable<T>, ...args: unknown[]) => T | undefined;
188
+ /**
189
+ * Returns the first element of the first array in a nested array
190
+ * @param xs - Array of arrays
191
+ * @returns First element of first array or undefined
192
+ */
193
+ export declare const ffirst: <T>(xs: Iterable<Iterable<T>>, ...args: unknown[]) => T | undefined;
194
+ /**
195
+ * Returns the last element of an array
196
+ * @param xs - The array
197
+ * @returns Last element or undefined
198
+ */
199
+ export declare const last: <T>(xs: Iterable<T>, ...args: unknown[]) => T;
200
+ /**
201
+ * Returns array with first n elements removed
202
+ * @param n - Number of elements to drop
203
+ * @param xs - Input array
204
+ * @returns Array with first n elements removed
205
+ */
206
+ export declare const drop: <T>(n: number, xs: Iterable<T>) => T[];
207
+ /**
208
+ * Returns first n elements of array
209
+ * @param n - Number of elements to take
210
+ * @param xs - Input array
211
+ * @returns Array of first n elements
212
+ */
213
+ export declare const take: <T>(n: number, xs: Iterable<T>) => T[];
214
+ /**
215
+ * Concatenates multiple arrays, filtering out null/undefined
216
+ * @param xs - Arrays to concatenate
217
+ * @returns Combined array
218
+ */
219
+ export declare const concat: <T>(...xs: T[][]) => T[];
220
+ /**
221
+ * Appends element to array
222
+ * @param x - Element to append
223
+ * @param xs - Array to append to
224
+ * @returns New array with element appended
225
+ */
226
+ export declare const append: <T>(x: T, xs: T[]) => T[];
227
+ /**
228
+ * Creates union of two arrays
229
+ * @param a - First array
230
+ * @param b - Second array
231
+ * @returns Array containing unique elements from both arrays
232
+ */
233
+ export declare const union: <T>(a: T[], b: T[]) => T[];
234
+ /**
235
+ * Returns elements common to both arrays
236
+ * @param a - First array
237
+ * @param b - Second array
238
+ * @returns Array of elements present in both inputs
239
+ */
240
+ export declare const intersection: <T>(a: T[], b: T[]) => T[];
241
+ /**
242
+ * Returns elements in first array not present in second
243
+ * @param a - Source array
244
+ * @param b - Array of elements to exclude
245
+ * @returns Array containing elements unique to first array
246
+ */
247
+ export declare const difference: <T>(a: T[], b: T[]) => T[];
248
+ /**
249
+ * Removes all instances of an element from array
250
+ * @param a - Element to remove
251
+ * @param xs - Source array
252
+ * @returns New array with element removed
253
+ */
254
+ export declare const remove: <T>(a: T, xs: T[]) => T[];
255
+ /**
256
+ * Removes element at index
257
+ * @param i - Index to remove
258
+ * @param xs - Source array
259
+ * @returns New array with element removed
260
+ */
261
+ export declare const removeAt: <T>(i: number, xs: T[]) => T[];
262
+ /**
263
+ * Returns elements from second array not present in first
264
+ * @param a - Array of elements to exclude
265
+ * @param b - Source array
266
+ * @returns Filtered array
267
+ */
268
+ export declare const without: <T>(a: T[], b: T[]) => T[];
269
+ /**
270
+ * Toggles presence of element in array
271
+ * @param x - Element to toggle
272
+ * @param xs - Source array
273
+ * @returns New array with element added or removed
274
+ */
275
+ export declare const toggle: <T>(x: T, xs: T[]) => T[];
276
+ /**
277
+ * Generates sequence of numbers from a to b
278
+ * @param a - Start number (inclusive)
279
+ * @param b - End number (exclusive)
280
+ * @param step - Increment between numbers
281
+ * @yields Numbers in sequence
282
+ */
283
+ export declare function range(a: number, b: number, step?: number): Generator<number, void, unknown>;
284
+ /**
285
+ * Yields indexed items
286
+ * @param items - A collection of items
287
+ * @yields tuples of [index, item]
288
+ */
289
+ export declare function enumerate<T>(items: T[]): Generator<[number, T], void, unknown>;
290
+ /** Returns a function that gets property value from object */
291
+ export declare const pluck: <T>(k: string, xs: Record<string, unknown>[]) => T[];
292
+ /**
293
+ * Creates object from array of key-value pairs
294
+ * @param pairs - Array of [key, value] tuples
295
+ * @returns Object with keys and values from pairs
296
+ */
297
+ export declare const fromPairs: <T>(pairs: [k?: string, v?: T, ...args: unknown[]][]) => Record<string, T>;
298
+ /**
299
+ * Flattens array of arrays into single array
300
+ * @param xs - Array of arrays to flatten
301
+ * @returns Flattened array
302
+ */
303
+ export declare const flatten: <T>(xs: T[][]) => T[];
304
+ /**
305
+ * Splits array into two arrays based on predicate
306
+ * @param f - Function to test elements
307
+ * @param xs - Array to partition
308
+ * @returns Tuple of [matching, non-matching] arrays
309
+ */
310
+ export declare const partition: <T>(f: (x: T) => boolean, xs: T[]) => T[][];
311
+ /**
312
+ * Returns array with duplicate elements removed
313
+ * @param xs - Array with possible duplicates
314
+ * @returns Array with unique elements
315
+ */
316
+ export declare const uniq: <T>(xs: T[]) => T[];
317
+ /**
318
+ * Returns array with elements unique by key function
319
+ * @param f - Function to generate key for each element
320
+ * @param xs - Input array
321
+ * @returns Array with elements unique by key
322
+ */
323
+ export declare const uniqBy: <T>(f: (x: T) => any, xs: T[]) => T[];
324
+ /**
325
+ * Returns sorted copy of array
326
+ * @param xs - Array to sort
327
+ * @returns New sorted array
328
+ */
329
+ export declare const sort: <T>(xs: T[]) => T[];
330
+ /**
331
+ * Returns array sorted by key function
332
+ * @param f - Function to generate sort key
333
+ * @param xs - Array to sort
334
+ * @returns Sorted array
335
+ */
336
+ export declare const sortBy: <T>(f: (x: T) => any, xs: T[]) => T[];
337
+ /**
338
+ * Groups array elements by key function
339
+ * @param f - Function to generate group key
340
+ * @param xs - Array to group
341
+ * @returns Map of groups
342
+ */
343
+ export declare const groupBy: <T, K>(f: (x: T) => K, xs: T[]) => Map<K, T[]>;
344
+ /**
345
+ * Counts array elements by key function
346
+ * @param f - Function to generate group key
347
+ * @param xs - Array to count entries
348
+ * @returns Map of counts
349
+ */
350
+ export declare const countBy: <T, K>(f: (x: T) => K, xs: T[]) => Map<K, number>;
351
+ /**
352
+ * Creates map from array using key function
353
+ * @param f - Function to generate key
354
+ * @param xs - Array to index
355
+ * @returns Map of values by key
356
+ */
357
+ export declare const indexBy: <T, K>(f: (x: T) => K, xs: T[]) => Map<K, T>;
358
+ /**
359
+ * Creates array of specified length using generator function
360
+ * @param n - Length of array
361
+ * @param f - Function to generate each element
362
+ * @returns Generated array
363
+ */
364
+ export declare const initArray: <T>(n: number, f: () => T) => T[];
365
+ /**
366
+ * Splits array into chunks of specified length
367
+ * @param chunkLength - Maximum length of each chunk
368
+ * @param xs - Array to split
369
+ * @returns Array of chunks
370
+ */
371
+ export declare const chunk: <T>(chunkLength: number, xs: T[]) => T[][];
372
+ /**
373
+ * Splits array into specified number of chunks
374
+ * @param n - Number of chunks
375
+ * @param xs - Array to split
376
+ * @returns Array of n chunks
377
+ */
378
+ export declare const chunks: <T>(n: number, xs: T[]) => T[][];
379
+ /** Splits array into two parts at index */
380
+ export declare const splitAt: <T>(n: number, xs: T[]) => T[][];
381
+ /** Inserts element into array at index */
382
+ export declare const insertAt: <T>(n: number, x: T, xs: T[]) => T[];
383
+ /** Replaces array element at index */
384
+ export declare const replaceAt: <T>(n: number, x: T, xs: T[]) => T[];
385
+ /** Returns random element from array */
386
+ export declare const choice: <T>(xs: T[]) => T;
387
+ /** Returns shuffled copy of iterable */
388
+ export declare const shuffle: <T>(xs: Iterable<T>) => T[];
389
+ /** Returns n random elements from array */
390
+ export declare const sample: <T>(n: number, xs: T[]) => T[];
391
+ /** Checks if value is iterable */
392
+ export declare const isIterable: (x: any) => boolean;
393
+ /** Ensures value is iterable by wrapping in array if needed */
394
+ export declare const toIterable: (x: any) => any;
395
+ /** Ensures value is array by wrapping if needed */
396
+ export declare const ensurePlural: <T>(x: T | T[]) => T[];
397
+ /** Ensures values are not undefined */
398
+ export declare const removeNil: <T>(xs: T[]) => NonNullable<T & {}>[];
399
+ /**
400
+ * Checks if value is a plain object
401
+ * @param obj - Value to check
402
+ * @returns True if value is a plain object
403
+ */
404
+ export declare const isPojo: (obj: any) => boolean;
405
+ /**
406
+ * Creates new object with only specified keys
407
+ * @param ks - Keys to keep
408
+ * @param x - Source object
409
+ * @returns New object with only specified keys
410
+ */
411
+ export declare const pick: <T extends Obj>(ks: string[], x: T) => T;
412
+ /**
413
+ * Creates new object with specified keys removed
414
+ * @param ks - Keys to remove
415
+ * @param x - Source object
416
+ * @returns New object without specified keys
417
+ */
418
+ export declare const omit: <T extends Obj>(ks: string[], x: T) => T;
419
+ /**
420
+ * Creates new object excluding entries with specified values
421
+ * @param xs - Values to exclude
422
+ * @param x - Source object
423
+ * @returns New object without entries containing specified values
424
+ */
425
+ export declare const omitVals: <T extends Obj>(xs: any[], x: T) => T;
426
+ /**
427
+ * Filters object values based on predicate
428
+ * @param f - Function to test values
429
+ * @param x - Object to filter
430
+ * @returns Object with only values that pass predicate
431
+ */
432
+ export declare const filterVals: <T extends Record<string, any>>(f: (v: any) => boolean, x: T) => T;
433
+ /**
434
+ * Creates new object with transformed keys
435
+ * @param f - Function to transform keys
436
+ * @param x - Source object
437
+ * @returns Object with transformed keys
438
+ */
439
+ export declare const mapKeys: <T extends Obj>(f: (v: string) => string, x: T) => T;
440
+ /**
441
+ * Creates new object with transformed values
442
+ * @param f - Function to transform values
443
+ * @param x - Source object
444
+ * @returns Object with transformed values
445
+ */
446
+ export declare const mapVals: <V, U>(f: (v: V) => U, x: Record<string, V>) => Record<string, U>;
447
+ /**
448
+ * Merges two objects, with left object taking precedence
449
+ * @param a - Left object
450
+ * @param b - Right object
451
+ * @returns Merged object with a"s properties overriding b"s
452
+ */
453
+ export declare const mergeLeft: <T extends Obj>(a: T, b: T) => T;
454
+ /**
455
+ * Merges two objects, with right object taking precedence
456
+ * @param a - Left object
457
+ * @param b - Right object
458
+ * @returns Merged object with b"s properties overriding a"s
459
+ */
460
+ export declare const mergeRight: <T extends Obj>(a: T, b: T) => T;
461
+ /** Deep merge two objects, prioritizing the first argument. */
462
+ export declare const deepMergeLeft: (a: Obj, b: Obj) => Obj<any>;
463
+ /** Deep merge two objects, prioritizing the second argument. */
464
+ export declare const deepMergeRight: (a: Obj, b: Obj) => Obj<any>;
465
+ /**
466
+ * Switches on key in object, with default fallback
467
+ * @param k - Key to look up
468
+ * @param m - Object with values and optional default
469
+ * @returns Value at key or default value
470
+ */
471
+ export declare const switcher: <T>(k: string, m: Record<string, T>) => T;
472
+ /** Returns a function that returns the boolean negation of the given function */
473
+ export declare const complement: <T extends unknown[]>(f: (...args: T) => any) => (...args: T) => boolean;
474
+ /**
475
+ * Safely executes function and handles errors
476
+ * @param f - Function to execute
477
+ * @param onError - Optional error handler
478
+ * @returns Function result or undefined if error
479
+ */
480
+ export declare const tryCatch: <T>(f: () => T, onError?: (e: Error) => void) => T | undefined;
481
+ /**
482
+ * Creates function that only executes once
483
+ * @param f - Function to wrap
484
+ * @returns Function that executes f only on first call
485
+ */
486
+ export declare const once: (f: (...args: any) => void) => (...args: any) => void;
487
+ /**
488
+ * Calls a function
489
+ * @param f - Function to call
490
+ * @returns Whatever f returns
491
+ */
492
+ export declare const call: <T>(f: () => T, ...args: unknown[]) => T;
493
+ /**
494
+ * Memoizes function results based on arguments
495
+ * @param f - Function to memoize
496
+ * @returns Memoized function
497
+ */
498
+ export declare const memoize: <T>(f: (...args: any[]) => T) => (...args: any[]) => T;
499
+ /**
500
+ * Executes a function if the value is defined
501
+ * @param x - The value to check
502
+ * @param f - Function to execute if x is defined
503
+ * @returns Result of f(x) if x is defined, undefined otherwise
504
+ */
505
+ export declare const ifLet: <T>(x: T | undefined, f: (x: T) => void) => void;
506
+ /**
507
+ * Generates random integer between min and max (inclusive)
508
+ * @param min - Minimum value
509
+ * @param max - Maximum value
510
+ * @returns Random integer
511
+ */
512
+ export declare const randomInt: (min?: number, max?: number) => number;
513
+ /**
514
+ * Generates random string ID
515
+ * @returns Random string suitable for use as an ID
516
+ */
517
+ export declare const randomId: () => string;
518
+ /**
519
+ * Creates a promise that resolves after specified time
520
+ * @param t - Time in milliseconds
521
+ * @returns Promise that resolves after t milliseconds
522
+ */
523
+ export declare const sleep: (t: number) => Promise<unknown>;
524
+ export type PollOptions = {
525
+ signal: AbortSignal;
526
+ condition: () => boolean;
527
+ interval?: number;
528
+ };
529
+ /**
530
+ * Creates a promise that resolves after the condition completes or timeout
531
+ * @param options - PollOptions
532
+ * @returns void Promise
533
+ */
534
+ export declare const poll: ({ interval, condition, signal }: PollOptions) => Promise<void>;
535
+ /**
536
+ * Creates a microtask that yields to other tasks in the event loop
537
+ * @returns Promise that resolves after yielding
538
+ */
539
+ export declare const yieldThread: () => any;
540
+ /**
541
+ * Creates throttled version of function
542
+ * @param ms - Minimum time between calls
543
+ * @param f - Function to throttle
544
+ * @returns Throttled function
545
+ */
546
+ export declare const throttle: <F extends (...args: any[]) => any>(ms: number, f: F) => F | ((...thisArgs: Parameters<F>) => void);
547
+ /**
548
+ * Creates throttled function that returns cached value
549
+ * @param ms - Minimum time between updates
550
+ * @param f - Function to throttle
551
+ * @returns Function returning latest value
552
+ */
553
+ export declare const throttleWithValue: <T>(ms: number, f: () => T) => () => T;
554
+ /**
555
+ * Creates batching function that collects items
556
+ * this function does not delay execution, if a series of items is passed in sequence
557
+ * the first item will be processed immediately, and the rest will be batched
558
+ * @param t - Time window for batching
559
+ * @param f - Function to process batch
560
+ * @returns Function that adds items to batch
561
+ */
562
+ export declare const batch: <T>(t: number, f: (xs: T[]) => void) => (x: T) => void;
563
+ /**
564
+ * Creates batching function that returns results
565
+ * @param t - Time window for batching
566
+ * @param execute - Function to process batch
567
+ * @returns Function that returns promise of result
568
+ */
569
+ export declare const batcher: <T, U>(t: number, execute: (request: T[]) => U[] | Promise<U[]>) => (request: T) => Promise<U>;
570
+ /**
571
+ * Returns a promise that resolves after some proportion of promises complete
572
+ * @param threshold - number between 0 and 1 for how many promises to wait for
573
+ * @param promises - array of promises
574
+ * @returns promise
575
+ */
576
+ export declare const race: (threshold: number, promises: Promise<unknown>[]) => Promise<void>;
577
+ /**
578
+ * Removes protocol (http://, https://, etc) from URL
579
+ * @param url - URL to process
580
+ * @returns URL without protocol
581
+ */
582
+ export declare const stripProtocol: (url: string) => string;
583
+ /**
584
+ * Formats URL for display by removing protocol, www, and trailing slash
585
+ * @param url - URL to format
586
+ * @returns Formatted URL
587
+ */
588
+ export declare const displayUrl: (url: string) => string;
589
+ /**
590
+ * Extracts and formats domain from URL
591
+ * @param url - URL to process
592
+ * @returns Formatted domain name
593
+ */
594
+ export declare const displayDomain: (url: string) => string;
595
+ /**
596
+ * Safely parses JSON string
597
+ * @param json - JSON string to parse
598
+ * @returns Parsed object or null if invalid
599
+ */
600
+ export declare const parseJson: (json: string | undefined) => any;
601
+ /**
602
+ * Gets and parses JSON from localStorage
603
+ * @param k - Storage key
604
+ * @returns Parsed value or undefined if invalid/missing
605
+ */
606
+ export declare const getJson: (k: string) => any;
607
+ /**
608
+ * Stringifies and stores value in localStorage
609
+ * @param k - Storage key
610
+ * @param v - Value to store
611
+ */
612
+ export declare const setJson: (k: string, v: any) => void;
613
+ /** Options for fetch requests */
614
+ type FetchOpts = {
615
+ method?: string;
616
+ headers?: Record<string, string | boolean>;
617
+ body?: string | FormData;
618
+ };
619
+ /**
620
+ * Fetches JSON from URL with options
621
+ * @param url - URL to fetch from
622
+ * @param opts - Fetch options
623
+ * @returns Promise of parsed JSON response
624
+ */
625
+ export declare const fetchJson: (url: string, opts?: FetchOpts) => Promise<any>;
626
+ /**
627
+ * Posts JSON data to URL
628
+ * @param url - URL to post to
629
+ * @param data - Data to send
630
+ * @param opts - Additional fetch options
631
+ * @returns Promise of parsed JSON response
632
+ */
633
+ export declare const postJson: <T>(url: string, data: T, opts?: FetchOpts) => Promise<any>;
634
+ /**
635
+ * Uploads file to URL
636
+ * @param url - Upload URL
637
+ * @param file - File to upload
638
+ * @returns Promise of parsed JSON response
639
+ */
640
+ export declare const uploadFile: (url: string, file: File) => Promise<any>;
641
+ /**
642
+ * A generic type-safe event listener function that works with event emitters.
643
+ *
644
+ * @param target - The event target object with add/remove listener methods
645
+ * @param eventName - The name of the event to listen for
646
+ * @param callback - The callback function to execute when the event occurs
647
+ * @returns A function that removes the event listener when called
648
+ */
649
+ export declare const on: <EventMap extends Record<string | symbol, any[]>, E extends keyof EventMap>(target: {
650
+ on(event: E, listener: (...args: EventMap[E]) => any): any;
651
+ off(event: E, listener: (...args: EventMap[E]) => any): any;
652
+ }, eventName: E, callback: (...args: EventMap[E]) => void) => (() => void);
653
+ /**
654
+ * Truncates string to length, breaking at word boundaries
655
+ * @param s - String to truncate
656
+ * @param l - Maximum length
657
+ * @param suffix - String to append if truncated
658
+ * @returns Truncated string
659
+ */
660
+ export declare const ellipsize: (s: string, l: number, suffix?: string) => string;
661
+ /** Displays a list of items with oxford commas and a chosen conjunction */
662
+ export declare const displayList: <T>(xs: T[], conj?: string, n?: number) => string;
663
+ /** Generates a hash string from input string */
664
+ export declare const hash: (s: string) => string;
665
+ /** Returns a function that gets the nth element of an array */
666
+ export declare const nth: (i: number) => <T>(xs: T[], ...args: unknown[]) => T;
667
+ /** Returns a function that checks if nth element equals value */
668
+ export declare const nthEq: (i: number, v: any) => (xs: any[], ...args: unknown[]) => boolean;
669
+ /** Returns a function that checks if nth element does not equal value */
670
+ export declare const nthNe: (i: number, v: any) => (xs: any[], ...args: unknown[]) => boolean;
671
+ /** Returns a function that checks if key/value pairs of x match all pairs in spec */
672
+ export declare const spec: (values: Obj | Array<any>) => (x: Obj | Array<any>, ...args: unknown[]) => boolean;
673
+ /** Returns a function that checks equality with value */
674
+ export declare const eq: <T>(v: T) => (x: T, ...args: unknown[]) => boolean;
675
+ /** Returns a function that checks inequality with value */
676
+ export declare const ne: <T>(v: T) => (x: T, ...args: unknown[]) => boolean;
677
+ /** Returns a function that gets property value from object */
678
+ export declare const prop: <T>(k: string) => (x: Record<string, unknown>) => T;
679
+ /** Returns a function that adds/updates a property on object */
680
+ export declare const assoc: <K extends string, T, U>(k: K, v: T) => (o: U) => U & Record<K, T>;
681
+ /** Returns a function that removes a property on object */
682
+ export declare const dissoc: <K extends string, T extends Obj>(k: K) => (o: T) => T;
683
+ /** Returns a function that checks whether a value is in the given sequence */
684
+ export declare const member: <T>(xs: Iterable<T>) => (x: T) => boolean;
685
+ /**
686
+ * Adds value to Set at key in object
687
+ * @param m - Object mapping keys to Sets
688
+ * @param k - Key to add to
689
+ * @param v - Value to add
690
+ */
691
+ export declare const addToKey: <T>(m: Record<string, Set<T>>, k: string, v: T) => void;
692
+ /**
693
+ * Pushes value to array at key in object
694
+ * @param m - Object mapping keys to arrays
695
+ * @param k - Key to push to
696
+ * @param v - Value to push
697
+ */
698
+ export declare const pushToKey: <T>(m: Record<string, T[]>, k: string, v: T) => void;
699
+ /**
700
+ * Adds value to Set at key in Map
701
+ * @param m - Map of Sets
702
+ * @param k - Key to add to
703
+ * @param v - Value to add
704
+ */
705
+ export declare const addToMapKey: <K, T>(m: Map<K, Set<T>>, k: K, v: T) => void;
706
+ /**
707
+ * Pushes value to array at key in Map
708
+ * @param m - Map of arrays
709
+ * @param k - Key to push to
710
+ * @param v - Value to push
711
+ */
712
+ export declare const pushToMapKey: <K, T>(m: Map<K, T[]>, k: K, v: T) => void;
713
+ /**
714
+ * Converts hex string to bech32 format
715
+ * @param prefix - Bech32 prefix
716
+ * @param hex - Hex string to convert
717
+ * @returns Bech32 encoded string
718
+ */
719
+ export declare const hexToBech32: (prefix: string, hex: string) => `${Lowercase<string>}1${string}`;
720
+ /**
721
+ * Converts bech32 string to hex format
722
+ * @param b32 - Bech32 string to convert
723
+ * @returns Hex encoded string
724
+ */
725
+ export declare const bech32ToHex: (b32: string) => string;
726
+ export {};
727
+ //# sourceMappingURL=Tools.d.ts.map