@hairy/utils 1.39.0 → 1.40.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 +248 -198
- package/dist/index.d.ts +61 -15
- package/dist/index.global.js +225 -191
- package/dist/index.js +237 -194
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
export { clone, cloneDeep, cloneDeepWith, cloneWith, concat, debounce, find, 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';
|
|
2
|
-
import
|
|
3
|
-
export { default as Bignumber } from 'bignumber.js';
|
|
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';
|
|
2
|
+
import _Bignumber from 'bignumber.js';
|
|
4
3
|
|
|
5
4
|
interface OpenFilePickerOptions {
|
|
6
5
|
/**
|
|
@@ -88,6 +87,12 @@ type DeepMerge<F, S> = MergeInsertions<{
|
|
|
88
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;
|
|
89
88
|
}>;
|
|
90
89
|
|
|
90
|
+
/**
|
|
91
|
+
* Any type that can be used where a big number is needed.
|
|
92
|
+
*/
|
|
93
|
+
type Numberish = Numeric | {
|
|
94
|
+
toString: (...args: any[]) => string;
|
|
95
|
+
} | undefined | null;
|
|
91
96
|
type Awaitable<T> = T | PromiseLike<T>;
|
|
92
97
|
type Arrayable<T> = T | T[];
|
|
93
98
|
type Promisify<T> = Promise<Awaited<T>>;
|
|
@@ -101,6 +106,7 @@ type IsAny<T> = IfAny<T, true, false>;
|
|
|
101
106
|
type ConstructorType<T = void> = new (...args: any[]) => T;
|
|
102
107
|
type ArgumentsType<T> = T extends ((...args: infer A) => any) ? A : never;
|
|
103
108
|
declare type PromiseType<P extends PromiseLike<any>> = P extends PromiseLike<infer T> ? T : never;
|
|
109
|
+
type BrowserNativeObject = Date | FileList | File;
|
|
104
110
|
type Option<L extends Key = 'label', V extends Key = 'value', C extends Key = 'children'> = {
|
|
105
111
|
[P in L]?: string;
|
|
106
112
|
} & {
|
|
@@ -116,6 +122,10 @@ type PickBy<T, U> = {
|
|
|
116
122
|
};
|
|
117
123
|
type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;
|
|
118
124
|
type Assign<T, U> = Omit<T, keyof U> & U;
|
|
125
|
+
type NonUndefined<T> = T extends undefined ? never : T;
|
|
126
|
+
type DeepMap<T, V> = IsAny<T> extends true ? any : T extends BrowserNativeObject ? V : T extends object ? {
|
|
127
|
+
[K in keyof T]: DeepMap<NonUndefined<T[K]>, V>;
|
|
128
|
+
} : V;
|
|
119
129
|
|
|
120
130
|
declare function redirectTo(url: string, target?: string): void;
|
|
121
131
|
declare function dialsPhone(phoneNumber: string): void;
|
|
@@ -210,6 +220,20 @@ declare function snakeCase(input: string, options?: Options): string;
|
|
|
210
220
|
*/
|
|
211
221
|
declare function trainCase(input: string, options?: Options): string;
|
|
212
222
|
|
|
223
|
+
declare const DEFAULT_BIGNUM_CONFIG: _Bignumber.Config;
|
|
224
|
+
declare namespace Bignumber {
|
|
225
|
+
type RoundingMode = _Bignumber.RoundingMode;
|
|
226
|
+
type Format = _Bignumber.Format;
|
|
227
|
+
type Config = _Bignumber.Config;
|
|
228
|
+
type Instance = _Bignumber.Instance;
|
|
229
|
+
type Value = _Bignumber.Value;
|
|
230
|
+
}
|
|
231
|
+
declare const Bignumber: typeof _Bignumber;
|
|
232
|
+
/**
|
|
233
|
+
* export bignumber.js
|
|
234
|
+
*
|
|
235
|
+
* do not use Bignumber directly, use bignumber function instead
|
|
236
|
+
*/
|
|
213
237
|
declare const BIG_INTS: {
|
|
214
238
|
t: {
|
|
215
239
|
v: number;
|
|
@@ -232,12 +256,6 @@ declare const BIG_INTS: {
|
|
|
232
256
|
n: string;
|
|
233
257
|
};
|
|
234
258
|
};
|
|
235
|
-
/**
|
|
236
|
-
* Any type that can be used where a big number is needed.
|
|
237
|
-
*/
|
|
238
|
-
type Numberish = Numeric | {
|
|
239
|
-
toString: (...args: any[]) => string;
|
|
240
|
-
};
|
|
241
259
|
type Delimiter = 'k' | 'm' | 'b' | 't';
|
|
242
260
|
interface DecimalOptions {
|
|
243
261
|
d?: number;
|
|
@@ -255,13 +273,16 @@ interface FormatNumericOptions {
|
|
|
255
273
|
default?: string;
|
|
256
274
|
format?: Bignumber.Format;
|
|
257
275
|
}
|
|
258
|
-
declare function
|
|
259
|
-
declare
|
|
276
|
+
declare function bignumber(n?: Numberish, base?: number): _Bignumber;
|
|
277
|
+
declare namespace bignumber {
|
|
278
|
+
var clone: (config: Bignumber.Config) => typeof _Bignumber;
|
|
279
|
+
}
|
|
260
280
|
declare function gte(a: Numberish, b: Numberish): boolean;
|
|
261
281
|
declare function gt(a: Numberish, b: Numberish): boolean;
|
|
262
282
|
declare function lte(a: Numberish, b: Numberish): boolean;
|
|
263
283
|
declare function lt(a: Numberish, b: Numberish): boolean;
|
|
264
284
|
declare function plus(array: Numberish[], options?: DecimalOptions): string;
|
|
285
|
+
declare function divs(array: Numberish[], options?: DecimalOptions): string;
|
|
265
286
|
declare function average(array: Numberish[], options?: DecimalOptions): string;
|
|
266
287
|
/**
|
|
267
288
|
* calculate percentage
|
|
@@ -297,7 +318,6 @@ declare function parseNumeric(num: Numberish, delimiters?: Delimiter[]): {
|
|
|
297
318
|
* format number thousand separator and unit
|
|
298
319
|
* @param value
|
|
299
320
|
* @param options
|
|
300
|
-
* @returns
|
|
301
321
|
*/
|
|
302
322
|
declare function formatNumeric(value?: Numberish, options?: FormatNumericOptions): string;
|
|
303
323
|
|
|
@@ -477,12 +497,36 @@ declare namespace compose {
|
|
|
477
497
|
* formData to object
|
|
478
498
|
* @param formData
|
|
479
499
|
*/
|
|
480
|
-
declare function
|
|
500
|
+
declare function objectFromFormdata(formData: FormData): Record<string, string>;
|
|
481
501
|
/**
|
|
482
502
|
* Object to formData
|
|
483
503
|
* @param object
|
|
484
504
|
*/
|
|
485
|
-
declare function
|
|
505
|
+
declare function formdataFromObject(object: Record<string, string | File>): FormData;
|
|
506
|
+
/**
|
|
507
|
+
* Check if a value is not NaN.
|
|
508
|
+
* @param value - The value to check.
|
|
509
|
+
* @returns The value if it is not NaN, otherwise undefined.
|
|
510
|
+
*/
|
|
511
|
+
declare function nonnanable<T>(value: T): T | undefined;
|
|
512
|
+
/**
|
|
513
|
+
* Convert a value to a number.
|
|
514
|
+
* @param value - The value to convert to a number.
|
|
515
|
+
* @returns The number value.
|
|
516
|
+
*/
|
|
517
|
+
declare function numberify(value: any): number;
|
|
518
|
+
/**
|
|
519
|
+
* Convert a value to a string.
|
|
520
|
+
* @param value - The value to convert to a string.
|
|
521
|
+
* @returns The string value.
|
|
522
|
+
*/
|
|
523
|
+
declare function stringify(value: any): string;
|
|
524
|
+
/**
|
|
525
|
+
* Convert a value to a numberish value.
|
|
526
|
+
* @param value - The value to convert to a numberish value.
|
|
527
|
+
* @returns The numberish value.
|
|
528
|
+
*/
|
|
529
|
+
declare function numberish(value: Numberish): string;
|
|
486
530
|
|
|
487
531
|
declare class Deferred<T> extends Promise<T> {
|
|
488
532
|
resolve: (value?: T) => Deferred<T>;
|
|
@@ -595,10 +639,12 @@ declare function randomString(size: number, chars?: string): string;
|
|
|
595
639
|
|
|
596
640
|
declare function to<T, U = Error>(promise: Promise<T> | (() => Promise<T>), error?: object): Promise<[U, undefined] | [null, T]>;
|
|
597
641
|
|
|
642
|
+
declare function toArray<T>(value?: T | T[]): T[] | undefined;
|
|
643
|
+
|
|
598
644
|
declare function arange(x1: number, x2?: number, stp?: number, z?: number[], z0?: number): number[];
|
|
599
645
|
declare function riposte<T>(...args: [cond: boolean, value: T][]): T;
|
|
600
646
|
declare function unwrap<T extends object>(value: T | (() => T)): T;
|
|
601
647
|
declare function whenever<T, C extends (value: Exclude<T, null | undefined>) => any>(value: T, callback: C): ReturnType<C> | undefined;
|
|
602
648
|
declare function call<T extends Fn$1<any>>(fn: T, ...args: Parameters<T>): ReturnType<T>;
|
|
603
649
|
|
|
604
|
-
export { type AnyFn, type ArgumentsType, type Arrayable, type Assign, type Awaitable, BIG_INTS, type BooleanLike, type ConstructorType, type DecimalOptions, type DeepKeyof, 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 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 ReaderType, type StringObject, type SymbolObject, type Typeof, arange, average,
|
|
650
|
+
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 ReaderType, type StringObject, type SymbolObject, type Typeof, arange, average, bignumber, call, camelCase, capitalCase, compose, constantCase, cover, decimal, delay, dialsPhone, divs, dotCase, downloadBlobFile, downloadNetworkFile, ensurePrefix, ensureSuffix, formatNumeric, formatSize, formatUnit, formdataFromObject, getTypeof, gt, gte, integer, isAndroid, isBrowser, isChrome, isEdge, isFF, isFormData, isIE, isIE11, isIE9, isIOS, isMobile, isPhantomJS, isTruthy, isTypeof, isWeex, isWindow, jsonTryParse, kebabCase, loop, lt, lte, noCase, nonnanable, noop, numberify, numberish, objectFromFormdata, off, on, parseNumeric, pascalCase, pascalSnakeCase, pathCase, percentage, pipe, plus, proxy, randomArray, randomNumber, randomString, readFileReader, redirectTo, riposte, selectImages, sentenceCase, showOpenFilePicker, showOpenImagePicker, slash, snakeCase, stringify, template, to, toArray, trainCase, unindent, unwrap, whenever, zerofill, zeromove };
|
package/dist/index.global.js
CHANGED
|
@@ -4483,192 +4483,6 @@
|
|
|
4483
4483
|
var BigNumber = clone2();
|
|
4484
4484
|
var bignumber_default = BigNumber;
|
|
4485
4485
|
|
|
4486
|
-
// src/number/index.ts
|
|
4487
|
-
var BIG_INTS = {
|
|
4488
|
-
t: { v: 10 ** 12, d: 13, n: "t" },
|
|
4489
|
-
b: { v: 10 ** 9, d: 10, n: "b" },
|
|
4490
|
-
m: { v: 10 ** 6, d: 7, n: "m" },
|
|
4491
|
-
k: { v: 10 ** 3, d: 4, n: "k" }
|
|
4492
|
-
};
|
|
4493
|
-
function bignum(n = "0") {
|
|
4494
|
-
return new bignumber_default(numfix(n));
|
|
4495
|
-
}
|
|
4496
|
-
function numfix(value) {
|
|
4497
|
-
return Number.isNaN(Number(value)) || value.toString() === "NaN" ? "0" : String(value);
|
|
4498
|
-
}
|
|
4499
|
-
function gte(a, b) {
|
|
4500
|
-
return bignum(a).gte(bignum(b));
|
|
4501
|
-
}
|
|
4502
|
-
function gt(a, b) {
|
|
4503
|
-
return bignum(a).gt(bignum(b));
|
|
4504
|
-
}
|
|
4505
|
-
function lte(a, b) {
|
|
4506
|
-
return bignum(a).lte(bignum(b));
|
|
4507
|
-
}
|
|
4508
|
-
function lt(a, b) {
|
|
4509
|
-
return bignum(a).lt(bignum(b));
|
|
4510
|
-
}
|
|
4511
|
-
function plus(array, options) {
|
|
4512
|
-
const rounding = options?.r || bignumber_default.ROUND_DOWN;
|
|
4513
|
-
const decimal2 = options?.d || 0;
|
|
4514
|
-
return array.filter((v) => bignum(v).gt(0)).reduce((t, v) => t.plus(bignum(v)), bignum(0)).toFixed(decimal2, rounding);
|
|
4515
|
-
}
|
|
4516
|
-
function average(array, options) {
|
|
4517
|
-
const rounding = options?.r || bignumber_default.ROUND_DOWN;
|
|
4518
|
-
const decimal2 = options?.d || 0;
|
|
4519
|
-
if (array.length === 0)
|
|
4520
|
-
return "0";
|
|
4521
|
-
return bignum(plus(array)).div(array.length).toFixed(decimal2, rounding);
|
|
4522
|
-
}
|
|
4523
|
-
function percentage(total, count, options) {
|
|
4524
|
-
options ??= { d: 3, r: bignumber_default.ROUND_DOWN };
|
|
4525
|
-
const rounding = options?.r || bignumber_default.ROUND_DOWN;
|
|
4526
|
-
const decimal2 = options?.d || 3;
|
|
4527
|
-
if (bignum(total).lte(0) || bignum(count).lte(0))
|
|
4528
|
-
return "0";
|
|
4529
|
-
return bignum(count).div(bignum(total)).times(100).toFixed(decimal2, rounding);
|
|
4530
|
-
}
|
|
4531
|
-
function zerofill(value, n = 2, type = "positive") {
|
|
4532
|
-
const _value = integer(value);
|
|
4533
|
-
if (_value.length >= n)
|
|
4534
|
-
return value;
|
|
4535
|
-
const zero = "0".repeat(n - _value.length);
|
|
4536
|
-
if (type === "positive")
|
|
4537
|
-
return zero + value;
|
|
4538
|
-
if (type === "reverse")
|
|
4539
|
-
return zero + value;
|
|
4540
|
-
return "";
|
|
4541
|
-
}
|
|
4542
|
-
function zeromove(value) {
|
|
4543
|
-
return value.toString().replace(/\.?0+$/, "");
|
|
4544
|
-
}
|
|
4545
|
-
function integer(value) {
|
|
4546
|
-
return new bignumber_default(numfix(value)).toFixed(0);
|
|
4547
|
-
}
|
|
4548
|
-
function decimal(value, n = 2) {
|
|
4549
|
-
let [integer2, decimal2] = numfix(value).split(".");
|
|
4550
|
-
if (n <= 0)
|
|
4551
|
-
return integer2;
|
|
4552
|
-
if (!decimal2)
|
|
4553
|
-
decimal2 = "0";
|
|
4554
|
-
decimal2 = decimal2.slice(0, n);
|
|
4555
|
-
decimal2 = decimal2 + "0".repeat(n - decimal2.length);
|
|
4556
|
-
return `${integer2}.${decimal2}`;
|
|
4557
|
-
}
|
|
4558
|
-
function parseNumeric(num, delimiters = ["t", "b", "m"]) {
|
|
4559
|
-
const mappings = [
|
|
4560
|
-
delimiters.includes("t") && ((n) => gte(n, BIG_INTS.t.v) && BIG_INTS.t),
|
|
4561
|
-
delimiters.includes("b") && ((n) => gte(n, BIG_INTS.b.v) && lt(n, BIG_INTS.t.v) && BIG_INTS.b),
|
|
4562
|
-
delimiters.includes("m") && ((n) => gte(n, BIG_INTS.m.v) && lt(n, BIG_INTS.b.v) && BIG_INTS.m),
|
|
4563
|
-
delimiters.includes("k") && ((n) => gte(n, BIG_INTS.k.v) && lt(n, BIG_INTS.m.v) && BIG_INTS.k)
|
|
4564
|
-
];
|
|
4565
|
-
let options;
|
|
4566
|
-
for (const analy of mappings) {
|
|
4567
|
-
const opts = analy && analy(bignum(num).toFixed(0));
|
|
4568
|
-
opts && (options = opts);
|
|
4569
|
-
}
|
|
4570
|
-
return options || { v: 1, d: 0, n: "" };
|
|
4571
|
-
}
|
|
4572
|
-
function formatNumeric(value = "0", options) {
|
|
4573
|
-
if (options?.default && bignum(value).isZero())
|
|
4574
|
-
return options?.default;
|
|
4575
|
-
const {
|
|
4576
|
-
rounding = bignumber_default.ROUND_DOWN,
|
|
4577
|
-
delimiters,
|
|
4578
|
-
format,
|
|
4579
|
-
decimals = 2
|
|
4580
|
-
} = options || {};
|
|
4581
|
-
const config = parseNumeric(value, delimiters || []);
|
|
4582
|
-
let number = bignum(value).div(config.v).toFormat(decimals, rounding, {
|
|
4583
|
-
decimalSeparator: ".",
|
|
4584
|
-
groupSeparator: ",",
|
|
4585
|
-
groupSize: 3,
|
|
4586
|
-
secondaryGroupSize: 0,
|
|
4587
|
-
fractionGroupSeparator: " ",
|
|
4588
|
-
fractionGroupSize: 0,
|
|
4589
|
-
...format
|
|
4590
|
-
});
|
|
4591
|
-
number = options?.zeromove ? zeromove(number) : number;
|
|
4592
|
-
return `${number}${config.n}`;
|
|
4593
|
-
}
|
|
4594
|
-
|
|
4595
|
-
// src/size/index.ts
|
|
4596
|
-
function formatUnit(value, unit = "px") {
|
|
4597
|
-
if (!(isString_default(value) || isNumber_default(value)))
|
|
4598
|
-
return "";
|
|
4599
|
-
value = String(value);
|
|
4600
|
-
return /\D/.test(value) ? value : value + unit;
|
|
4601
|
-
}
|
|
4602
|
-
function formatSize(dimension, unit) {
|
|
4603
|
-
const _formatUnit = (value) => formatUnit(value, unit);
|
|
4604
|
-
if (typeof dimension === "string" || typeof dimension === "number")
|
|
4605
|
-
return { width: _formatUnit(dimension), height: _formatUnit(dimension) };
|
|
4606
|
-
if (Array.isArray(dimension))
|
|
4607
|
-
return { width: _formatUnit(dimension[0]), height: _formatUnit(dimension[1]) };
|
|
4608
|
-
if (typeof dimension === "object")
|
|
4609
|
-
return { width: _formatUnit(dimension.width), height: _formatUnit(dimension.height) };
|
|
4610
|
-
return { width: "", height: "" };
|
|
4611
|
-
}
|
|
4612
|
-
|
|
4613
|
-
// src/string/index.ts
|
|
4614
|
-
function cover(value, mode, symbol = "*") {
|
|
4615
|
-
return value.slice(0, mode[0]) + symbol.repeat(mode[1]) + value.slice(-mode[2]);
|
|
4616
|
-
}
|
|
4617
|
-
function slash(str) {
|
|
4618
|
-
return str.replace(/\\/g, "/");
|
|
4619
|
-
}
|
|
4620
|
-
function ensurePrefix(prefix, str) {
|
|
4621
|
-
if (!str.startsWith(prefix))
|
|
4622
|
-
return prefix + str;
|
|
4623
|
-
return str;
|
|
4624
|
-
}
|
|
4625
|
-
function ensureSuffix(suffix, str) {
|
|
4626
|
-
if (!str.endsWith(suffix))
|
|
4627
|
-
return str + suffix;
|
|
4628
|
-
return str;
|
|
4629
|
-
}
|
|
4630
|
-
function template(str, ...args) {
|
|
4631
|
-
const [firstArg, fallback] = args;
|
|
4632
|
-
if (isObject_default(firstArg)) {
|
|
4633
|
-
const vars = firstArg;
|
|
4634
|
-
return str.replace(/\{(\w+)\}/g, (_, key) => vars[key] || ((typeof fallback === "function" ? fallback(key) : fallback) ?? key));
|
|
4635
|
-
} else {
|
|
4636
|
-
return str.replace(/\{(\d+)\}/g, (_, key) => {
|
|
4637
|
-
const index = Number(key);
|
|
4638
|
-
if (Number.isNaN(index))
|
|
4639
|
-
return key;
|
|
4640
|
-
return args[index];
|
|
4641
|
-
});
|
|
4642
|
-
}
|
|
4643
|
-
}
|
|
4644
|
-
var _reFullWs = /^\s*$/;
|
|
4645
|
-
function unindent(str) {
|
|
4646
|
-
const lines = (typeof str === "string" ? str : str[0]).split("\n");
|
|
4647
|
-
const whitespaceLines = lines.map((line) => _reFullWs.test(line));
|
|
4648
|
-
const commonIndent = lines.reduce((min, line, idx) => {
|
|
4649
|
-
if (whitespaceLines[idx])
|
|
4650
|
-
return min;
|
|
4651
|
-
const indent = line.match(/^\s*/)?.[0].length;
|
|
4652
|
-
return indent === void 0 ? min : Math.min(min, indent);
|
|
4653
|
-
}, Number.POSITIVE_INFINITY);
|
|
4654
|
-
let emptyLinesHead = 0;
|
|
4655
|
-
while (emptyLinesHead < lines.length && whitespaceLines[emptyLinesHead])
|
|
4656
|
-
emptyLinesHead++;
|
|
4657
|
-
let emptyLinesTail = 0;
|
|
4658
|
-
while (emptyLinesTail < lines.length && whitespaceLines[lines.length - emptyLinesTail - 1])
|
|
4659
|
-
emptyLinesTail++;
|
|
4660
|
-
return lines.slice(emptyLinesHead, lines.length - emptyLinesTail).map((line) => line.slice(commonIndent)).join("\n");
|
|
4661
|
-
}
|
|
4662
|
-
|
|
4663
|
-
// src/typeof/index.ts
|
|
4664
|
-
function getTypeof(target) {
|
|
4665
|
-
const value = Object.prototype.toString.call(target).slice(8, -1).toLocaleLowerCase();
|
|
4666
|
-
return value;
|
|
4667
|
-
}
|
|
4668
|
-
function isTypeof(target, type) {
|
|
4669
|
-
return getTypeof(target) === type;
|
|
4670
|
-
}
|
|
4671
|
-
|
|
4672
4486
|
// src/util/compose-promise.ts
|
|
4673
4487
|
function pCompose(...fns) {
|
|
4674
4488
|
if (fns.length === 0)
|
|
@@ -4689,13 +4503,30 @@
|
|
|
4689
4503
|
compose.promise = pCompose;
|
|
4690
4504
|
|
|
4691
4505
|
// src/util/converts.ts
|
|
4692
|
-
function
|
|
4506
|
+
function objectFromFormdata(formData) {
|
|
4693
4507
|
return Object.fromEntries(formData.entries());
|
|
4694
4508
|
}
|
|
4695
|
-
function
|
|
4696
|
-
const
|
|
4697
|
-
for (const [key, value] of Object.entries(object))
|
|
4698
|
-
|
|
4509
|
+
function formdataFromObject(object) {
|
|
4510
|
+
const formdata = new FormData();
|
|
4511
|
+
for (const [key, value] of Object.entries(object))
|
|
4512
|
+
formdata.set(key, value);
|
|
4513
|
+
return formdata;
|
|
4514
|
+
}
|
|
4515
|
+
function nonnanable(value) {
|
|
4516
|
+
return Number.isNaN(Number(value)) ? void 0 : value;
|
|
4517
|
+
}
|
|
4518
|
+
function numberify(value) {
|
|
4519
|
+
return Number.isNaN(Number(value)) ? 0 : Number(value);
|
|
4520
|
+
}
|
|
4521
|
+
function stringify(value) {
|
|
4522
|
+
return String(value);
|
|
4523
|
+
}
|
|
4524
|
+
function numberish(value) {
|
|
4525
|
+
if (value === void 0 || value === null)
|
|
4526
|
+
return "0";
|
|
4527
|
+
if (Number.isNaN(Number(value)))
|
|
4528
|
+
return "0";
|
|
4529
|
+
return value.toString();
|
|
4699
4530
|
}
|
|
4700
4531
|
|
|
4701
4532
|
// src/util/noop.ts
|
|
@@ -4838,6 +4669,13 @@
|
|
|
4838
4669
|
});
|
|
4839
4670
|
}
|
|
4840
4671
|
|
|
4672
|
+
// src/util/to-array.ts
|
|
4673
|
+
function toArray(value) {
|
|
4674
|
+
if (!value)
|
|
4675
|
+
return void 0;
|
|
4676
|
+
return Array.isArray(value) ? value : [value];
|
|
4677
|
+
}
|
|
4678
|
+
|
|
4841
4679
|
// src/util/util.ts
|
|
4842
4680
|
function arange(x1, x2, stp = 1, z = [], z0 = z.length) {
|
|
4843
4681
|
if (!x2)
|
|
@@ -4862,6 +4700,202 @@
|
|
|
4862
4700
|
function call(fn, ...args) {
|
|
4863
4701
|
return fn(...args);
|
|
4864
4702
|
}
|
|
4703
|
+
|
|
4704
|
+
// src/number/index.ts
|
|
4705
|
+
var DEFAULT_BIGNUM_CONFIG = {
|
|
4706
|
+
ROUNDING_MODE: bignumber_default.ROUND_UP,
|
|
4707
|
+
DECIMAL_PLACES: 6
|
|
4708
|
+
};
|
|
4709
|
+
var Bignumber = bignumber_default.clone(DEFAULT_BIGNUM_CONFIG);
|
|
4710
|
+
var BIG_INTS = {
|
|
4711
|
+
t: { v: 10 ** 12, d: 13, n: "t" },
|
|
4712
|
+
b: { v: 10 ** 9, d: 10, n: "b" },
|
|
4713
|
+
m: { v: 10 ** 6, d: 7, n: "m" },
|
|
4714
|
+
k: { v: 10 ** 3, d: 4, n: "k" }
|
|
4715
|
+
};
|
|
4716
|
+
function bignumber(n = "0", base) {
|
|
4717
|
+
return new Bignumber(numberish(n), base);
|
|
4718
|
+
}
|
|
4719
|
+
bignumber.clone = function(config) {
|
|
4720
|
+
return Bignumber.clone({ ...DEFAULT_BIGNUM_CONFIG, ...config });
|
|
4721
|
+
};
|
|
4722
|
+
function gte(a, b) {
|
|
4723
|
+
return bignumber(a).gte(bignumber(b));
|
|
4724
|
+
}
|
|
4725
|
+
function gt(a, b) {
|
|
4726
|
+
return bignumber(a).gt(bignumber(b));
|
|
4727
|
+
}
|
|
4728
|
+
function lte(a, b) {
|
|
4729
|
+
return bignumber(a).lte(bignumber(b));
|
|
4730
|
+
}
|
|
4731
|
+
function lt(a, b) {
|
|
4732
|
+
return bignumber(a).lt(bignumber(b));
|
|
4733
|
+
}
|
|
4734
|
+
function plus(array, options) {
|
|
4735
|
+
const rounding = options?.r || Bignumber.ROUND_DOWN;
|
|
4736
|
+
const decimal2 = options?.d || 0;
|
|
4737
|
+
return array.filter((v) => bignumber(v).gt(0)).reduce((t, v) => t.plus(bignumber(v)), bignumber(0)).toFixed(decimal2, rounding);
|
|
4738
|
+
}
|
|
4739
|
+
function divs(array, options) {
|
|
4740
|
+
const rounding = options?.r || Bignumber.ROUND_DOWN;
|
|
4741
|
+
const decimal2 = options?.d || 0;
|
|
4742
|
+
return array.reduce((t, v) => t.div(bignumber(v)), bignumber(1)).toFixed(decimal2, rounding);
|
|
4743
|
+
}
|
|
4744
|
+
function average(array, options) {
|
|
4745
|
+
const rounding = options?.r || Bignumber.ROUND_DOWN;
|
|
4746
|
+
const decimal2 = options?.d || 0;
|
|
4747
|
+
if (array.length === 0)
|
|
4748
|
+
return "0";
|
|
4749
|
+
return bignumber(plus(array)).div(array.length).toFixed(decimal2, rounding);
|
|
4750
|
+
}
|
|
4751
|
+
function percentage(total, count, options) {
|
|
4752
|
+
options ??= { d: 3, r: Bignumber.ROUND_DOWN };
|
|
4753
|
+
const rounding = options?.r || Bignumber.ROUND_DOWN;
|
|
4754
|
+
const decimal2 = options?.d || 3;
|
|
4755
|
+
if (bignumber(total).lte(0) || bignumber(count).lte(0))
|
|
4756
|
+
return "0";
|
|
4757
|
+
return bignumber(count).div(bignumber(total)).times(100).toFixed(decimal2, rounding);
|
|
4758
|
+
}
|
|
4759
|
+
function zerofill(value, n = 2, type = "positive") {
|
|
4760
|
+
const _value = integer(value);
|
|
4761
|
+
if (_value.length >= n)
|
|
4762
|
+
return value;
|
|
4763
|
+
const zero = "0".repeat(n - _value.length);
|
|
4764
|
+
if (type === "positive")
|
|
4765
|
+
return zero + value;
|
|
4766
|
+
if (type === "reverse")
|
|
4767
|
+
return zero + value;
|
|
4768
|
+
return "";
|
|
4769
|
+
}
|
|
4770
|
+
function zeromove(value) {
|
|
4771
|
+
return numberish(value).toString().replace(/\.?0+$/, "");
|
|
4772
|
+
}
|
|
4773
|
+
function integer(value) {
|
|
4774
|
+
return new Bignumber(numberish(value)).toFixed(0);
|
|
4775
|
+
}
|
|
4776
|
+
function decimal(value, n = 2) {
|
|
4777
|
+
let [integer2, decimal2] = numberish(value).split(".");
|
|
4778
|
+
if (n <= 0)
|
|
4779
|
+
return integer2;
|
|
4780
|
+
if (!decimal2)
|
|
4781
|
+
decimal2 = "0";
|
|
4782
|
+
decimal2 = decimal2.slice(0, n);
|
|
4783
|
+
decimal2 = decimal2 + "0".repeat(n - decimal2.length);
|
|
4784
|
+
return `${integer2}.${decimal2}`;
|
|
4785
|
+
}
|
|
4786
|
+
function parseNumeric(num, delimiters = ["t", "b", "m"]) {
|
|
4787
|
+
const mappings = [
|
|
4788
|
+
delimiters.includes("t") && ((n) => gte(n, BIG_INTS.t.v) && BIG_INTS.t),
|
|
4789
|
+
delimiters.includes("b") && ((n) => gte(n, BIG_INTS.b.v) && lt(n, BIG_INTS.t.v) && BIG_INTS.b),
|
|
4790
|
+
delimiters.includes("m") && ((n) => gte(n, BIG_INTS.m.v) && lt(n, BIG_INTS.b.v) && BIG_INTS.m),
|
|
4791
|
+
delimiters.includes("k") && ((n) => gte(n, BIG_INTS.k.v) && lt(n, BIG_INTS.m.v) && BIG_INTS.k)
|
|
4792
|
+
];
|
|
4793
|
+
let options;
|
|
4794
|
+
for (const analy of mappings) {
|
|
4795
|
+
const opts = analy && analy(bignumber(num).toFixed(0));
|
|
4796
|
+
opts && (options = opts);
|
|
4797
|
+
}
|
|
4798
|
+
return options || { v: 1, d: 0, n: "" };
|
|
4799
|
+
}
|
|
4800
|
+
function formatNumeric(value = "0", options) {
|
|
4801
|
+
if (options?.default && bignumber(value).isZero())
|
|
4802
|
+
return options?.default;
|
|
4803
|
+
const {
|
|
4804
|
+
rounding = Bignumber.ROUND_DOWN,
|
|
4805
|
+
delimiters,
|
|
4806
|
+
format,
|
|
4807
|
+
decimals = 2
|
|
4808
|
+
} = options || {};
|
|
4809
|
+
const config = parseNumeric(value, delimiters || []);
|
|
4810
|
+
let number = bignumber(value).div(config.v).toFormat(decimals, rounding, {
|
|
4811
|
+
decimalSeparator: ".",
|
|
4812
|
+
groupSeparator: ",",
|
|
4813
|
+
groupSize: 3,
|
|
4814
|
+
secondaryGroupSize: 0,
|
|
4815
|
+
fractionGroupSeparator: " ",
|
|
4816
|
+
fractionGroupSize: 0,
|
|
4817
|
+
...format
|
|
4818
|
+
});
|
|
4819
|
+
number = options?.zeromove ? zeromove(number) : number;
|
|
4820
|
+
return `${number}${config.n}`;
|
|
4821
|
+
}
|
|
4822
|
+
|
|
4823
|
+
// src/size/index.ts
|
|
4824
|
+
function formatUnit(value, unit = "px") {
|
|
4825
|
+
if (!(isString_default(value) || isNumber_default(value)))
|
|
4826
|
+
return "";
|
|
4827
|
+
value = String(value);
|
|
4828
|
+
return /\D/.test(value) ? value : value + unit;
|
|
4829
|
+
}
|
|
4830
|
+
function formatSize(dimension, unit) {
|
|
4831
|
+
const _formatUnit = (value) => formatUnit(value, unit);
|
|
4832
|
+
if (typeof dimension === "string" || typeof dimension === "number")
|
|
4833
|
+
return { width: _formatUnit(dimension), height: _formatUnit(dimension) };
|
|
4834
|
+
if (Array.isArray(dimension))
|
|
4835
|
+
return { width: _formatUnit(dimension[0]), height: _formatUnit(dimension[1]) };
|
|
4836
|
+
if (typeof dimension === "object")
|
|
4837
|
+
return { width: _formatUnit(dimension.width), height: _formatUnit(dimension.height) };
|
|
4838
|
+
return { width: "", height: "" };
|
|
4839
|
+
}
|
|
4840
|
+
|
|
4841
|
+
// src/string/index.ts
|
|
4842
|
+
function cover(value, mode, symbol = "*") {
|
|
4843
|
+
return value.slice(0, mode[0]) + symbol.repeat(mode[1]) + value.slice(-mode[2]);
|
|
4844
|
+
}
|
|
4845
|
+
function slash(str) {
|
|
4846
|
+
return str.replace(/\\/g, "/");
|
|
4847
|
+
}
|
|
4848
|
+
function ensurePrefix(prefix, str) {
|
|
4849
|
+
if (!str.startsWith(prefix))
|
|
4850
|
+
return prefix + str;
|
|
4851
|
+
return str;
|
|
4852
|
+
}
|
|
4853
|
+
function ensureSuffix(suffix, str) {
|
|
4854
|
+
if (!str.endsWith(suffix))
|
|
4855
|
+
return str + suffix;
|
|
4856
|
+
return str;
|
|
4857
|
+
}
|
|
4858
|
+
function template(str, ...args) {
|
|
4859
|
+
const [firstArg, fallback] = args;
|
|
4860
|
+
if (isObject_default(firstArg)) {
|
|
4861
|
+
const vars = firstArg;
|
|
4862
|
+
return str.replace(/\{(\w+)\}/g, (_, key) => vars[key] || ((typeof fallback === "function" ? fallback(key) : fallback) ?? key));
|
|
4863
|
+
} else {
|
|
4864
|
+
return str.replace(/\{(\d+)\}/g, (_, key) => {
|
|
4865
|
+
const index = Number(key);
|
|
4866
|
+
if (Number.isNaN(index))
|
|
4867
|
+
return key;
|
|
4868
|
+
return args[index];
|
|
4869
|
+
});
|
|
4870
|
+
}
|
|
4871
|
+
}
|
|
4872
|
+
var _reFullWs = /^\s*$/;
|
|
4873
|
+
function unindent(str) {
|
|
4874
|
+
const lines = (typeof str === "string" ? str : str[0]).split("\n");
|
|
4875
|
+
const whitespaceLines = lines.map((line) => _reFullWs.test(line));
|
|
4876
|
+
const commonIndent = lines.reduce((min, line, idx) => {
|
|
4877
|
+
if (whitespaceLines[idx])
|
|
4878
|
+
return min;
|
|
4879
|
+
const indent = line.match(/^\s*/)?.[0].length;
|
|
4880
|
+
return indent === void 0 ? min : Math.min(min, indent);
|
|
4881
|
+
}, Number.POSITIVE_INFINITY);
|
|
4882
|
+
let emptyLinesHead = 0;
|
|
4883
|
+
while (emptyLinesHead < lines.length && whitespaceLines[emptyLinesHead])
|
|
4884
|
+
emptyLinesHead++;
|
|
4885
|
+
let emptyLinesTail = 0;
|
|
4886
|
+
while (emptyLinesTail < lines.length && whitespaceLines[lines.length - emptyLinesTail - 1])
|
|
4887
|
+
emptyLinesTail++;
|
|
4888
|
+
return lines.slice(emptyLinesHead, lines.length - emptyLinesTail).map((line) => line.slice(commonIndent)).join("\n");
|
|
4889
|
+
}
|
|
4890
|
+
|
|
4891
|
+
// src/typeof/index.ts
|
|
4892
|
+
function getTypeof(target) {
|
|
4893
|
+
const value = Object.prototype.toString.call(target).slice(8, -1).toLocaleLowerCase();
|
|
4894
|
+
return value;
|
|
4895
|
+
}
|
|
4896
|
+
function isTypeof(target, type) {
|
|
4897
|
+
return getTypeof(target) === type;
|
|
4898
|
+
}
|
|
4865
4899
|
})();
|
|
4866
4900
|
/*! Bundled license information:
|
|
4867
4901
|
|