@hairy/utils 1.45.0 → 1.47.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.
- package/dist/index.cjs +419 -117
- package/dist/index.d.ts +275 -104
- package/dist/index.global.js +382 -108
- package/dist/index.js +399 -111
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { 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, merge, mergeWith, set, truncate, uniq, uniqBy, uniqWith, values } from 'lodash-es';
|
|
1
|
+
export { 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';
|
|
2
2
|
import _Bignumber from 'bignumber.js';
|
|
3
3
|
|
|
4
4
|
interface OpenFilePickerOptions {
|
|
@@ -14,7 +14,9 @@ interface OpenFilePickerOptions {
|
|
|
14
14
|
/**
|
|
15
15
|
* Select multiple files
|
|
16
16
|
*/
|
|
17
|
-
declare function
|
|
17
|
+
declare function openFilePicker(option?: OpenFilePickerOptions): Promise<File[]>;
|
|
18
|
+
/** @deprecated use openFilePicker */
|
|
19
|
+
declare const showOpenFilePicker: typeof openFilePicker;
|
|
18
20
|
interface OpenImagePickerOptions {
|
|
19
21
|
/**
|
|
20
22
|
* select multiple images
|
|
@@ -24,9 +26,10 @@ interface OpenImagePickerOptions {
|
|
|
24
26
|
/**
|
|
25
27
|
* Select multiple images
|
|
26
28
|
*/
|
|
27
|
-
declare function
|
|
28
|
-
/** @deprecated use
|
|
29
|
-
declare const selectImages: typeof
|
|
29
|
+
declare function openImagePicker(options?: OpenImagePickerOptions): Promise<File[]>;
|
|
30
|
+
/** @deprecated use openImagePicker */
|
|
31
|
+
declare const selectImages: typeof openImagePicker;
|
|
32
|
+
declare const showOpenImagePicker: typeof openImagePicker;
|
|
30
33
|
/**
|
|
31
34
|
* Generate Blob | string file and download it
|
|
32
35
|
* @param data Blob data, or string
|
|
@@ -38,7 +41,9 @@ declare function downloadBlobFile(data: Blob | string, name: string): void;
|
|
|
38
41
|
* @param url Download link
|
|
39
42
|
* @param name file name
|
|
40
43
|
*/
|
|
41
|
-
declare function
|
|
44
|
+
declare function downloadUrlFile(url: string, name?: string): void;
|
|
45
|
+
/** @deprecated use downloadUrlFile */
|
|
46
|
+
declare const downloadNetworkFile: typeof downloadUrlFile;
|
|
42
47
|
type ReaderType = 'readAsArrayBuffer' | 'readAsBinaryString' | 'readAsDataURL' | 'readAsText';
|
|
43
48
|
/**
|
|
44
49
|
* Read File file
|
|
@@ -48,6 +53,9 @@ type ReaderType = 'readAsArrayBuffer' | 'readAsBinaryString' | 'readAsDataURL' |
|
|
|
48
53
|
declare function readFileReader<T extends ReaderType>(formType: T, file: File): Promise<T extends "readAsArrayBuffer" ? ArrayBuffer : string>;
|
|
49
54
|
|
|
50
55
|
type Numeric = string | number | bigint;
|
|
56
|
+
type Numberish = Numeric | {
|
|
57
|
+
toString: (...args: any[]) => string;
|
|
58
|
+
} | undefined | null;
|
|
51
59
|
interface DynamicObject {
|
|
52
60
|
[key: string]: any;
|
|
53
61
|
}
|
|
@@ -67,32 +75,9 @@ type Key = string | number | symbol;
|
|
|
67
75
|
type BooleanLike = any;
|
|
68
76
|
type Noop = (...args: any[]) => any;
|
|
69
77
|
|
|
70
|
-
type DeepReadonly<T> = {
|
|
71
|
-
readonly [P in keyof T]: T[P] extends object ? DeepReadonly<T[P]> : T[P];
|
|
72
|
-
};
|
|
73
|
-
type DeepRequired<T> = {
|
|
74
|
-
[P in keyof T]-?: T[P] extends object ? DeepRequired<T[P]> : T[P];
|
|
75
|
-
};
|
|
76
|
-
type DeepPartial<T> = {
|
|
77
|
-
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
|
|
78
|
-
};
|
|
79
|
-
type DeepReplace<T, K = unknown, V = unknown> = {
|
|
80
|
-
[P in keyof T]: K extends P ? V : DeepReplace<T[P], K, V>;
|
|
81
|
-
};
|
|
82
|
-
type DeepKeyof<T> = T extends object ? keyof T | DeepKeyof<T[keyof T]> : never;
|
|
83
|
-
type MergeInsertions<T> = T extends object ? {
|
|
84
|
-
[K in keyof T]: MergeInsertions<T[K]>;
|
|
85
|
-
} : T;
|
|
86
|
-
type DeepMerge<F, S> = MergeInsertions<{
|
|
87
|
-
[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;
|
|
88
|
-
}>;
|
|
89
|
-
|
|
90
78
|
/**
|
|
91
79
|
* Any type that can be used where a big number is needed.
|
|
92
80
|
*/
|
|
93
|
-
type Numberish = Numeric | {
|
|
94
|
-
toString: (...args: any[]) => string;
|
|
95
|
-
} | undefined | null;
|
|
96
81
|
type Awaitable<T> = T | PromiseLike<T>;
|
|
97
82
|
type Arrayable<T> = T | T[];
|
|
98
83
|
type Promisify<T> = Promise<Awaited<T>>;
|
|
@@ -105,7 +90,7 @@ type IfAny<T, Y, N> = 0 extends 1 & T ? Y : N;
|
|
|
105
90
|
type IsAny<T> = IfAny<T, true, false>;
|
|
106
91
|
type ConstructorType<T = void> = new (...args: any[]) => T;
|
|
107
92
|
type ArgumentsType<T> = T extends ((...args: infer A) => any) ? A : never;
|
|
108
|
-
|
|
93
|
+
type PromiseType<P extends PromiseLike<any>> = P extends PromiseLike<infer T> ? T : never;
|
|
109
94
|
type BrowserNativeObject = Date | FileList | File;
|
|
110
95
|
type Option<L extends Key = 'label', V extends Key = 'value', C extends Key = 'children'> = {
|
|
111
96
|
[P in L]?: string;
|
|
@@ -123,8 +108,28 @@ type PickBy<T, U> = {
|
|
|
123
108
|
type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;
|
|
124
109
|
type Assign<T, U> = Omit<T, keyof U> & U;
|
|
125
110
|
type NonUndefined<T> = T extends undefined ? never : T;
|
|
126
|
-
|
|
127
|
-
|
|
111
|
+
|
|
112
|
+
type DeepReadonly<T> = {
|
|
113
|
+
readonly [P in keyof T]: T[P] extends object ? DeepReadonly<T[P]> : T[P];
|
|
114
|
+
};
|
|
115
|
+
type DeepRequired<T> = {
|
|
116
|
+
[P in keyof T]-?: T[P] extends object ? DeepRequired<T[P]> : T[P];
|
|
117
|
+
};
|
|
118
|
+
type DeepPartial<T> = {
|
|
119
|
+
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
|
|
120
|
+
};
|
|
121
|
+
type DeepReplace<T, K = unknown, V = unknown> = {
|
|
122
|
+
[P in keyof T]: K extends P ? V : DeepReplace<T[P], K, V>;
|
|
123
|
+
};
|
|
124
|
+
type DeepKeyof<T> = T extends object ? keyof T | DeepKeyof<T[keyof T]> : never;
|
|
125
|
+
type MergeInsertions<T> = T extends object ? {
|
|
126
|
+
[K in keyof T]: MergeInsertions<T[K]>;
|
|
127
|
+
} : T;
|
|
128
|
+
type DeepMerge<F, S> = MergeInsertions<{
|
|
129
|
+
[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;
|
|
130
|
+
}>;
|
|
131
|
+
type DeepMap<T, V, ST = BrowserNativeObject> = IsAny<T> extends true ? any : T extends ST ? V : T extends object ? {
|
|
132
|
+
[K in keyof T]: DeepMap<NonUndefined<T[K]>, V, ST>;
|
|
128
133
|
} : V;
|
|
129
134
|
|
|
130
135
|
declare function redirectTo(url: string, target?: string): void;
|
|
@@ -322,16 +327,6 @@ declare function parseNumeric(num: Numberish, delimiters?: Delimiter[]): {
|
|
|
322
327
|
*/
|
|
323
328
|
declare function formatNumeric(value?: Numberish, options?: FormatNumericOptions): string;
|
|
324
329
|
|
|
325
|
-
type Dimension = Numeric | [Numeric, Numeric] | {
|
|
326
|
-
width: Numeric;
|
|
327
|
-
height: Numeric;
|
|
328
|
-
};
|
|
329
|
-
declare function formatUnit(value: Numeric, unit?: string): string;
|
|
330
|
-
declare function formatSize(dimension: Dimension, unit?: string): {
|
|
331
|
-
width: string;
|
|
332
|
-
height: string;
|
|
333
|
-
};
|
|
334
|
-
|
|
335
330
|
/**
|
|
336
331
|
* Intercept front and back characters, hide middle characters
|
|
337
332
|
* @param value
|
|
@@ -339,6 +334,17 @@ declare function formatSize(dimension: Dimension, unit?: string): {
|
|
|
339
334
|
* @param symbol
|
|
340
335
|
*/
|
|
341
336
|
declare function cover(value: string, mode: [number, number, number], symbol?: string): string;
|
|
337
|
+
/**
|
|
338
|
+
* Shortens an identifier string by showing only the beginning and end portions,
|
|
339
|
+
* with ellipsis in the middle. Suitable for various types of identifiers like
|
|
340
|
+
* IPFS CID, transaction hashes, EVM addresses, user IDs, etc.
|
|
341
|
+
*
|
|
342
|
+
* @param value - The identifier string to shorten
|
|
343
|
+
* @param startWith - Number of characters to show at the start (default: 6)
|
|
344
|
+
* @param endWith - Number of characters to show at the end (default: 6)
|
|
345
|
+
* @returns Shortened identifier string with ellipsis, or empty string if id is null/undefined
|
|
346
|
+
*/
|
|
347
|
+
declare function shortenId(value: string | null | undefined, startWith?: number, endWith?: number): string;
|
|
342
348
|
/**
|
|
343
349
|
* Replace backslash to slash
|
|
344
350
|
*
|
|
@@ -402,19 +408,6 @@ declare function template(str: string, ...args: (string | number | bigint | unde
|
|
|
402
408
|
*/
|
|
403
409
|
declare function unindent(str: TemplateStringsArray | string): string;
|
|
404
410
|
|
|
405
|
-
type Typeof = 'string' | 'number' | 'bigint' | 'boolean' | 'symbol' | 'undefined' | 'object' | 'function' | 'null' | 'regexp';
|
|
406
|
-
/**
|
|
407
|
-
* obtain data type
|
|
408
|
-
* @param target Detection object
|
|
409
|
-
*/
|
|
410
|
-
declare function getTypeof(target: any): Typeof;
|
|
411
|
-
/**
|
|
412
|
-
* Detecting data types
|
|
413
|
-
* @param target Detection object
|
|
414
|
-
* @param type Data type
|
|
415
|
-
*/
|
|
416
|
-
declare function isTypeof(target: any, type: Typeof): boolean;
|
|
417
|
-
|
|
418
411
|
type UF$1<VT, RT> = (value: VT) => RT | PromiseLike<RT>;
|
|
419
412
|
type Composed<VT, RT> = (value?: VT) => Promise<RT>;
|
|
420
413
|
/**
|
|
@@ -495,52 +488,69 @@ declare namespace compose {
|
|
|
495
488
|
}
|
|
496
489
|
|
|
497
490
|
/**
|
|
498
|
-
*
|
|
499
|
-
* @param
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
*
|
|
504
|
-
*
|
|
505
|
-
*/
|
|
506
|
-
declare function objectToFormdata(object: Record<string, string | File>): FormData;
|
|
507
|
-
/**
|
|
508
|
-
* Check if a value is not NaN.
|
|
509
|
-
* @param value - The value to check.
|
|
510
|
-
* @returns The value if it is not NaN, otherwise undefined.
|
|
511
|
-
*/
|
|
512
|
-
declare function nonnanable<T>(value: T): T | undefined;
|
|
513
|
-
/**
|
|
514
|
-
* Convert a value to a number.
|
|
515
|
-
* @param value - The value to convert to a number.
|
|
516
|
-
* @returns The number value.
|
|
517
|
-
*/
|
|
518
|
-
declare function numberify(value: any): number;
|
|
519
|
-
/**
|
|
520
|
-
* Convert a value to a string.
|
|
521
|
-
* @param value - The value to convert to a string.
|
|
522
|
-
* @returns The string value.
|
|
523
|
-
*/
|
|
524
|
-
declare function stringify(value: any): string;
|
|
525
|
-
/**
|
|
526
|
-
* Convert a value to a numberish value.
|
|
527
|
-
* @param value - The value to convert to a numberish value.
|
|
528
|
-
* @returns The numberish value.
|
|
491
|
+
* A deferred promise.
|
|
492
|
+
* @param T - The type of the value.
|
|
493
|
+
* @returns The deferred promise.
|
|
494
|
+
* @example
|
|
495
|
+
* ```ts
|
|
496
|
+
* const deferred = new Deferred()
|
|
497
|
+
* deferred.resolve('value')
|
|
529
498
|
*/
|
|
530
|
-
declare function numberish(value: Numberish): string;
|
|
531
|
-
|
|
532
499
|
declare class Deferred<T> extends Promise<T> {
|
|
533
500
|
resolve: (value?: T) => Deferred<T>;
|
|
534
501
|
reject: (reason?: any) => Deferred<T>;
|
|
535
502
|
constructor(executor?: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void);
|
|
536
503
|
}
|
|
537
504
|
|
|
505
|
+
/**
|
|
506
|
+
* Delay for a given number of milliseconds.
|
|
507
|
+
* @param ms - The number of milliseconds to delay.
|
|
508
|
+
* @returns A promise that resolves after the given number of milliseconds.
|
|
509
|
+
* @example
|
|
510
|
+
* ```ts
|
|
511
|
+
* delay(1000).then(() => { console.log('1 second') })
|
|
512
|
+
*/
|
|
538
513
|
declare function delay(ms: number): Promise<void>;
|
|
539
514
|
|
|
540
|
-
declare function
|
|
515
|
+
declare function tryParseJson<T = any>(text: string | undefined | null): T | undefined;
|
|
541
516
|
|
|
517
|
+
/**
|
|
518
|
+
* A function that performs a loop operation with delay control.
|
|
519
|
+
* @template T - The return type of the loop function (defaults to void)
|
|
520
|
+
* @param next - A function that schedules the next iteration after a delay (in milliseconds)
|
|
521
|
+
* @returns A promise that resolves with the result of type T
|
|
522
|
+
*/
|
|
542
523
|
type Looper<T = void> = (next: (ms: number) => Promise<T>) => Promise<T>;
|
|
543
524
|
declare function loop_return<T = void>(fn: Looper<T>): Promise<T>;
|
|
525
|
+
/**
|
|
526
|
+
* Creates a cancellable loop that executes repeatedly with delays.
|
|
527
|
+
* Returns a cancel function that can be called to stop the loop.
|
|
528
|
+
* The loop will not execute further iterations after cancellation.
|
|
529
|
+
*
|
|
530
|
+
* @param fn - The loop function that receives a `next` callback to schedule the next iteration
|
|
531
|
+
* @returns A cancel function that stops the loop when called
|
|
532
|
+
*
|
|
533
|
+
* @example loop
|
|
534
|
+
* ```ts
|
|
535
|
+
* const cancel = loop(async (next) => {
|
|
536
|
+
* console.log('tick')
|
|
537
|
+
* await next(1000) // Wait 1 second before next iteration
|
|
538
|
+
* })
|
|
539
|
+
*
|
|
540
|
+
* // Stop the loop after 5 seconds
|
|
541
|
+
* setTimeout(cancel, 5000)
|
|
542
|
+
*```
|
|
543
|
+
* @example loop.return
|
|
544
|
+
* ```ts
|
|
545
|
+
* const result = await loop.return(async (next) => {
|
|
546
|
+
* if (condition) {
|
|
547
|
+
* return 'done'
|
|
548
|
+
* }
|
|
549
|
+
* await next(1000)
|
|
550
|
+
* })
|
|
551
|
+
* console.log(result)
|
|
552
|
+
* ```
|
|
553
|
+
*/
|
|
544
554
|
declare function loop(fn: Looper<void>): Fn$1;
|
|
545
555
|
declare namespace loop {
|
|
546
556
|
var _a: typeof loop_return;
|
|
@@ -585,7 +595,8 @@ declare function pPipe<VT, R1, R2, R3, R4, R5, R6, R7, R8, RT>(f1: UF<VT, R1>, f
|
|
|
585
595
|
* TypeScript, because it doesn't support **Variadic Kinds** and we explicitly
|
|
586
596
|
* have to define the type of all the possible usages as method overloads.
|
|
587
597
|
*
|
|
588
|
-
* @example
|
|
598
|
+
* @example pipe
|
|
599
|
+
*
|
|
589
600
|
* const normalizeWhiteSpaces = text => name.replace(/\s+/g, ' ').trim();
|
|
590
601
|
*
|
|
591
602
|
* const getInitials = pipe(
|
|
@@ -600,7 +611,7 @@ declare function pPipe<VT, R1, R2, R3, R4, R5, R6, R7, R8, RT>(f1: UF<VT, R1>, f
|
|
|
600
611
|
* @param fn - An arity N function. Its result is the argument of next one.
|
|
601
612
|
* @param fns - Functions of arity 1. Each one's result is next's argument.
|
|
602
613
|
*
|
|
603
|
-
* @example
|
|
614
|
+
* @example pipe.promise
|
|
604
615
|
*
|
|
605
616
|
* const addUnicorn = async string => `${string} Unicorn`;
|
|
606
617
|
* const addRainbow = async string => `${string} Rainbow`;
|
|
@@ -626,26 +637,186 @@ declare namespace pipe {
|
|
|
626
637
|
var promise: typeof pPipe;
|
|
627
638
|
}
|
|
628
639
|
|
|
629
|
-
|
|
630
|
-
proxy:
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
640
|
+
type Proxyed<T extends object, E extends object = {}> = T & {
|
|
641
|
+
proxy: {
|
|
642
|
+
update: (object?: T) => void;
|
|
643
|
+
source: T | undefined;
|
|
644
|
+
};
|
|
645
|
+
} & E;
|
|
646
|
+
/**
|
|
647
|
+
* Creates a proxy object that updates the original object when the proxy is updated.
|
|
648
|
+
* @param initObject - The initial object to proxy.
|
|
649
|
+
* @returns The proxy object.
|
|
650
|
+
*
|
|
651
|
+
* @example
|
|
652
|
+
* ```ts
|
|
653
|
+
* const obj = proxy({ name: 'John' })
|
|
654
|
+
* console.log(obj.name) // John
|
|
655
|
+
*
|
|
656
|
+
* obj.proxy.update({ name: 'Jane' })
|
|
657
|
+
* console.log(obj.name) // Jane
|
|
658
|
+
*
|
|
659
|
+
* const obj2 = proxy()
|
|
660
|
+
*
|
|
661
|
+
* obj2.any // Error: Proxy not updated. Call object.proxy.update() to update the proxy.
|
|
662
|
+
*
|
|
663
|
+
* obj2.proxy.source // undefined
|
|
664
|
+
* obj2.update({ name: 'John' })
|
|
665
|
+
*
|
|
666
|
+
* // get the original object
|
|
667
|
+
* obj2.proxy.source // { name: 'John' }
|
|
668
|
+
* ```
|
|
669
|
+
*/
|
|
670
|
+
declare function proxy<T extends object, E extends object = {}>(initObject?: T, initExtend?: E, options?: {
|
|
671
|
+
strictMessage?: string;
|
|
672
|
+
}): Proxyed<T, E>;
|
|
636
673
|
|
|
637
|
-
|
|
674
|
+
/**
|
|
675
|
+
* Get a random item from an array.
|
|
676
|
+
* @param array - The array to get a random item from.
|
|
677
|
+
* @returns The random item.
|
|
678
|
+
* @example
|
|
679
|
+
* ```ts
|
|
680
|
+
* randomItem(['a', 'b', 'c']) // 'a' | 'b' | 'c'
|
|
681
|
+
*/
|
|
682
|
+
declare function randomItem<T>(array: T[]): T;
|
|
683
|
+
/**
|
|
684
|
+
* Get a random number between a minimum and maximum value.
|
|
685
|
+
* @param min - The minimum value.
|
|
686
|
+
* @param max - The maximum value.
|
|
687
|
+
* @returns The random number.
|
|
688
|
+
* @example
|
|
689
|
+
* ```ts
|
|
690
|
+
* randomNumber(0, 100) // 0-100
|
|
691
|
+
*/
|
|
638
692
|
declare function randomNumber(min: number, max: number): number;
|
|
639
|
-
|
|
693
|
+
/**
|
|
694
|
+
* Get a random string of a given size.
|
|
695
|
+
* @param size - The size of the string.
|
|
696
|
+
* @param chars - The characters to use in the string.
|
|
697
|
+
* @returns The random string.
|
|
698
|
+
* @example
|
|
699
|
+
* ```ts
|
|
700
|
+
* randomString() // 10 characters long
|
|
701
|
+
* randomString(20) // 20 characters long
|
|
702
|
+
* randomString(20, 'abcdefghijklmnopqrstuvwxyz') // 20 characters long
|
|
703
|
+
*/
|
|
704
|
+
declare function randomString(size?: number, chars?: string): string;
|
|
705
|
+
|
|
706
|
+
/**
|
|
707
|
+
* formData to object
|
|
708
|
+
* @param formData
|
|
709
|
+
*/
|
|
710
|
+
declare function formdataToObject(formData: FormData): Record<string, string>;
|
|
711
|
+
/**
|
|
712
|
+
* Object to formData
|
|
713
|
+
* @param object
|
|
714
|
+
*/
|
|
715
|
+
declare function objectToFormdata(object: Record<string, string | File>): FormData;
|
|
716
|
+
/**
|
|
717
|
+
* Check if a value is not NaN.
|
|
718
|
+
* @param value - The value to check.
|
|
719
|
+
* @returns The value if it is not NaN, otherwise undefined.
|
|
720
|
+
*/
|
|
721
|
+
declare function nonnanable<T>(value: T): T | undefined;
|
|
722
|
+
/**
|
|
723
|
+
* Convert a value to a number.
|
|
724
|
+
* @param value - The value to convert to a number.
|
|
725
|
+
* @returns The number value.
|
|
726
|
+
*/
|
|
727
|
+
declare function numberify(value: any): number;
|
|
728
|
+
/**
|
|
729
|
+
* Convert a value to a string.
|
|
730
|
+
* @param value - The value to convert to a string.
|
|
731
|
+
* @returns The string value.
|
|
732
|
+
*/
|
|
733
|
+
declare function stringify(value: any): string;
|
|
734
|
+
/**
|
|
735
|
+
* Convert a value to a numberish value.
|
|
736
|
+
* @param value - The value to convert to a numberish value.
|
|
737
|
+
* @returns The numberish value.
|
|
738
|
+
*/
|
|
739
|
+
declare function numberish(value: Numberish): string;
|
|
640
740
|
|
|
741
|
+
/**
|
|
742
|
+
* Convert a promise to a tuple of [error, data].
|
|
743
|
+
* @param promise - The promise to convert.
|
|
744
|
+
* @param error - The error to return if the promise fails.
|
|
745
|
+
* @returns The tuple of [error, data].
|
|
746
|
+
* @example
|
|
747
|
+
* ```ts
|
|
748
|
+
* to(Promise.resolve('data')) // Promise<[null, 'data']>
|
|
749
|
+
* to(Promise.reject(new Error('error'))) // Promise<[Error, undefined]>
|
|
750
|
+
*/
|
|
641
751
|
declare function to<T, U = Error>(promise: Promise<T> | (() => Promise<T>), error?: object): Promise<[U, undefined] | [null, T]>;
|
|
642
752
|
|
|
643
|
-
|
|
753
|
+
/**
|
|
754
|
+
* Convert a value to an array.
|
|
755
|
+
* @param value - The value to convert.
|
|
756
|
+
* @param required - Whether the array is required.
|
|
757
|
+
* @returns The array.
|
|
758
|
+
* @example
|
|
759
|
+
* ```ts
|
|
760
|
+
* toArray(arrorOrItemOrUndefined) // item[] | undefined
|
|
761
|
+
* toArray(arrayOrItemOrUndefined, true) // item[]
|
|
762
|
+
*/
|
|
763
|
+
declare function toArray<T, R extends boolean>(value?: T | T[], required?: R): R extends true ? T[] : T[] | undefined;
|
|
764
|
+
|
|
765
|
+
type Dimension = Numeric | [Numeric, Numeric] | {
|
|
766
|
+
width: Numeric;
|
|
767
|
+
height: Numeric;
|
|
768
|
+
};
|
|
769
|
+
declare function unit(value: Numeric, unit?: string): string;
|
|
770
|
+
declare function size(dimension: Dimension, unit?: string): {
|
|
771
|
+
width: string;
|
|
772
|
+
height: string;
|
|
773
|
+
};
|
|
644
774
|
|
|
645
|
-
|
|
646
|
-
declare
|
|
775
|
+
/** @deprecated Use range instead */
|
|
776
|
+
declare const arange: {
|
|
777
|
+
(start: number, end?: number, step?: number): number[];
|
|
778
|
+
(end: number, index: string | number, guard: object): number[];
|
|
779
|
+
};
|
|
780
|
+
/**
|
|
781
|
+
* Select a value based on a condition.
|
|
782
|
+
* @param args - The arguments to select from.
|
|
783
|
+
* @returns The selected value.
|
|
784
|
+
* @example
|
|
785
|
+
* ```ts
|
|
786
|
+
* select(
|
|
787
|
+
* [condition1, value],
|
|
788
|
+
* [condition2, value2],
|
|
789
|
+
* // default value
|
|
790
|
+
* [true, value3],
|
|
791
|
+
* ...
|
|
792
|
+
* ) // value
|
|
793
|
+
* ```
|
|
794
|
+
*/
|
|
795
|
+
declare function select<T>(...args: [cond: boolean, value: T][]): T;
|
|
796
|
+
/**
|
|
797
|
+
* @deprecated Use select instead
|
|
798
|
+
*/
|
|
799
|
+
declare const riposte: typeof select;
|
|
800
|
+
/**
|
|
801
|
+
* Unwrap a value or a function that returns a value.
|
|
802
|
+
* @param value - The value or function to unwrap.
|
|
803
|
+
* @returns The unwrapped value.
|
|
804
|
+
* @example
|
|
805
|
+
* ```ts
|
|
806
|
+
* unwrap({ name: 'John' }) // { name: 'John' }
|
|
807
|
+
* unwrap(() => { return { name: 'John' } }) // { name: 'John' }
|
|
808
|
+
*/
|
|
647
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
|
+
*/
|
|
648
819
|
declare function whenever<T, C extends (value: Exclude<T, null | undefined>) => any>(value: T, callback: C): ReturnType<C> | undefined;
|
|
649
820
|
declare function call<T extends Fn$1<any>>(fn: T, ...args: Parameters<T>): ReturnType<T>;
|
|
650
821
|
|
|
651
|
-
export { type AnyFn, type ArgumentsType, type Arrayable, type Assign, type Awaitable, BIG_INTS, Bignumber, type BooleanLike, type BrowserNativeObject, type ConstructorType, DEFAULT_BIGNUM_CONFIG, type DecimalOptions, type DeepKeyof, type DeepMap, type DeepMerge, type DeepPartial, type DeepReadonly, type DeepReplace, type DeepRequired, Deferred, type Delimiter, type Dimension, type DynamicObject, type ElementOf, type Fn$1 as Fn, type FormatGroupOptions, type FormatNumericOptions, type IfAny, type IsAny, type Key, type Looper, type MergeInsertions, type NonUndefined, type Noop, type Nullable, type NumberObject, type Numberish, type Numeric, type NumericObject, type OmitBy, type OpenFilePickerOptions, type OpenImagePickerOptions, type Option, type Overwrite, type PickBy, type PromiseFn, type PromiseType, type Promisify, type
|
|
822
|
+
export { type AnyFn, type ArgumentsType, type Arrayable, type Assign, type Awaitable, BIG_INTS, Bignumber, type BooleanLike, type BrowserNativeObject, type ConstructorType, DEFAULT_BIGNUM_CONFIG, type DecimalOptions, type DeepKeyof, type DeepMap, type DeepMerge, type DeepPartial, type DeepReadonly, type DeepReplace, type DeepRequired, Deferred, type Delimiter, type Dimension, type DynamicObject, type ElementOf, type Fn$1 as Fn, type FormatGroupOptions, type FormatNumericOptions, type IfAny, type IsAny, type Key, type Looper, type MergeInsertions, type NonUndefined, type Noop, type Nullable, type NumberObject, type Numberish, type Numeric, type NumericObject, type OmitBy, type OpenFilePickerOptions, type OpenImagePickerOptions, type Option, type Overwrite, type PickBy, type PromiseFn, type PromiseType, type Promisify, type Proxyed, type ReaderType, type StringObject, type SymbolObject, arange, average, bignumber, call, camelCase, capitalCase, compose, constantCase, cover, decimal, delay, dialsPhone, divide, dotCase, downloadBlobFile, downloadNetworkFile, downloadUrlFile, ensurePrefix, ensureSuffix, formatNumeric, formdataToObject, gt, gte, integer, isAndroid, isBrowser, isChrome, isEdge, isFF, isFormData, isIE, isIE11, isIE9, isIOS, isMobile, isPhantomJS, isTruthy, isWeex, isWindow, kebabCase, loop, lt, lte, multiply, noCase, nonnanable, noop, numberify, numberish, objectToFormdata, off, on, openFilePicker, openImagePicker, parseNumeric, pascalCase, pascalSnakeCase, pathCase, percentage, pipe, plus, proxy, randomItem, randomNumber, randomString, readFileReader, redirectTo, riposte, select, selectImages, sentenceCase, shortenId, showOpenFilePicker, showOpenImagePicker, size, slash, snakeCase, stringify, template, to, toArray, trainCase, tryParseJson, unindent, unit, unwrap, whenever, zeroRemove, zerofill };
|