@hairy/utils 0.6.9 → 0.6.11
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 +1687 -104
- package/dist/index.d.ts +121 -18
- package/dist/index.mjs +1660 -115
- package/package.json +2 -7
- package/src/index.ts +0 -6
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import _pPipe from 'p-pipe';
|
|
2
|
+
import Bignumber from 'bignumber.js';
|
|
3
|
+
export { default as Bignumber } from 'bignumber.js';
|
|
3
4
|
|
|
4
5
|
declare const isBrowser: () => boolean;
|
|
5
6
|
declare const isWeex: () => boolean;
|
|
@@ -14,7 +15,15 @@ declare const isIOS: () => boolean;
|
|
|
14
15
|
declare const isChrome: () => boolean | "";
|
|
15
16
|
declare const isPhantomJS: () => boolean | "";
|
|
16
17
|
declare const isFF: () => false | RegExpMatchArray | null;
|
|
17
|
-
declare const isMobile: () => boolean;
|
|
18
|
+
declare const isMobile: () => boolean;
|
|
19
|
+
declare const isObject: (value: any) => value is object;
|
|
20
|
+
declare const isNumber: (value: any) => boolean;
|
|
21
|
+
declare const isString: (value: any) => boolean;
|
|
22
|
+
declare const isArray: (value: any) => value is any[];
|
|
23
|
+
declare const isNull: (value: any) => value is null;
|
|
24
|
+
declare const isPlainObject: (value: any) => boolean;
|
|
25
|
+
declare const isFormData: (value: any) => value is FormData;
|
|
26
|
+
declare const isWindow: (value: any) => value is Window;
|
|
18
27
|
|
|
19
28
|
/**
|
|
20
29
|
* 将 formData 转换为 object
|
|
@@ -25,10 +34,7 @@ declare function formDataToObject(formData: FormData): Record<string, string>;
|
|
|
25
34
|
* 将 object 转换为 formData
|
|
26
35
|
* @param object
|
|
27
36
|
*/
|
|
28
|
-
declare function objectToFormData(object: Record<string, string | File>): FormData;
|
|
29
|
-
declare function isFormData(value: any): value is FormData;
|
|
30
|
-
declare function isWindow(value: any): value is Window;
|
|
31
|
-
declare function isObject(value: any): value is object;
|
|
37
|
+
declare function objectToFormData(object: Record<string, string | File>): FormData;
|
|
32
38
|
|
|
33
39
|
type Numeric = string | number | bigint;
|
|
34
40
|
type DynamicObject = {
|
|
@@ -98,19 +104,116 @@ declare function getTypeof(target: any): TypeofType;
|
|
|
98
104
|
*/
|
|
99
105
|
declare function isTypeof(target: any, type: TypeofType): boolean;
|
|
100
106
|
|
|
101
|
-
|
|
102
|
-
resolve: (value: T) =>
|
|
103
|
-
reject: (
|
|
107
|
+
declare class Deferred<T> extends Promise<T> {
|
|
108
|
+
resolve: (value: T) => Deferred<T>;
|
|
109
|
+
reject: (reason?: any) => Deferred<T>;
|
|
110
|
+
constructor();
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
declare const pPipe: typeof _pPipe;
|
|
114
|
+
declare const pipe: (...fns: any[]) => any;
|
|
115
|
+
declare const compose: (...fns: any[]) => any;
|
|
116
|
+
|
|
117
|
+
declare function noop(): any;
|
|
118
|
+
declare function delay(ms: number): Promise<unknown>;
|
|
119
|
+
declare function arange(x1: number, x2?: number, stp?: number, z?: number[], z0?: number): number[];
|
|
120
|
+
declare function whenever<T, C extends (value: Exclude<T, null | undefined>) => any>(value: T, callback: C): ReturnType<C> | undefined;
|
|
121
|
+
declare function loop<T = void>(fn: (next: (ms: number) => Promise<T>) => Promise<T>): Promise<T>;
|
|
122
|
+
declare function riposte<T>(...args: [cond: boolean, value: T][]): T;
|
|
123
|
+
|
|
124
|
+
declare const BIG_INTS: {
|
|
125
|
+
t: {
|
|
126
|
+
v: number;
|
|
127
|
+
d: number;
|
|
128
|
+
n: string;
|
|
129
|
+
};
|
|
130
|
+
b: {
|
|
131
|
+
v: number;
|
|
132
|
+
d: number;
|
|
133
|
+
n: string;
|
|
134
|
+
};
|
|
135
|
+
m: {
|
|
136
|
+
v: number;
|
|
137
|
+
d: number;
|
|
138
|
+
n: string;
|
|
139
|
+
};
|
|
140
|
+
k: {
|
|
141
|
+
v: number;
|
|
142
|
+
d: number;
|
|
143
|
+
n: string;
|
|
144
|
+
};
|
|
104
145
|
};
|
|
105
|
-
|
|
146
|
+
/**
|
|
147
|
+
* Any type that can be used where a big number is needed.
|
|
148
|
+
*/
|
|
149
|
+
type Numberish = Numeric | {
|
|
150
|
+
toString: (...args: any[]) => string;
|
|
151
|
+
};
|
|
152
|
+
type Delimiter = 'k' | 'm' | 'b' | 't';
|
|
153
|
+
interface DecimalOptions {
|
|
154
|
+
d?: number;
|
|
155
|
+
r?: Bignumber.RoundingMode;
|
|
156
|
+
}
|
|
157
|
+
interface FormatGroupOptions {
|
|
158
|
+
size?: number;
|
|
159
|
+
symbol?: string;
|
|
160
|
+
}
|
|
161
|
+
interface FormatNumericOptions {
|
|
162
|
+
delimiters?: Delimiter[] | false;
|
|
163
|
+
rounding?: Bignumber.RoundingMode;
|
|
164
|
+
decimals?: number;
|
|
165
|
+
format?: Bignumber.Format;
|
|
166
|
+
}
|
|
167
|
+
declare function unum(num?: Numeric): Bignumber;
|
|
168
|
+
declare function gte(num: Numeric, n: Numeric): boolean;
|
|
169
|
+
declare function gt(num: Numeric, n: Numeric): boolean;
|
|
170
|
+
declare function lte(num: Numeric, n: Numeric): boolean;
|
|
171
|
+
declare function lt(num: Numeric, n: Numeric): boolean;
|
|
172
|
+
declare function plus(array: Numeric[], options?: DecimalOptions): string;
|
|
173
|
+
declare function average(array: Numeric[], options?: DecimalOptions): string;
|
|
174
|
+
/**
|
|
175
|
+
* calculate percentage
|
|
176
|
+
* @param total
|
|
177
|
+
* @param count
|
|
178
|
+
*/
|
|
179
|
+
declare function percentage(total: Numeric, count: Numeric, options?: DecimalOptions): string;
|
|
180
|
+
/**
|
|
181
|
+
* leading zeros
|
|
182
|
+
* @param number_
|
|
183
|
+
* @param lh
|
|
184
|
+
*/
|
|
185
|
+
declare function zerofill(value: Numberish, n?: number, type?: 'positive' | 'reverse'): Numberish;
|
|
186
|
+
declare function numerfix(value: any): string;
|
|
187
|
+
/**
|
|
188
|
+
* format as a positive integer
|
|
189
|
+
* @param value
|
|
190
|
+
*/
|
|
191
|
+
declare function integer(value: Numberish): string;
|
|
192
|
+
/**
|
|
193
|
+
* retain n decimal places
|
|
194
|
+
* @param value
|
|
195
|
+
* @param n
|
|
196
|
+
*/
|
|
197
|
+
declare function decimal(value: Numberish, n?: number): string;
|
|
198
|
+
declare function parseNumeric(num: Numeric, delimiters?: Delimiter[]): {
|
|
199
|
+
v: number;
|
|
200
|
+
d: number;
|
|
201
|
+
n: string;
|
|
202
|
+
};
|
|
203
|
+
/**
|
|
204
|
+
* format number thousand separator and unit
|
|
205
|
+
* @param value
|
|
206
|
+
* @param options
|
|
207
|
+
* @returns
|
|
208
|
+
*/
|
|
209
|
+
declare function formatNumeric(value?: Numeric, options?: FormatNumericOptions): string;
|
|
106
210
|
|
|
107
211
|
/**
|
|
108
|
-
*
|
|
109
|
-
*
|
|
212
|
+
* Intercept front and back characters, hide middle characters
|
|
213
|
+
* @param value
|
|
214
|
+
* @param mode
|
|
215
|
+
* @param symbol
|
|
110
216
|
*/
|
|
111
|
-
declare function
|
|
112
|
-
declare const pipe: (...fns: any[]) => any;
|
|
113
|
-
declare const compose: (...fns: any[]) => any;
|
|
114
|
-
declare function whenever<T, C extends (value: Exclude<T, null | undefined>) => any>(value: T, callback: C): ReturnType<C> | undefined;
|
|
217
|
+
declare function cover(value: string, mode: [number, number, number], symbol?: string): string;
|
|
115
218
|
|
|
116
|
-
export { Arrayable, Awaitable, BooleanLike, DeepKeyof, DeepPartial, DeepReadonly, DeepReplace, DeepRequired, Deferred, Dimension, DynamicObject, Key, NumberObject, Numeric, NumericObject, Option, StringObject, SymbolObject, TypeofType, UA, arange, compose,
|
|
219
|
+
export { Arrayable, Awaitable, BIG_INTS, BooleanLike, DecimalOptions, DeepKeyof, DeepPartial, DeepReadonly, DeepReplace, DeepRequired, Deferred, Delimiter, Dimension, DynamicObject, FormatGroupOptions, FormatNumericOptions, Key, NumberObject, Numberish, Numeric, NumericObject, Option, StringObject, SymbolObject, TypeofType, UA, arange, average, compose, cover, decimal, delay, formDataToObject, formatNumeric, formatSize, formatUnit, getTypeof, gt, gte, integer, isAndroid, isArray, isBrowser, isChrome, isEdge, isFF, isFormData, isIE, isIE11, isIE9, isIOS, isMobile, isNull, isNumber, isObject, isPhantomJS, isPlainObject, isString, isTypeof, isWeex, isWindow, loop, lt, lte, noop, numerfix, objectToFormData, pPipe, parseNumeric, percentage, pipe, plus, riposte, unum, weexPlatform, whenever, zerofill };
|