@hairy/utils 1.6.0 → 1.6.1
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/package.json +2 -2
- package/dist/index.d.ts +0 -248
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hairy/utils",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.6.
|
|
4
|
+
"version": "1.6.1",
|
|
5
5
|
"description": "Library for anywhere",
|
|
6
6
|
"author": "Hairyf <wwu710632@gmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -22,11 +22,11 @@
|
|
|
22
22
|
"dist"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
+
"@types/lodash-es": "^4.17.12",
|
|
25
26
|
"bignumber.js": "^9.1.2",
|
|
26
27
|
"p-pipe": "^4.0.0"
|
|
27
28
|
},
|
|
28
29
|
"devDependencies": {
|
|
29
|
-
"@types/lodash-es": "^4.17.12",
|
|
30
30
|
"change-case": "^5.4.4",
|
|
31
31
|
"lodash-es": "^4.17.21"
|
|
32
32
|
},
|
package/dist/index.d.ts
DELETED
|
@@ -1,248 +0,0 @@
|
|
|
1
|
-
export { camelCase, capitalCase, constantCase, dotCase, kebabCase, noCase, pascalCase, pascalSnakeCase, pathCase, sentenceCase, snakeCase, trainCase } from 'change-case';
|
|
2
|
-
export { clone, cloneDeep, concat, debounce, find, isArray, isArrayLike, isBoolean, isDate, isEmpty, isEqual, isError, isFunction, isNaN, isNative, isNull, isNumber, isObject, isPlainObject, isString, isUndefined, join, keys, truncate, uniq, uniqBy, values } from 'lodash-es';
|
|
3
|
-
import Bignumber from 'bignumber.js';
|
|
4
|
-
export { default as Bignumber } from 'bignumber.js';
|
|
5
|
-
|
|
6
|
-
type Numeric = string | number | bigint;
|
|
7
|
-
interface DynamicObject {
|
|
8
|
-
[key: string]: any;
|
|
9
|
-
}
|
|
10
|
-
interface NumericObject {
|
|
11
|
-
[key: string]: Numeric;
|
|
12
|
-
}
|
|
13
|
-
interface StringObject {
|
|
14
|
-
[key: string]: string;
|
|
15
|
-
}
|
|
16
|
-
interface NumberObject {
|
|
17
|
-
[key: string]: string;
|
|
18
|
-
}
|
|
19
|
-
interface SymbolObject {
|
|
20
|
-
[key: string]: symbol;
|
|
21
|
-
}
|
|
22
|
-
type Key = string | number | symbol;
|
|
23
|
-
type BooleanLike = any;
|
|
24
|
-
type Noop = (...args: any[]) => any;
|
|
25
|
-
|
|
26
|
-
type DeepReadonly<T> = {
|
|
27
|
-
readonly [P in keyof T]: T[P] extends object ? DeepReadonly<T[P]> : T[P];
|
|
28
|
-
};
|
|
29
|
-
type DeepRequired<T> = {
|
|
30
|
-
[P in keyof T]-?: T[P] extends object ? DeepRequired<T[P]> : T[P];
|
|
31
|
-
};
|
|
32
|
-
type DeepPartial<T> = {
|
|
33
|
-
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
|
|
34
|
-
};
|
|
35
|
-
type DeepReplace<T, K = unknown, V = unknown> = {
|
|
36
|
-
[P in keyof T]: K extends P ? V : DeepReplace<T[P], K, V>;
|
|
37
|
-
};
|
|
38
|
-
type DeepKeyof<T> = T extends object ? keyof T | DeepKeyof<T[keyof T]> : never;
|
|
39
|
-
|
|
40
|
-
type Awaitable<T> = T | Promise<T>;
|
|
41
|
-
type Arrayable<T> = T | T[];
|
|
42
|
-
type Option<L extends Key = 'label', V extends Key = 'value', C extends Key = 'children'> = {
|
|
43
|
-
[P in L]?: string;
|
|
44
|
-
} & {
|
|
45
|
-
[P in V]?: Numeric;
|
|
46
|
-
} & {
|
|
47
|
-
[P in C]?: Option<L, V, C>[];
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
declare const BIG_INTS: {
|
|
51
|
-
t: {
|
|
52
|
-
v: number;
|
|
53
|
-
d: number;
|
|
54
|
-
n: string;
|
|
55
|
-
};
|
|
56
|
-
b: {
|
|
57
|
-
v: number;
|
|
58
|
-
d: number;
|
|
59
|
-
n: string;
|
|
60
|
-
};
|
|
61
|
-
m: {
|
|
62
|
-
v: number;
|
|
63
|
-
d: number;
|
|
64
|
-
n: string;
|
|
65
|
-
};
|
|
66
|
-
k: {
|
|
67
|
-
v: number;
|
|
68
|
-
d: number;
|
|
69
|
-
n: string;
|
|
70
|
-
};
|
|
71
|
-
};
|
|
72
|
-
/**
|
|
73
|
-
* Any type that can be used where a big number is needed.
|
|
74
|
-
*/
|
|
75
|
-
type Numberish = Numeric | {
|
|
76
|
-
toString: (...args: any[]) => string;
|
|
77
|
-
};
|
|
78
|
-
type Delimiter = 'k' | 'm' | 'b' | 't';
|
|
79
|
-
interface DecimalOptions {
|
|
80
|
-
d?: number;
|
|
81
|
-
r?: Bignumber.RoundingMode;
|
|
82
|
-
}
|
|
83
|
-
interface FormatGroupOptions {
|
|
84
|
-
size?: number;
|
|
85
|
-
symbol?: string;
|
|
86
|
-
}
|
|
87
|
-
interface FormatNumericOptions {
|
|
88
|
-
delimiters?: Delimiter[] | false;
|
|
89
|
-
rounding?: Bignumber.RoundingMode;
|
|
90
|
-
decimals?: number;
|
|
91
|
-
zeromove?: boolean;
|
|
92
|
-
format?: Bignumber.Format;
|
|
93
|
-
}
|
|
94
|
-
declare function unum(num?: Numeric): Bignumber;
|
|
95
|
-
declare function gte(num: Numeric, n: Numeric): boolean;
|
|
96
|
-
declare function gt(num: Numeric, n: Numeric): boolean;
|
|
97
|
-
declare function lte(num: Numeric, n: Numeric): boolean;
|
|
98
|
-
declare function lt(num: Numeric, n: Numeric): boolean;
|
|
99
|
-
declare function plus(array: Numeric[], options?: DecimalOptions): string;
|
|
100
|
-
declare function average(array: Numeric[], options?: DecimalOptions): string;
|
|
101
|
-
/**
|
|
102
|
-
* calculate percentage
|
|
103
|
-
* @param total
|
|
104
|
-
* @param count
|
|
105
|
-
*/
|
|
106
|
-
declare function percentage(total: Numeric, count: Numeric, options?: DecimalOptions): string;
|
|
107
|
-
/**
|
|
108
|
-
* leading zeros
|
|
109
|
-
* @param value
|
|
110
|
-
* @param n
|
|
111
|
-
* @param type
|
|
112
|
-
*/
|
|
113
|
-
declare function zerofill(value: Numberish, n?: number, type?: 'positive' | 'reverse'): Numberish;
|
|
114
|
-
declare function zeromove(value: Numberish): string;
|
|
115
|
-
declare function numerfix(value: any): string;
|
|
116
|
-
/**
|
|
117
|
-
* format as a positive integer
|
|
118
|
-
* @param value
|
|
119
|
-
*/
|
|
120
|
-
declare function integer(value: Numberish): string;
|
|
121
|
-
/**
|
|
122
|
-
* retain n decimal places
|
|
123
|
-
* @param value
|
|
124
|
-
* @param n
|
|
125
|
-
*/
|
|
126
|
-
declare function decimal(value: Numberish, n?: number): string;
|
|
127
|
-
declare function parseNumeric(num: Numeric, delimiters?: Delimiter[]): {
|
|
128
|
-
v: number;
|
|
129
|
-
d: number;
|
|
130
|
-
n: string;
|
|
131
|
-
};
|
|
132
|
-
/**
|
|
133
|
-
* format number thousand separator and unit
|
|
134
|
-
* @param value
|
|
135
|
-
* @param options
|
|
136
|
-
* @returns
|
|
137
|
-
*/
|
|
138
|
-
declare function formatNumeric(value?: Numeric, options?: FormatNumericOptions): string;
|
|
139
|
-
|
|
140
|
-
type Dimension = Numeric | [Numeric, Numeric] | {
|
|
141
|
-
width: Numeric;
|
|
142
|
-
height: Numeric;
|
|
143
|
-
};
|
|
144
|
-
declare function formatUnit(value: Numeric, unit?: string): string;
|
|
145
|
-
declare function formatSize(dimension: Dimension, unit?: string): {
|
|
146
|
-
width: string;
|
|
147
|
-
height: string;
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* Intercept front and back characters, hide middle characters
|
|
152
|
-
* @param value
|
|
153
|
-
* @param mode
|
|
154
|
-
* @param symbol
|
|
155
|
-
*/
|
|
156
|
-
declare function cover(value: string, mode: [number, number, number], symbol?: string): string;
|
|
157
|
-
|
|
158
|
-
type Typeof = 'string' | 'number' | 'bigint' | 'boolean' | 'symbol' | 'undefined' | 'object' | 'function' | 'null' | 'regexp';
|
|
159
|
-
/**
|
|
160
|
-
* obtain data type
|
|
161
|
-
* @param target Detection object
|
|
162
|
-
*/
|
|
163
|
-
declare function getTypeof(target: any): Typeof;
|
|
164
|
-
/**
|
|
165
|
-
* Detecting data types
|
|
166
|
-
* @param target Detection object
|
|
167
|
-
* @param type Data type
|
|
168
|
-
*/
|
|
169
|
-
declare function isTypeof(target: any, type: Typeof): boolean;
|
|
170
|
-
|
|
171
|
-
declare const compose: (...fns: any[]) => any;
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* formData to object
|
|
175
|
-
* @param formData
|
|
176
|
-
*/
|
|
177
|
-
declare function formToObject(formData: FormData): Record<string, string>;
|
|
178
|
-
/**
|
|
179
|
-
* Object to formData
|
|
180
|
-
* @param object
|
|
181
|
-
*/
|
|
182
|
-
declare function objectToForm(object: Record<string, string | File>): FormData;
|
|
183
|
-
|
|
184
|
-
declare class Deferred<T> extends Promise<T> {
|
|
185
|
-
resolve: (value: T) => Deferred<T>;
|
|
186
|
-
reject: (reason?: any) => Deferred<T>;
|
|
187
|
-
constructor();
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
declare function delay(ms: number): Promise<void>;
|
|
191
|
-
|
|
192
|
-
declare const isBrowser: () => boolean;
|
|
193
|
-
declare const isWeex: () => boolean;
|
|
194
|
-
declare const isIE: () => boolean | "";
|
|
195
|
-
declare const isIE9: () => boolean | "";
|
|
196
|
-
declare const isIE11: () => boolean;
|
|
197
|
-
declare const isEdge: () => boolean | "";
|
|
198
|
-
declare const isAndroid: () => boolean;
|
|
199
|
-
declare const isIOS: () => boolean;
|
|
200
|
-
declare const isChrome: () => boolean | "";
|
|
201
|
-
declare const isPhantomJS: () => boolean | "";
|
|
202
|
-
declare const isFF: () => false | RegExpMatchArray | null;
|
|
203
|
-
declare const isMobile: () => boolean;
|
|
204
|
-
declare const isFormData: (value: any) => value is FormData;
|
|
205
|
-
declare const isWindow: (value: any) => value is Window;
|
|
206
|
-
|
|
207
|
-
declare const noop: (...args: any) => any;
|
|
208
|
-
|
|
209
|
-
type UnaryFunction<ValueType, ReturnType> = (value: ValueType) => ReturnType | PromiseLike<ReturnType>;
|
|
210
|
-
type Pipeline<ValueType, ReturnType> = (value?: ValueType) => Promise<ReturnType>;
|
|
211
|
-
/**
|
|
212
|
-
Compose promise-returning & async functions into a reusable pipeline.
|
|
213
|
-
|
|
214
|
-
@param ...input - Iterated over sequentially when returned `function` is called.
|
|
215
|
-
@returns The `input` functions are applied from left to right.
|
|
216
|
-
|
|
217
|
-
@example
|
|
218
|
-
```
|
|
219
|
-
import { pPipe } from '@hairy/utils';
|
|
220
|
-
|
|
221
|
-
const addUnicorn = async string => `${string} Unicorn`;
|
|
222
|
-
const addRainbow = async string => `${string} Rainbow`;
|
|
223
|
-
|
|
224
|
-
const pipeline = pPipe(addUnicorn, addRainbow);
|
|
225
|
-
|
|
226
|
-
console.log(await pipeline('❤️'));
|
|
227
|
-
//=> '❤️ Unicorn Rainbow'
|
|
228
|
-
```
|
|
229
|
-
*/
|
|
230
|
-
declare function pPipe<ValueType, ReturnType>(f1: UnaryFunction<ValueType, ReturnType>): Pipeline<ValueType, ReturnType>;
|
|
231
|
-
declare function pPipe<ValueType, ResultValue1, ReturnType>(f1: UnaryFunction<ValueType, ResultValue1>, f2: UnaryFunction<ResultValue1, ReturnType>): Pipeline<ValueType, ReturnType>;
|
|
232
|
-
declare function pPipe<ValueType, ResultValue1, ResultValue2, ReturnType>(f1: UnaryFunction<ValueType, ResultValue1>, f2: UnaryFunction<ResultValue1, ResultValue2>, f3: UnaryFunction<ResultValue2, ReturnType>): Pipeline<ValueType, ReturnType>;
|
|
233
|
-
declare function pPipe<ValueType, ResultValue1, ResultValue2, ResultValue3, ReturnType>(f1: UnaryFunction<ValueType, ResultValue1>, f2: UnaryFunction<ResultValue1, ResultValue2>, f3: UnaryFunction<ResultValue2, ResultValue3>, f4: UnaryFunction<ResultValue3, ReturnType>): Pipeline<ValueType, ReturnType>;
|
|
234
|
-
declare function pPipe<ValueType, ResultValue1, ResultValue2, ResultValue3, ResultValue4, ReturnType>(f1: UnaryFunction<ValueType, ResultValue1>, f2: UnaryFunction<ResultValue1, ResultValue2>, f3: UnaryFunction<ResultValue2, ResultValue3>, f4: UnaryFunction<ResultValue3, ResultValue4>, f5: UnaryFunction<ResultValue4, ReturnType>): Pipeline<ValueType, ReturnType>;
|
|
235
|
-
declare function pPipe<ValueType, ResultValue1, ResultValue2, ResultValue3, ResultValue4, ResultValue5, ReturnType>(f1: UnaryFunction<ValueType, ResultValue1>, f2: UnaryFunction<ResultValue1, ResultValue2>, f3: UnaryFunction<ResultValue2, ResultValue3>, f4: UnaryFunction<ResultValue3, ResultValue4>, f5: UnaryFunction<ResultValue4, ResultValue5>, f6: UnaryFunction<ResultValue5, ReturnType>): Pipeline<ValueType, ReturnType>;
|
|
236
|
-
declare function pPipe<ValueType, ResultValue1, ResultValue2, ResultValue3, ResultValue4, ResultValue5, ResultValue6, ReturnType>(f1: UnaryFunction<ValueType, ResultValue1>, f2: UnaryFunction<ResultValue1, ResultValue2>, f3: UnaryFunction<ResultValue2, ResultValue3>, f4: UnaryFunction<ResultValue3, ResultValue4>, f5: UnaryFunction<ResultValue4, ResultValue5>, f6: UnaryFunction<ResultValue5, ResultValue6>, f7: UnaryFunction<ResultValue6, ReturnType>): Pipeline<ValueType, ReturnType>;
|
|
237
|
-
declare function pPipe<ValueType, ResultValue1, ResultValue2, ResultValue3, ResultValue4, ResultValue5, ResultValue6, ResultValue7, ReturnType>(f1: UnaryFunction<ValueType, ResultValue1>, f2: UnaryFunction<ResultValue1, ResultValue2>, f3: UnaryFunction<ResultValue2, ResultValue3>, f4: UnaryFunction<ResultValue3, ResultValue4>, f5: UnaryFunction<ResultValue4, ResultValue5>, f6: UnaryFunction<ResultValue5, ResultValue6>, f7: UnaryFunction<ResultValue6, ResultValue7>, f8: UnaryFunction<ResultValue7, ReturnType>): Pipeline<ValueType, ReturnType>;
|
|
238
|
-
declare function pPipe<ValueType, ResultValue1, ResultValue2, ResultValue3, ResultValue4, ResultValue5, ResultValue6, ResultValue7, ResultValue8, ReturnType>(f1: UnaryFunction<ValueType, ResultValue1>, f2: UnaryFunction<ResultValue1, ResultValue2>, f3: UnaryFunction<ResultValue2, ResultValue3>, f4: UnaryFunction<ResultValue3, ResultValue4>, f5: UnaryFunction<ResultValue4, ResultValue5>, f6: UnaryFunction<ResultValue5, ResultValue6>, f7: UnaryFunction<ResultValue6, ResultValue7>, f8: UnaryFunction<ResultValue7, ResultValue8>, f9: UnaryFunction<ResultValue8, ReturnType>): Pipeline<ValueType, ReturnType>;
|
|
239
|
-
|
|
240
|
-
declare const pipe: (...fns: any[]) => any;
|
|
241
|
-
|
|
242
|
-
declare function arange(x1: number, x2?: number, stp?: number, z?: number[], z0?: number): number[];
|
|
243
|
-
declare function loop<T = void>(fn: (next: (ms: number) => Promise<T>) => Promise<T>): Promise<T>;
|
|
244
|
-
declare function riposte<T>(...args: [cond: boolean, value: T][]): T;
|
|
245
|
-
declare function unwrap<T extends object>(value: T | (() => T)): T;
|
|
246
|
-
declare function whenever<T, C extends (value: Exclude<T, null | undefined>) => any>(value: T, callback: C): ReturnType<C> | undefined;
|
|
247
|
-
|
|
248
|
-
export { type Arrayable, type Awaitable, BIG_INTS, type BooleanLike, type DecimalOptions, type DeepKeyof, type DeepPartial, type DeepReadonly, type DeepReplace, type DeepRequired, Deferred, type Delimiter, type Dimension, type DynamicObject, type FormatGroupOptions, type FormatNumericOptions, type Key, type Noop, type NumberObject, type Numberish, type Numeric, type NumericObject, type Option, type Pipeline, type StringObject, type SymbolObject, type Typeof, type UnaryFunction, arange, average, compose, cover, decimal, delay, formToObject, formatNumeric, formatSize, formatUnit, getTypeof, gt, gte, integer, isAndroid, isBrowser, isChrome, isEdge, isFF, isFormData, isIE, isIE11, isIE9, isIOS, isMobile, isPhantomJS, isTypeof, isWeex, isWindow, loop, lt, lte, noop, numerfix, objectToForm, pPipe, parseNumeric, percentage, pipe, plus, riposte, unum, unwrap, whenever, zerofill, zeromove };
|