@hairy/utils 1.47.0 → 1.50.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.
@@ -0,0 +1,823 @@
1
+ import _Bignumber from "bignumber.js";
2
+ import { chunk, clone, cloneDeep, cloneDeepWith, cloneWith, concat, debounce, find, get, groupBy, isArguments, isArray, isArrayBuffer, isArrayLike, isArrayLikeObject, isBoolean, isBuffer, isDate, isElement, isEmpty, isEqual, isEqualWith, isError, isFunction, isInteger, isMap, isMatch, isMatchWith, isNaN, isNative, isNull, isNumber, isObject, isObjectLike, isPlainObject, isRegExp as isRegexp, isSet, isString, isSymbol, isUndefined, isWeakMap, isWeakSet, join, keyBy, keys, max, maxBy, merge, mergeWith, min, minBy, omit, omitBy, once, pick, pickBy, range, set, truncate, uniq, uniqBy, uniqWith, values } from "lodash-es";
3
+
4
+ //#region src/browser/file.d.ts
5
+ interface OpenFilePickerOptions {
6
+ /**
7
+ * select multiple files
8
+ */
9
+ multiple?: boolean;
10
+ /**
11
+ * Choose the default format for the file
12
+ */
13
+ accept?: string;
14
+ }
15
+ /**
16
+ * Select multiple files
17
+ */
18
+ declare function openFilePicker(option?: OpenFilePickerOptions): Promise<File[]>;
19
+ /** @deprecated use openFilePicker */
20
+ declare const showOpenFilePicker: typeof openFilePicker;
21
+ interface OpenImagePickerOptions {
22
+ /**
23
+ * select multiple images
24
+ */
25
+ multiple?: boolean;
26
+ }
27
+ /**
28
+ * Select multiple images
29
+ */
30
+ declare function openImagePicker(options?: OpenImagePickerOptions): Promise<File[]>;
31
+ /** @deprecated use openImagePicker */
32
+ declare const selectImages: typeof openImagePicker;
33
+ declare const showOpenImagePicker: typeof openImagePicker;
34
+ /**
35
+ * Generate Blob | string file and download it
36
+ * @param data Blob data, or string
37
+ * @param name file name
38
+ */
39
+ declare function downloadBlobFile(data: Blob | string, name: string): void;
40
+ /**
41
+ * Download network files
42
+ * @param url Download link
43
+ * @param name file name
44
+ */
45
+ declare function downloadUrlFile(url: string, name?: string): void;
46
+ /** @deprecated use downloadUrlFile */
47
+ declare const downloadNetworkFile: typeof downloadUrlFile;
48
+ type ReaderType = 'readAsArrayBuffer' | 'readAsBinaryString' | 'readAsDataURL' | 'readAsText';
49
+ /**
50
+ * Read File file
51
+ * @param formType Transform type
52
+ * @param file file object
53
+ */
54
+ declare function readFileReader<T extends ReaderType>(formType: T, file: File): Promise<T extends "readAsArrayBuffer" ? ArrayBuffer : string>;
55
+ //#endregion
56
+ //#region src/typings/atom.d.ts
57
+ type Numeric = string | number | bigint;
58
+ type Numberish = Numeric | {
59
+ toString: (...args: any[]) => string;
60
+ } | undefined | null;
61
+ interface DynamicObject {
62
+ [key: string]: any;
63
+ }
64
+ interface NumericObject {
65
+ [key: string]: Numeric;
66
+ }
67
+ interface StringObject {
68
+ [key: string]: string;
69
+ }
70
+ interface NumberObject {
71
+ [key: string]: string;
72
+ }
73
+ interface SymbolObject {
74
+ [key: string]: symbol;
75
+ }
76
+ type Key = string | number | symbol;
77
+ type BooleanLike = any;
78
+ type Noop = (...args: any[]) => any;
79
+ //#endregion
80
+ //#region src/typings/util.d.ts
81
+ /**
82
+ * Any type that can be used where a big number is needed.
83
+ */
84
+ type Awaitable<T> = T | PromiseLike<T>;
85
+ type Arrayable<T> = T | T[];
86
+ type Promisify<T> = Promise<Awaited<T>>;
87
+ type ElementOf<T> = T extends (infer E)[] ? E : never;
88
+ type Nullable<T> = T | null | undefined;
89
+ type Fn<T = void> = () => T;
90
+ type AnyFn = (...args: any[]) => any;
91
+ type PromiseFn = (...args: any[]) => Promise<any>;
92
+ type IfAny<T, Y, N> = 0 extends 1 & T ? Y : N;
93
+ type IsAny<T> = IfAny<T, true, false>;
94
+ type ConstructorType<T = void> = new (...args: any[]) => T;
95
+ type ArgumentsType<T> = T extends ((...args: infer A) => any) ? A : never;
96
+ type PromiseType<P extends PromiseLike<any>> = P extends PromiseLike<infer T> ? T : never;
97
+ type BrowserNativeObject = Date | FileList | File;
98
+ type Option<L extends Key = 'label', V extends Key = 'value', C extends Key = 'children'> = { [P in L]?: string } & { [P in V]?: Numeric } & { [P in C]?: Option<L, V, C>[] };
99
+ type OmitBy<T, V> = { [K in keyof T as T[K] extends V ? never : K]: T[K] };
100
+ type PickBy<T, U> = { [K in keyof T as T[K] extends U ? K : never]: T[K] };
101
+ type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;
102
+ type Assign<T, U> = Omit<T, keyof U> & U;
103
+ type NonUndefined<T> = T extends undefined ? never : T;
104
+ //#endregion
105
+ //#region src/typings/deep.d.ts
106
+ type DeepReadonly<T> = { readonly [P in keyof T]: T[P] extends object ? DeepReadonly<T[P]> : T[P] };
107
+ type DeepRequired<T> = { [P in keyof T]-?: T[P] extends object ? DeepRequired<T[P]> : T[P] };
108
+ type DeepPartial<T> = { [P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P] };
109
+ type DeepReplace<T, K = unknown, V = unknown> = { [P in keyof T]: K extends P ? V : DeepReplace<T[P], K, V> };
110
+ type DeepKeyof<T> = T extends object ? keyof T | DeepKeyof<T[keyof T]> : never;
111
+ type MergeInsertions<T> = T extends object ? { [K in keyof T]: MergeInsertions<T[K]> } : T;
112
+ type DeepMerge<F, S> = MergeInsertions<{ [K in keyof F | keyof S]: K extends keyof S & keyof F ? DeepMerge<F[K], S[K]> : K extends keyof S ? S[K] : K extends keyof F ? F[K] : never }>;
113
+ type DeepMap<T, V, ST = BrowserNativeObject> = IsAny<T> extends true ? any : T extends ST ? V : T extends object ? { [K in keyof T]: DeepMap<NonUndefined<T[K]>, V, ST> } : V;
114
+ //#endregion
115
+ //#region src/browser/util.d.ts
116
+ declare function redirectTo(url: string, target?: string): void;
117
+ declare function dialsPhone(phoneNumber: string): void;
118
+ declare function on<T extends Window | Document | HTMLElement | EventTarget>(obj: T | null, ...args: Parameters<T['addEventListener']> | [string, Fn | null, ...any]): void;
119
+ declare function off<T extends Window | Document | HTMLElement | EventTarget>(obj: T | null, ...args: Parameters<T['removeEventListener']> | [string, Fn | null, ...any]): void;
120
+ //#endregion
121
+ //#region src/is/index.d.ts
122
+ declare const isBrowser: () => boolean;
123
+ declare const isWeex: () => boolean;
124
+ declare const isIE: () => boolean | "";
125
+ declare const isIE9: () => boolean | "";
126
+ declare const isIE11: () => boolean;
127
+ declare const isEdge: () => boolean | "";
128
+ declare const isAndroid: () => boolean;
129
+ declare const isIOS: () => boolean;
130
+ declare const isChrome: () => boolean | "";
131
+ declare const isPhantomJS: () => boolean | "";
132
+ declare const isFF: () => false | RegExpMatchArray | null;
133
+ declare const isMobile: () => boolean;
134
+ declare const isFormData: (value: any) => value is FormData;
135
+ declare const isWindow: (value: any) => value is Window;
136
+ declare const isTruthy: <T>(value: T) => value is NonNullable<T>;
137
+ //#endregion
138
+ //#region ../../node_modules/.pnpm/change-case@5.4.4/node_modules/change-case/dist/index.d.ts
139
+ /**
140
+ * Supported locale values. Use `false` to ignore locale.
141
+ * Defaults to `undefined`, which uses the host environment.
142
+ */
143
+ type Locale = string[] | string | false | undefined;
144
+ /**
145
+ * Options used for converting strings to pascal/camel case.
146
+ */
147
+ interface PascalCaseOptions extends Options {
148
+ mergeAmbiguousCharacters?: boolean;
149
+ }
150
+ /**
151
+ * Options used for converting strings to any case.
152
+ */
153
+ interface Options {
154
+ locale?: Locale;
155
+ split?: (value: string) => string[];
156
+ /** @deprecated Pass `split: splitSeparateNumbers` instead. */
157
+ separateNumbers?: boolean;
158
+ delimiter?: string;
159
+ prefixCharacters?: string;
160
+ suffixCharacters?: string;
161
+ }
162
+ /**
163
+ * Convert a string to space separated lower case (`foo bar`).
164
+ */
165
+ declare function noCase(input: string, options?: Options): string;
166
+ /**
167
+ * Convert a string to camel case (`fooBar`).
168
+ */
169
+ declare function camelCase(input: string, options?: PascalCaseOptions): string;
170
+ /**
171
+ * Convert a string to pascal case (`FooBar`).
172
+ */
173
+ declare function pascalCase(input: string, options?: PascalCaseOptions): string;
174
+ /**
175
+ * Convert a string to pascal snake case (`Foo_Bar`).
176
+ */
177
+ declare function pascalSnakeCase(input: string, options?: Options): string;
178
+ /**
179
+ * Convert a string to capital case (`Foo Bar`).
180
+ */
181
+ declare function capitalCase(input: string, options?: Options): string;
182
+ /**
183
+ * Convert a string to constant case (`FOO_BAR`).
184
+ */
185
+ declare function constantCase(input: string, options?: Options): string;
186
+ /**
187
+ * Convert a string to dot case (`foo.bar`).
188
+ */
189
+ declare function dotCase(input: string, options?: Options): string;
190
+ /**
191
+ * Convert a string to kebab case (`foo-bar`).
192
+ */
193
+ declare function kebabCase(input: string, options?: Options): string;
194
+ /**
195
+ * Convert a string to path case (`foo/bar`).
196
+ */
197
+ declare function pathCase(input: string, options?: Options): string;
198
+ /**
199
+ * Convert a string to path case (`Foo bar`).
200
+ */
201
+ declare function sentenceCase(input: string, options?: Options): string;
202
+ /**
203
+ * Convert a string to snake case (`foo_bar`).
204
+ */
205
+ declare function snakeCase(input: string, options?: Options): string;
206
+ /**
207
+ * Convert a string to header case (`Foo-Bar`).
208
+ */
209
+ declare function trainCase(input: string, options?: Options): string;
210
+ //#endregion
211
+ //#region src/number/index.d.ts
212
+ declare const DEFAULT_BIGNUM_CONFIG: _Bignumber.Config;
213
+ declare namespace Bignumber {
214
+ type RoundingMode = _Bignumber.RoundingMode;
215
+ type Format = _Bignumber.Format;
216
+ type Config = _Bignumber.Config;
217
+ type Instance = _Bignumber.Instance;
218
+ type Value = _Bignumber.Value;
219
+ }
220
+ declare const Bignumber: typeof _Bignumber;
221
+ /**
222
+ * export bignumber.js
223
+ *
224
+ * do not use Bignumber directly, use bignumber function instead
225
+ */
226
+ declare const BIG_INTS: Record<Delimiter, {
227
+ v: number;
228
+ d: number;
229
+ n: string;
230
+ }>;
231
+ type Delimiter = 'k' | 'm' | 'b' | 't';
232
+ interface DecimalOptions {
233
+ d?: number;
234
+ r?: Bignumber.RoundingMode;
235
+ }
236
+ interface FormatGroupOptions {
237
+ size?: number;
238
+ symbol?: string;
239
+ }
240
+ interface FormatNumericOptions {
241
+ delimiters?: Delimiter[] | false;
242
+ rounding?: Bignumber.RoundingMode;
243
+ decimals?: number;
244
+ decimalsZero?: boolean;
245
+ default?: string;
246
+ format?: Bignumber.Format;
247
+ }
248
+ declare function bignumber(n?: Numberish, base?: number): _Bignumber;
249
+ declare namespace bignumber {
250
+ var clone: (config: Bignumber.Config) => typeof _Bignumber;
251
+ }
252
+ declare function gte(a: Numberish, b: Numberish): boolean;
253
+ declare function gt(a: Numberish, b: Numberish): boolean;
254
+ declare function lte(a: Numberish, b: Numberish): boolean;
255
+ declare function lt(a: Numberish, b: Numberish): boolean;
256
+ declare function plus(array: Numberish[], options?: DecimalOptions): string;
257
+ declare function divide(array: Numberish[], options?: DecimalOptions): string;
258
+ declare function multiply(array: Numberish[], options?: DecimalOptions): string;
259
+ declare function average(array: Numberish[], options?: DecimalOptions): string;
260
+ /**
261
+ * calculate percentage
262
+ * @param total
263
+ * @param count
264
+ */
265
+ declare function percentage(total: Numberish, count: Numberish, options?: DecimalOptions): string;
266
+ /**
267
+ * leading zeros
268
+ * @param value
269
+ * @param n
270
+ * @param type
271
+ */
272
+ declare function zerofill(value: Numberish, n?: number, type?: 'positive' | 'reverse'): Numberish;
273
+ declare function zeroRemove(value: Numberish, convert?: boolean): string;
274
+ /**
275
+ * format as a positive integer
276
+ * @param value
277
+ */
278
+ declare function integer(value: Numberish): string;
279
+ /**
280
+ * retain n decimal places
281
+ * @param value
282
+ * @param n
283
+ */
284
+ declare function decimal(value: Numberish, n?: number): string;
285
+ declare function parseNumeric(num: Numberish, delimiters?: Delimiter[]): {
286
+ v: number;
287
+ d: number;
288
+ n: string;
289
+ };
290
+ /**
291
+ * format number thousand separator and unit
292
+ * @param value
293
+ * @param options
294
+ */
295
+ declare function formatNumeric(value?: Numberish, options?: FormatNumericOptions): string;
296
+ //#endregion
297
+ //#region src/string/index.d.ts
298
+ /**
299
+ * Intercept front and back characters, hide middle characters
300
+ * @param value
301
+ * @param mode
302
+ * @param symbol
303
+ */
304
+ declare function cover(value: string, mode: [number, number, number], symbol?: string): string;
305
+ /**
306
+ * Shortens an identifier string by showing only the beginning and end portions,
307
+ * with ellipsis in the middle. Suitable for various types of identifiers like
308
+ * IPFS CID, transaction hashes, EVM addresses, user IDs, etc.
309
+ *
310
+ * @param value - The identifier string to shorten
311
+ * @param startWith - Number of characters to show at the start (default: 6)
312
+ * @param endWith - Number of characters to show at the end (default: 6)
313
+ * @returns Shortened identifier string with ellipsis, or empty string if id is null/undefined
314
+ */
315
+ declare function shortenId(value: string | null | undefined, startWith?: number, endWith?: number): string;
316
+ /**
317
+ * Replace backslash to slash
318
+ *
319
+ * @category String
320
+ */
321
+ declare function slash(str: string): string;
322
+ /**
323
+ * Ensure prefix of a string
324
+ *
325
+ * @category String
326
+ */
327
+ declare function ensurePrefix(prefix: string, str: string): string;
328
+ /**
329
+ * Ensure suffix of a string
330
+ *
331
+ * @category String
332
+ */
333
+ declare function ensureSuffix(suffix: string, str: string): string;
334
+ /**
335
+ * Dead simple template engine, just like Python's `.format()`
336
+ * Support passing variables as either in index based or object/name based approach
337
+ * While using object/name based approach, you can pass a fallback value as the third argument
338
+ *
339
+ * @category String
340
+ * @example
341
+ * ```
342
+ * const result = template(
343
+ * 'Hello {0}! My name is {1}.',
344
+ * 'Inès',
345
+ * 'Anthony'
346
+ * ) // Hello Inès! My name is Anthony.
347
+ * ```
348
+ *
349
+ * ```
350
+ * const result = namedTemplate(
351
+ * '{greet}! My name is {name}.',
352
+ * { greet: 'Hello', name: 'Anthony' }
353
+ * ) // Hello! My name is Anthony.
354
+ * ```
355
+ *
356
+ * const result = namedTemplate(
357
+ * '{greet}! My name is {name}.',
358
+ * { greet: 'Hello' }, // name isn't passed hence fallback will be used for name
359
+ * 'placeholder'
360
+ * ) // Hello! My name is placeholder.
361
+ * ```
362
+ */
363
+ declare function template(str: string, object: Record<string | number, any>, fallback?: string | ((key: string) => string)): string;
364
+ declare function template(str: string, ...args: (string | number | bigint | undefined | null)[]): string;
365
+ /**
366
+ * Remove common leading whitespace from a template string.
367
+ * Will also remove empty lines at the beginning and end.
368
+ * @category string
369
+ * @example
370
+ * ```ts
371
+ * const str = unindent`
372
+ * if (a) {
373
+ * b()
374
+ * }
375
+ * `
376
+ * ```
377
+ */
378
+ declare function unindent(str: TemplateStringsArray | string): string;
379
+ //#endregion
380
+ //#region src/util/compose-promise.d.ts
381
+ type UF$1<VT, RT> = (value: VT) => RT | PromiseLike<RT>;
382
+ type Composed<VT, RT> = (value?: VT) => Promise<RT>;
383
+ /**
384
+ * Compose promise-returning & async fns into a reusable pipeline.
385
+ *
386
+ * @param ...fns - Iterated over sequentially when returned `function` is called.
387
+ * @returns The `fns` are applied from right to left.
388
+ *
389
+ * @example
390
+ * ```
391
+ * const addUnicorn = async string => `${string} Unicorn`;
392
+ * const addRainbow = async string => `${string} Rainbow`;
393
+ *
394
+ * const pipeline = pCompose(addRainbow, addUnicorn);
395
+ *
396
+ * console.log(await pipeline('❤️'));
397
+ * //=> '❤️ Unicorn Rainbow'
398
+ * ```
399
+ */
400
+ declare function pCompose<VT, RT>(f1: UF$1<VT, RT>): Composed<VT, RT>;
401
+ declare function pCompose<VT, R1, RT>(f1: UF$1<R1, RT>, f2: UF$1<VT, R1>): Composed<VT, RT>;
402
+ declare function pCompose<VT, R1, R2, RT>(f1: UF$1<R2, RT>, f2: UF$1<R1, R2>, f3: UF$1<VT, R1>): Composed<VT, RT>;
403
+ declare function pCompose<VT, R1, R2, R3, RT>(f1: UF$1<R3, RT>, f2: UF$1<R2, R3>, f3: UF$1<R1, R2>, f4: UF$1<VT, R1>): Composed<VT, RT>;
404
+ declare function pCompose<VT, R1, R2, R3, R4, RT>(f1: UF$1<R4, RT>, f2: UF$1<R3, R4>, f3: UF$1<R2, R3>, f4: UF$1<R1, R2>, f5: UF$1<VT, R1>): Composed<VT, RT>;
405
+ declare function pCompose<VT, R1, R2, R3, R4, R5, RT>(f1: UF$1<R5, RT>, f2: UF$1<R4, R5>, f3: UF$1<R3, R4>, f4: UF$1<R2, R3>, f5: UF$1<R1, R2>, f6: UF$1<VT, R1>): Composed<VT, RT>;
406
+ declare function pCompose<VT, R1, R2, R3, R4, R5, R6, RT>(f1: UF$1<R6, RT>, f2: UF$1<R5, R6>, f3: UF$1<R4, R5>, f4: UF$1<R3, R4>, f5: UF$1<R2, R3>, f6: UF$1<R1, R2>, f7: UF$1<VT, R1>): Composed<VT, RT>;
407
+ declare function pCompose<VT, R1, R2, R3, R4, R5, R6, R7, RT>(f1: UF$1<R7, RT>, f2: UF$1<R6, R7>, f3: UF$1<R5, R6>, f4: UF$1<R4, R5>, f5: UF$1<R3, R4>, f6: UF$1<R2, R3>, f7: UF$1<R1, R2>, f8: UF$1<VT, R1>): Composed<VT, RT>;
408
+ declare function pCompose<VT, R1, R2, R3, R4, R5, R6, R7, R8, RT>(f1: UF$1<R8, RT>, f2: UF$1<R7, R8>, f3: UF$1<R6, R7>, f4: UF$1<R5, R6>, f5: UF$1<R4, R5>, f6: UF$1<R3, R4>, f7: UF$1<R2, R3>, f8: UF$1<R1, R2>, f9: UF$1<VT, R1>): Composed<VT, RT>;
409
+ //#endregion
410
+ //#region src/util/compose.d.ts
411
+ type Fn$1<V, R> = (x: V) => R;
412
+ type Q<T, V> = (...args: T) => V;
413
+ /**
414
+ * Performs function composition in RTL (Right To Left) direction.
415
+ *
416
+ * Our `compose` and `compose.promise` implementation supports N arguments. But you can use only 10 in
417
+ * TypeScript, because it doesn't support **Variadic Kinds** and we explicitly
418
+ * have to define the type of all the possible usages as method overloads.
419
+ *
420
+ * @example
421
+ * const normalizeWhiteSpaces = text => name.replace(/\s+/g, ' ').trim();
422
+ *
423
+ * const getInitials = compose(
424
+ * initials => initials.join('').toLocaleUpperCase(),
425
+ * name => name.split(' ').map(name => name.charAt(0)),
426
+ * normalizeWhiteSpaces
427
+ * );
428
+ *
429
+ * getInitials('Vitor Luiz Cavalcanti');
430
+ * //=> "VLC"
431
+ *
432
+ * @param fn - An arity 1 function, except the last one which can have arity N.
433
+ * @param fns - Functions of arity 1. Each one's result is next's argument.
434
+ *
435
+ * @example
436
+ *
437
+ * const addUnicorn = async string => `${string} Unicorn`;
438
+ * const addRainbow = async string => `${string} Rainbow`;
439
+ *
440
+ * const pipeline = compose.promise(addRainbow, addUnicorn);
441
+ *
442
+ * console.log(await pipeline('❤️'));
443
+ * //=> '❤️ Unicorn Rainbow'
444
+ * @param ...fns - Iterated over sequentially when returned `function` is called.
445
+ * @returns The `fns` functions are applied from right to left.
446
+ */
447
+ declare function compose<T, V0, V1>(fn1: Fn$1<V0, V1>, fn0: Q<T, V0>): Q<T, V1>;
448
+ declare function compose<T, V0, V1, V2>(fn2: Fn$1<V1, V2>, fn1: Fn$1<V0, V1>, fn0: Q<T, V0>): Q<T, V2>;
449
+ declare function compose<T, V0, V1, V2, V3>(fn3: Fn$1<V2, V3>, fn2: Fn$1<V1, V2>, fn1: Fn$1<V0, V1>, fn0: Q<T, V0>): Q<T, V3>;
450
+ declare function compose<T, V0, V1, V2, V3, V4>(fn4: Fn$1<V3, V4>, fn3: Fn$1<V2, V3>, fn2: Fn$1<V1, V2>, fn1: Fn$1<V0, V1>, fn0: Q<T, V0>): Q<T, V4>;
451
+ declare function compose<T, V0, V1, V2, V3, V4, V5>(fn5: Fn$1<V4, V5>, fn4: Fn$1<V3, V4>, fn3: Fn$1<V2, V3>, fn2: Fn$1<V1, V2>, fn1: Fn$1<V0, V1>, fn0: Q<T, V0>): Q<T, V5>;
452
+ declare function compose<T, V0, V1, V2, V3, V4, V5, V6>(fn6: Fn$1<V5, V6>, fn5: Fn$1<V4, V5>, fn4: Fn$1<V3, V4>, fn3: Fn$1<V2, V3>, fn2: Fn$1<V1, V2>, fn1: Fn$1<V0, V1>, fn0: Q<T, V0>): Q<T, V6>;
453
+ declare function compose<T, V0, V1, V2, V3, V4, V5, V6, V7>(fn7: Fn$1<V6, V7>, fn6: Fn$1<V5, V6>, fn5: Fn$1<V4, V5>, fn4: Fn$1<V3, V4>, fn3: Fn$1<V2, V3>, fn2: Fn$1<V1, V2>, fn1: Fn$1<V0, V1>, fn0: Q<T, V0>): Q<T, V7>;
454
+ declare function compose<T, V0, V1, V2, V3, V4, V5, V6, V7, V8>(fn8: Fn$1<V7, V8>, fn7: Fn$1<V6, V7>, fn6: Fn$1<V5, V6>, fn5: Fn$1<V4, V5>, fn4: Fn$1<V3, V4>, fn3: Fn$1<V2, V3>, fn2: Fn$1<V1, V2>, fn1: Fn$1<V0, V1>, fn0: Q<T, V0>): Q<T, V8>;
455
+ declare function compose<T, V0, V1, V2, V3, V4, V5, V6, V7, V8, V9>(fn9: Fn$1<V8, V9>, fn8: Fn$1<V7, V8>, fn7: Fn$1<V6, V7>, fn6: Fn$1<V5, V6>, fn5: Fn$1<V4, V5>, fn4: Fn$1<V3, V4>, fn3: Fn$1<V2, V3>, fn2: Fn$1<V1, V2>, fn1: Fn$1<V0, V1>, fn0: Q<T, V0>): Q<T, V9>;
456
+ declare function compose<T, V0, V1, V2, V3, V4, V5, V6, V7, V8, V9, V10>(fn10: Fn$1<V9, V10>, fn9: Fn$1<V8, V9>, fn8: Fn$1<V7, V8>, fn7: Fn$1<V6, V7>, fn6: Fn$1<V5, V6>, fn5: Fn$1<V4, V5>, fn4: Fn$1<V3, V4>, fn3: Fn$1<V2, V3>, fn2: Fn$1<V1, V2>, fn1: Fn$1<V0, V1>, fn0: Q<T, V0>): Q<T, V10>;
457
+ declare namespace compose {
458
+ var promise: typeof pCompose;
459
+ }
460
+ //#endregion
461
+ //#region src/util/deferred.d.ts
462
+ /**
463
+ * A deferred promise.
464
+ * @param T - The type of the value.
465
+ * @returns The deferred promise.
466
+ * @example
467
+ * ```ts
468
+ * const deferred = new Deferred()
469
+ * deferred.resolve('value')
470
+ * ```
471
+ */
472
+ declare class Deferred<T> extends Promise<T> {
473
+ resolve: (value?: T) => Deferred<T>;
474
+ reject: (reason?: any) => Deferred<T>;
475
+ constructor(executor?: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void);
476
+ }
477
+ //#endregion
478
+ //#region src/util/delay.d.ts
479
+ /**
480
+ * Delay for a given number of milliseconds.
481
+ * @param ms - The number of milliseconds to delay.
482
+ * @returns A promise that resolves after the given number of milliseconds.
483
+ * @example
484
+ * ```ts
485
+ * delay(1000).then(() => { console.log('1 second') })
486
+ * ```
487
+ */
488
+ declare function delay(ms: number): Promise<void>;
489
+ //#endregion
490
+ //#region src/util/ghost.d.ts
491
+ type Ghost<T extends object> = T & {
492
+ enabled: boolean;
493
+ resolve: (value: T) => void;
494
+ };
495
+ declare function ghost<T extends object>(strictMessage?: string): Ghost<T>;
496
+ //#endregion
497
+ //#region src/util/json.d.ts
498
+ declare function tryParseJson<T = any>(text: string | undefined | null): T | undefined;
499
+ //#endregion
500
+ //#region src/util/loop.d.ts
501
+ /**
502
+ * A function that performs a loop operation with delay control.
503
+ * @template T - The return type of the loop function (defaults to void)
504
+ * @param next - A function that schedules the next iteration after a delay (in milliseconds)
505
+ * @returns A promise that resolves with the result of type T
506
+ */
507
+ type Looper<T = void> = (next: (ms: number) => Promise<T>) => Promise<T>;
508
+ declare function loop_return<T = void>(fn: Looper<T>): Promise<T>;
509
+ /**
510
+ * Creates a cancellable loop that executes repeatedly with delays.
511
+ * Returns a cancel function that can be called to stop the loop.
512
+ * The loop will not execute further iterations after cancellation.
513
+ *
514
+ * @param fn - The loop function that receives a `next` callback to schedule the next iteration
515
+ * @returns A cancel function that stops the loop when called
516
+ *
517
+ * @example loop
518
+ * ```ts
519
+ * const cancel = loop(async (next) => {
520
+ * console.log('tick')
521
+ * await next(1000) // Wait 1 second before next iteration
522
+ * })
523
+ *
524
+ * // Stop the loop after 5 seconds
525
+ * setTimeout(cancel, 5000)
526
+ *```
527
+ * @example loop.return
528
+ * ```ts
529
+ * const result = await loop.return(async (next) => {
530
+ * if (condition) {
531
+ * return 'done'
532
+ * }
533
+ * await next(1000)
534
+ * })
535
+ * console.log(result)
536
+ * ```
537
+ */
538
+ declare function loop(fn: Looper<void>): Fn;
539
+ declare namespace loop {
540
+ var _a: typeof loop_return;
541
+ export { _a as return };
542
+ }
543
+ //#endregion
544
+ //#region src/util/noop.d.ts
545
+ declare const noop: (...args: any) => any;
546
+ //#endregion
547
+ //#region src/util/pipe-promise.d.ts
548
+ type UF<VT, RT> = (value: VT) => RT | PromiseLike<RT>;
549
+ type Pipeline<VT, RT> = (value?: VT) => Promise<RT>;
550
+ /**
551
+ * Compose promise-returning & async fns into a reusable pipeline.
552
+ *
553
+ * @param ...input - Iterated over sequentially when returned `function` is called.
554
+ * @returns The `input` fns are applied from left to right.
555
+ *
556
+ * @example
557
+ * ```
558
+ * const addUnicorn = async string => `${string} Unicorn`;
559
+ * const addRainbow = async string => `${string} Rainbow`;
560
+ *
561
+ * const pipeline = pipe.promise(addUnicorn, addRainbow);
562
+ *
563
+ * console.log(await pipeline('❤️'));
564
+ * //=> '❤️ Unicorn Rainbow'
565
+ * ```
566
+ */
567
+ declare function pPipe<VT, RT>(f1: UF<VT, RT>): Pipeline<VT, RT>;
568
+ declare function pPipe<VT, R1, RT>(f1: UF<VT, R1>, f2: UF<R1, RT>): Pipeline<VT, RT>;
569
+ declare function pPipe<VT, R1, R2, RT>(f1: UF<VT, R1>, f2: UF<R1, R2>, f3: UF<R2, RT>): Pipeline<VT, RT>;
570
+ declare function pPipe<VT, R1, R2, R3, RT>(f1: UF<VT, R1>, f2: UF<R1, R2>, f3: UF<R2, R3>, f4: UF<R3, RT>): Pipeline<VT, RT>;
571
+ declare function pPipe<VT, R1, R2, R3, R4, RT>(f1: UF<VT, R1>, f2: UF<R1, R2>, f3: UF<R2, R3>, f4: UF<R3, R4>, f5: UF<R4, RT>): Pipeline<VT, RT>;
572
+ declare function pPipe<VT, R1, R2, R3, R4, R5, RT>(f1: UF<VT, R1>, f2: UF<R1, R2>, f3: UF<R2, R3>, f4: UF<R3, R4>, f5: UF<R4, R5>, f6: UF<R5, RT>): Pipeline<VT, RT>;
573
+ declare function pPipe<VT, R1, R2, R3, R4, R5, R6, RT>(f1: UF<VT, R1>, f2: UF<R1, R2>, f3: UF<R2, R3>, f4: UF<R3, R4>, f5: UF<R4, R5>, f6: UF<R5, R6>, f7: UF<R6, RT>): Pipeline<VT, RT>;
574
+ declare function pPipe<VT, R1, R2, R3, R4, R5, R6, R7, RT>(f1: UF<VT, R1>, f2: UF<R1, R2>, f3: UF<R2, R3>, f4: UF<R3, R4>, f5: UF<R4, R5>, f6: UF<R5, R6>, f7: UF<R6, R7>, f8: UF<R7, RT>): Pipeline<VT, RT>;
575
+ declare function pPipe<VT, R1, R2, R3, R4, R5, R6, R7, R8, RT>(f1: UF<VT, R1>, f2: UF<R1, R2>, f3: UF<R2, R3>, f4: UF<R3, R4>, f5: UF<R4, R5>, f6: UF<R5, R6>, f7: UF<R6, R7>, f8: UF<R7, R8>, f9: UF<R8, RT>): Pipeline<VT, RT>;
576
+ //#endregion
577
+ //#region src/util/pipe.d.ts
578
+ /**
579
+ * Performs function composition in LTR (Left To Right) direction.
580
+ *
581
+ * Our `pipe` and `pipe.promise` implementation supports N arguments. But you can use only 10 in
582
+ * TypeScript, because it doesn't support **Variadic Kinds** and we explicitly
583
+ * have to define the type of all the possible usages as method overloads.
584
+ *
585
+ * @example pipe
586
+ *
587
+ * const normalizeWhiteSpaces = text => name.replace(/\s+/g, ' ').trim();
588
+ *
589
+ * const getInitials = pipe(
590
+ * normalizeWhiteSpaces,
591
+ * name => name.split(' ').map(name => name.charAt(0)),
592
+ * initials => initials.join('').toLocaleUpperCase()
593
+ * );
594
+ *
595
+ * getInitials('Vitor Luiz Cavalcanti');
596
+ * //=> "VLC"
597
+ *
598
+ * @param fn - An arity N function. Its result is the argument of next one.
599
+ * @param fns - Functions of arity 1. Each one's result is next's argument.
600
+ *
601
+ * @example pipe.promise
602
+ *
603
+ * const addUnicorn = async string => `${string} Unicorn`;
604
+ * const addRainbow = async string => `${string} Rainbow`;
605
+ *
606
+ * const pipeline = pipe.promise(addUnicorn, addRainbow);
607
+ *
608
+ * console.log(await pipeline('❤️'));
609
+ * //=> '❤️ Unicorn Rainbow'
610
+ * @param ...input - Iterated over sequentially when returned `function` is called.
611
+ * @returns The `input` functions are applied from left to right.
612
+ */
613
+ declare function pipe<Args extends unknown[], T0>(...fns: [(...xs: Args) => T0]): (...xs: Args) => T0;
614
+ declare function pipe<Args extends unknown[], T0, T1>(...fns: [(...xs: Args) => T0, (x: T0) => T1]): (...xs: Args) => T1;
615
+ declare function pipe<Args extends unknown[], T0, T1, T2>(...fns: [(...xs: Args) => T0, (x: T0) => T1, (x: T1) => T2]): (...xs: Args) => T2;
616
+ declare function pipe<Args extends unknown[], T0, T1, T2, T3>(...fns: [(...xs: Args) => T0, (x: T0) => T1, (x: T1) => T2, (x: T2) => T3]): (...xs: Args) => T3;
617
+ declare function pipe<Args extends unknown[], T0, T1, T2, T3, T4>(...fns: [(...xs: Args) => T0, (x: T0) => T1, (x: T1) => T2, (x: T2) => T3, (x: T3) => T4]): (...xs: Args) => T4;
618
+ declare function pipe<Args extends unknown[], T0, T1, T2, T3, T4, T5>(...fns: [(...xs: Args) => T0, (x: T0) => T1, (x: T1) => T2, (x: T2) => T3, (x: T3) => T4, (x: T4) => T5]): (...xs: Args) => T5;
619
+ declare function pipe<Args extends unknown[], T0, T1, T2, T3, T4, T5, T6>(...fns: [(...xs: Args) => T0, (x: T0) => T1, (x: T1) => T2, (x: T2) => T3, (x: T3) => T4, (x: T4) => T5, (x: T5) => T6]): (...xs: Args) => T6;
620
+ declare function pipe<Args extends unknown[], T0, T1, T2, T3, T4, T5, T6, T7>(...fns: [(...xs: Args) => T0, (x: T0) => T1, (x: T1) => T2, (x: T2) => T3, (x: T3) => T4, (x: T4) => T5, (x: T5) => T6, (x: T6) => T7]): (...xs: Args) => T7;
621
+ declare function pipe<Args extends unknown[], T0, T1, T2, T3, T4, T5, T6, T7, T8>(...fns: [(...xs: Args) => T0, (x: T0) => T1, (x: T1) => T2, (x: T2) => T3, (x: T3) => T4, (x: T4) => T5, (x: T5) => T6, (x: T6) => T7, (x: T7) => T8]): (...xs: Args) => T8;
622
+ declare function pipe<Args extends unknown[], T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>(...fns: [(...xs: Args) => T0, (x: T0) => T1, (x: T1) => T2, (x: T2) => T3, (x: T3) => T4, (x: T4) => T5, (x: T5) => T6, (x: T6) => T7, (x: T7) => T8, (x: T8) => T9]): (...xs: Args) => T9;
623
+ declare namespace pipe {
624
+ var promise: typeof pPipe;
625
+ }
626
+ //#endregion
627
+ //#region src/util/proxy.d.ts
628
+ type Proxyed<T extends object, E extends object = {}> = T & {
629
+ proxy: {
630
+ update: (object?: T) => void;
631
+ source: T | undefined;
632
+ };
633
+ } & E;
634
+ /**
635
+ * Creates a proxy object that updates the original object when the proxy is updated.
636
+ * @param initObject - The initial object to proxy.
637
+ * @returns The proxy object.
638
+ *
639
+ * @example
640
+ * ```ts
641
+ * const obj = proxy({ name: 'John' })
642
+ * console.log(obj.name) // John
643
+ *
644
+ * obj.proxy.update({ name: 'Jane' })
645
+ * console.log(obj.name) // Jane
646
+ *
647
+ * const obj2 = proxy()
648
+ *
649
+ * obj2.any // Error: Proxy not updated. Call object.proxy.update() to update the proxy.
650
+ *
651
+ * obj2.proxy.source // undefined
652
+ * obj2.update({ name: 'John' })
653
+ *
654
+ * // get the original object
655
+ * obj2.proxy.source // { name: 'John' }
656
+ * ```
657
+ */
658
+ declare function proxy<T extends object, E extends object = {}>(initObject?: T, initExtend?: E, options?: {
659
+ strictMessage?: string;
660
+ }): Proxyed<T, E>;
661
+ //#endregion
662
+ //#region src/util/random.d.ts
663
+ /**
664
+ * Get a random item from an array.
665
+ * @param array - The array to get a random item from.
666
+ * @returns The random item.
667
+ * @example
668
+ * ```ts
669
+ * randomItem(['a', 'b', 'c']) // 'a' | 'b' | 'c'
670
+ * ```
671
+ */
672
+ declare function randomItem<T>(array: T[]): T;
673
+ /**
674
+ * Get a random number between a minimum and maximum value.
675
+ * @param min - The minimum value.
676
+ * @param max - The maximum value.
677
+ * @returns The random number.
678
+ * @example
679
+ * ```ts
680
+ * randomNumber(0, 100) // 0-100
681
+ * ```
682
+ */
683
+ declare function randomNumber(min: number, max: number): number;
684
+ /**
685
+ * Get a random string of a given size.
686
+ * @param size - The size of the string.
687
+ * @param chars - The characters to use in the string.
688
+ * @returns The random string.
689
+ * @example
690
+ * ```ts
691
+ * randomString() // 10 characters long
692
+ * randomString(20) // 20 characters long
693
+ * randomString(20, 'abcdefghijklmnopqrstuvwxyz') // 20 characters long
694
+ * ```
695
+ */
696
+ declare function randomString(size?: number, chars?: string): string;
697
+ //#endregion
698
+ //#region src/util/serialized.d.ts
699
+ /**
700
+ * formData to object
701
+ * @param formData
702
+ */
703
+ declare function formdataToObject(formData: FormData): Record<string, string>;
704
+ /**
705
+ * Object to formData
706
+ * @param object
707
+ */
708
+ declare function objectToFormdata(object: Record<string, string | File>): FormData;
709
+ /**
710
+ * Check if a value is not NaN.
711
+ * @param value - The value to check.
712
+ * @returns The value if it is not NaN, otherwise undefined.
713
+ */
714
+ declare function nonnanable<T>(value: T): T | undefined;
715
+ /**
716
+ * Convert a value to a number.
717
+ * @param value - The value to convert to a number.
718
+ * @returns The number value.
719
+ */
720
+ declare function numberify(value: any): number;
721
+ /**
722
+ * Convert a value to a string.
723
+ * @param value - The value to convert to a string.
724
+ * @returns The string value.
725
+ */
726
+ declare function stringify(value: any): string;
727
+ /**
728
+ * Convert a value to a numberish value.
729
+ * @param value - The value to convert to a numberish value.
730
+ * @returns The numberish value.
731
+ */
732
+ declare function numberish(value: Numberish): string;
733
+ //#endregion
734
+ //#region src/util/to.d.ts
735
+ /**
736
+ * Convert a promise to a tuple of [error, data].
737
+ * @param promise - The promise to convert.
738
+ * @param error - The error to return if the promise fails.
739
+ * @returns The tuple of [error, data].
740
+ * @example
741
+ * ```ts
742
+ * to(Promise.resolve('data')) // Promise<[null, 'data']>
743
+ * to(Promise.reject(new Error('error'))) // Promise<[Error, undefined]>
744
+ * ```
745
+ */
746
+ declare function to<T, U = Error>(promise: Promise<T> | (() => Promise<T>), error?: object): Promise<[U, undefined] | [null, T]>;
747
+ //#endregion
748
+ //#region src/util/to-array.d.ts
749
+ /**
750
+ * Convert a value to an array.
751
+ * @param value - The value to convert.
752
+ * @param required - Whether the array is required.
753
+ * @returns The array.
754
+ * @example
755
+ * ```ts
756
+ * toArray(arrorOrItemOrUndefined) // item[] | undefined
757
+ * toArray(arrayOrItemOrUndefined, true) // item[]
758
+ * ```
759
+ */
760
+ declare function toArray<T, R extends boolean>(value?: T | T[], required?: R): R extends true ? T[] : T[] | undefined;
761
+ //#endregion
762
+ //#region src/util/unit.d.ts
763
+ type Dimension = Numeric | [Numeric, Numeric] | {
764
+ width: Numeric;
765
+ height: Numeric;
766
+ };
767
+ declare function unit(value: Numeric, unit?: string): string;
768
+ declare function size(dimension: Dimension, unit?: string): {
769
+ width: string;
770
+ height: string;
771
+ };
772
+ //#endregion
773
+ //#region src/util/util.d.ts
774
+ /** @deprecated Use range instead */
775
+ declare const arange: {
776
+ (start: number, end?: number, step?: number): number[];
777
+ (end: number, index: string | number, guard: object): number[];
778
+ };
779
+ /**
780
+ * Select a value based on a condition.
781
+ * @param args - The arguments to select from.
782
+ * @returns The selected value.
783
+ * @example
784
+ * ```ts
785
+ * select(
786
+ * [condition1, value],
787
+ * [condition2, value2],
788
+ * // default value
789
+ * [true, value3],
790
+ * ...
791
+ * ) // value
792
+ * ```
793
+ */
794
+ declare function select<T>(...args: [cond: boolean, value: T][]): T;
795
+ /**
796
+ * @deprecated Use select instead
797
+ */
798
+ declare const riposte: typeof select;
799
+ /**
800
+ * Unwrap a value or a function that returns a value.
801
+ * @param value - The value or function to unwrap.
802
+ * @returns The unwrapped value.
803
+ * @example
804
+ * ```ts
805
+ * unwrap({ name: 'John' }) // { name: 'John' }
806
+ * unwrap(() => { return { name: 'John' } }) // { name: 'John' }
807
+ * ```
808
+ */
809
+ declare function unwrap<T extends object>(value: T | (() => T)): T;
810
+ /**
811
+ * Call a callback if a value is not null or undefined.
812
+ * @param value - The value to check.
813
+ * @param callback - The callback to call.
814
+ * @returns The result of the callback.
815
+ * @example
816
+ * ```ts
817
+ * whenever(value, (value) => { return 'value' }) // value
818
+ * ```
819
+ */
820
+ declare function whenever<T, C extends (value: Exclude<T, null | undefined>) => any>(value: T, callback: C): ReturnType<C> | undefined;
821
+ declare function call<T extends Fn<any>>(fn: T, ...args: Parameters<T>): ReturnType<T>;
822
+ //#endregion
823
+ export { AnyFn, ArgumentsType, Arrayable, Assign, Awaitable, BIG_INTS, Bignumber, BooleanLike, BrowserNativeObject, ConstructorType, DEFAULT_BIGNUM_CONFIG, DecimalOptions, DeepKeyof, DeepMap, DeepMerge, DeepPartial, DeepReadonly, DeepReplace, DeepRequired, Deferred, Delimiter, Dimension, DynamicObject, ElementOf, Fn, FormatGroupOptions, FormatNumericOptions, Ghost, IfAny, IsAny, Key, Looper, MergeInsertions, NonUndefined, Noop, Nullable, NumberObject, Numberish, Numeric, NumericObject, OmitBy, OpenFilePickerOptions, OpenImagePickerOptions, Option, Overwrite, PickBy, PromiseFn, PromiseType, Promisify, Proxyed, ReaderType, StringObject, SymbolObject, arange, average, bignumber, call, camelCase, capitalCase, chunk, clone, cloneDeep, cloneDeepWith, cloneWith, compose, concat, constantCase, cover, debounce, decimal, delay, dialsPhone, divide, dotCase, downloadBlobFile, downloadNetworkFile, downloadUrlFile, ensurePrefix, ensureSuffix, find, formatNumeric, formdataToObject, get, ghost, groupBy, gt, gte, integer, isAndroid, isArguments, isArray, isArrayBuffer, isArrayLike, isArrayLikeObject, isBoolean, isBrowser, isBuffer, isChrome, isDate, isEdge, isElement, isEmpty, isEqual, isEqualWith, isError, isFF, isFormData, isFunction, isIE, isIE11, isIE9, isIOS, isInteger, isMap, isMatch, isMatchWith, isMobile, isNaN, isNative, isNull, isNumber, isObject, isObjectLike, isPhantomJS, isPlainObject, isRegexp, isSet, isString, isSymbol, isTruthy, isUndefined, isWeakMap, isWeakSet, isWeex, isWindow, join, kebabCase, keyBy, keys, loop, lt, lte, max, maxBy, merge, mergeWith, min, minBy, multiply, noCase, nonnanable, noop, numberify, numberish, objectToFormdata, off, omit, omitBy, on, once, openFilePicker, openImagePicker, parseNumeric, pascalCase, pascalSnakeCase, pathCase, percentage, pick, pickBy, pipe, plus, proxy, randomItem, randomNumber, randomString, range, readFileReader, redirectTo, riposte, select, selectImages, sentenceCase, set, shortenId, showOpenFilePicker, showOpenImagePicker, size, slash, snakeCase, stringify, template, to, toArray, trainCase, truncate, tryParseJson, unindent, uniq, uniqBy, uniqWith, unit, unwrap, values, whenever, zeroRemove, zerofill };