@hairy/utils 1.38.0 → 1.39.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/dist/index.cjs +247 -199
- package/dist/index.d.ts +47 -14
- package/dist/index.global.js +225 -191
- package/dist/index.js +236 -194
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -31,11 +31,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
33
|
BIG_INTS: () => BIG_INTS,
|
|
34
|
-
|
|
34
|
+
DEFAULT_BIGNUM_CONFIG: () => DEFAULT_BIGNUM_CONFIG,
|
|
35
35
|
Deferred: () => Deferred,
|
|
36
36
|
arange: () => arange,
|
|
37
37
|
average: () => average,
|
|
38
|
-
|
|
38
|
+
bignumber: () => bignumber,
|
|
39
39
|
call: () => call,
|
|
40
40
|
camelCase: () => camelCase,
|
|
41
41
|
capitalCase: () => capitalCase,
|
|
@@ -51,16 +51,18 @@ __export(index_exports, {
|
|
|
51
51
|
decimal: () => decimal,
|
|
52
52
|
delay: () => delay,
|
|
53
53
|
dialsPhone: () => dialsPhone,
|
|
54
|
+
divs: () => divs,
|
|
54
55
|
dotCase: () => dotCase,
|
|
55
56
|
downloadBlobFile: () => downloadBlobFile,
|
|
56
57
|
downloadNetworkFile: () => downloadNetworkFile,
|
|
57
58
|
ensurePrefix: () => ensurePrefix,
|
|
58
59
|
ensureSuffix: () => ensureSuffix,
|
|
59
60
|
find: () => find_default,
|
|
60
|
-
formToObject: () => formToObject,
|
|
61
61
|
formatNumeric: () => formatNumeric,
|
|
62
62
|
formatSize: () => formatSize,
|
|
63
63
|
formatUnit: () => formatUnit,
|
|
64
|
+
formdataFromObject: () => formdataFromObject,
|
|
65
|
+
get: () => get_default,
|
|
64
66
|
getTypeof: () => getTypeof,
|
|
65
67
|
groupBy: () => groupBy_default,
|
|
66
68
|
gt: () => gt,
|
|
@@ -125,9 +127,11 @@ __export(index_exports, {
|
|
|
125
127
|
merge: () => merge_default,
|
|
126
128
|
mergeWith: () => mergeWith_default,
|
|
127
129
|
noCase: () => noCase,
|
|
130
|
+
nonnanable: () => nonnanable,
|
|
128
131
|
noop: () => noop2,
|
|
129
|
-
|
|
130
|
-
|
|
132
|
+
numberify: () => numberify,
|
|
133
|
+
numberish: () => numberish,
|
|
134
|
+
objectFromFormdata: () => objectFromFormdata,
|
|
131
135
|
off: () => off,
|
|
132
136
|
on: () => on,
|
|
133
137
|
parseNumeric: () => parseNumeric,
|
|
@@ -151,8 +155,10 @@ __export(index_exports, {
|
|
|
151
155
|
showOpenImagePicker: () => showOpenImagePicker,
|
|
152
156
|
slash: () => slash,
|
|
153
157
|
snakeCase: () => snakeCase,
|
|
158
|
+
stringify: () => stringify,
|
|
154
159
|
template: () => template,
|
|
155
160
|
to: () => to,
|
|
161
|
+
toArray: () => toArray,
|
|
156
162
|
trainCase: () => trainCase,
|
|
157
163
|
truncate: () => truncate_default,
|
|
158
164
|
unindent: () => unindent,
|
|
@@ -3308,190 +3314,6 @@ function splitPrefixSuffix(input, options = {}) {
|
|
|
3308
3314
|
|
|
3309
3315
|
// src/number/index.ts
|
|
3310
3316
|
var import_bignumber = __toESM(require("bignumber.js"), 1);
|
|
3311
|
-
var BIG_INTS = {
|
|
3312
|
-
t: { v: 10 ** 12, d: 13, n: "t" },
|
|
3313
|
-
b: { v: 10 ** 9, d: 10, n: "b" },
|
|
3314
|
-
m: { v: 10 ** 6, d: 7, n: "m" },
|
|
3315
|
-
k: { v: 10 ** 3, d: 4, n: "k" }
|
|
3316
|
-
};
|
|
3317
|
-
function bignum(n = "0") {
|
|
3318
|
-
return new import_bignumber.default(numfix(n));
|
|
3319
|
-
}
|
|
3320
|
-
function numfix(value) {
|
|
3321
|
-
return Number.isNaN(Number(value)) || value.toString() === "NaN" ? "0" : String(value);
|
|
3322
|
-
}
|
|
3323
|
-
function gte(a, b) {
|
|
3324
|
-
return bignum(a).gte(bignum(b));
|
|
3325
|
-
}
|
|
3326
|
-
function gt(a, b) {
|
|
3327
|
-
return bignum(a).gt(bignum(b));
|
|
3328
|
-
}
|
|
3329
|
-
function lte(a, b) {
|
|
3330
|
-
return bignum(a).lte(bignum(b));
|
|
3331
|
-
}
|
|
3332
|
-
function lt(a, b) {
|
|
3333
|
-
return bignum(a).lt(bignum(b));
|
|
3334
|
-
}
|
|
3335
|
-
function plus(array, options) {
|
|
3336
|
-
const rounding = options?.r || import_bignumber.default.ROUND_DOWN;
|
|
3337
|
-
const decimal2 = options?.d || 0;
|
|
3338
|
-
return array.filter((v) => bignum(v).gt(0)).reduce((t, v) => t.plus(bignum(v)), bignum(0)).toFixed(decimal2, rounding);
|
|
3339
|
-
}
|
|
3340
|
-
function average(array, options) {
|
|
3341
|
-
const rounding = options?.r || import_bignumber.default.ROUND_DOWN;
|
|
3342
|
-
const decimal2 = options?.d || 0;
|
|
3343
|
-
if (array.length === 0)
|
|
3344
|
-
return "0";
|
|
3345
|
-
return bignum(plus(array)).div(array.length).toFixed(decimal2, rounding);
|
|
3346
|
-
}
|
|
3347
|
-
function percentage(total, count, options) {
|
|
3348
|
-
options ??= { d: 3, r: import_bignumber.default.ROUND_DOWN };
|
|
3349
|
-
const rounding = options?.r || import_bignumber.default.ROUND_DOWN;
|
|
3350
|
-
const decimal2 = options?.d || 3;
|
|
3351
|
-
if (bignum(total).lte(0) || bignum(count).lte(0))
|
|
3352
|
-
return "0";
|
|
3353
|
-
return bignum(count).div(bignum(total)).times(100).toFixed(decimal2, rounding);
|
|
3354
|
-
}
|
|
3355
|
-
function zerofill(value, n = 2, type = "positive") {
|
|
3356
|
-
const _value = integer(value);
|
|
3357
|
-
if (_value.length >= n)
|
|
3358
|
-
return value;
|
|
3359
|
-
const zero = "0".repeat(n - _value.length);
|
|
3360
|
-
if (type === "positive")
|
|
3361
|
-
return zero + value;
|
|
3362
|
-
if (type === "reverse")
|
|
3363
|
-
return zero + value;
|
|
3364
|
-
return "";
|
|
3365
|
-
}
|
|
3366
|
-
function zeromove(value) {
|
|
3367
|
-
return value.toString().replace(/\.?0+$/, "");
|
|
3368
|
-
}
|
|
3369
|
-
function integer(value) {
|
|
3370
|
-
return new import_bignumber.default(numfix(value)).toFixed(0);
|
|
3371
|
-
}
|
|
3372
|
-
function decimal(value, n = 2) {
|
|
3373
|
-
let [integer2, decimal2] = numfix(value).split(".");
|
|
3374
|
-
if (n <= 0)
|
|
3375
|
-
return integer2;
|
|
3376
|
-
if (!decimal2)
|
|
3377
|
-
decimal2 = "0";
|
|
3378
|
-
decimal2 = decimal2.slice(0, n);
|
|
3379
|
-
decimal2 = decimal2 + "0".repeat(n - decimal2.length);
|
|
3380
|
-
return `${integer2}.${decimal2}`;
|
|
3381
|
-
}
|
|
3382
|
-
function parseNumeric(num, delimiters = ["t", "b", "m"]) {
|
|
3383
|
-
const mappings = [
|
|
3384
|
-
delimiters.includes("t") && ((n) => gte(n, BIG_INTS.t.v) && BIG_INTS.t),
|
|
3385
|
-
delimiters.includes("b") && ((n) => gte(n, BIG_INTS.b.v) && lt(n, BIG_INTS.t.v) && BIG_INTS.b),
|
|
3386
|
-
delimiters.includes("m") && ((n) => gte(n, BIG_INTS.m.v) && lt(n, BIG_INTS.b.v) && BIG_INTS.m),
|
|
3387
|
-
delimiters.includes("k") && ((n) => gte(n, BIG_INTS.k.v) && lt(n, BIG_INTS.m.v) && BIG_INTS.k)
|
|
3388
|
-
];
|
|
3389
|
-
let options;
|
|
3390
|
-
for (const analy of mappings) {
|
|
3391
|
-
const opts = analy && analy(bignum(num).toFixed(0));
|
|
3392
|
-
opts && (options = opts);
|
|
3393
|
-
}
|
|
3394
|
-
return options || { v: 1, d: 0, n: "" };
|
|
3395
|
-
}
|
|
3396
|
-
function formatNumeric(value = "0", options) {
|
|
3397
|
-
if (options?.default && bignum(value).isZero())
|
|
3398
|
-
return options?.default;
|
|
3399
|
-
const {
|
|
3400
|
-
rounding = import_bignumber.default.ROUND_DOWN,
|
|
3401
|
-
delimiters,
|
|
3402
|
-
format,
|
|
3403
|
-
decimals = 2
|
|
3404
|
-
} = options || {};
|
|
3405
|
-
const config = parseNumeric(value, delimiters || []);
|
|
3406
|
-
let number = bignum(value).div(config.v).toFormat(decimals, rounding, {
|
|
3407
|
-
decimalSeparator: ".",
|
|
3408
|
-
groupSeparator: ",",
|
|
3409
|
-
groupSize: 3,
|
|
3410
|
-
secondaryGroupSize: 0,
|
|
3411
|
-
fractionGroupSeparator: " ",
|
|
3412
|
-
fractionGroupSize: 0,
|
|
3413
|
-
...format
|
|
3414
|
-
});
|
|
3415
|
-
number = options?.zeromove ? zeromove(number) : number;
|
|
3416
|
-
return `${number}${config.n}`;
|
|
3417
|
-
}
|
|
3418
|
-
|
|
3419
|
-
// src/size/index.ts
|
|
3420
|
-
function formatUnit(value, unit = "px") {
|
|
3421
|
-
if (!(isString_default(value) || isNumber_default(value)))
|
|
3422
|
-
return "";
|
|
3423
|
-
value = String(value);
|
|
3424
|
-
return /\D/.test(value) ? value : value + unit;
|
|
3425
|
-
}
|
|
3426
|
-
function formatSize(dimension, unit) {
|
|
3427
|
-
const _formatUnit = (value) => formatUnit(value, unit);
|
|
3428
|
-
if (typeof dimension === "string" || typeof dimension === "number")
|
|
3429
|
-
return { width: _formatUnit(dimension), height: _formatUnit(dimension) };
|
|
3430
|
-
if (Array.isArray(dimension))
|
|
3431
|
-
return { width: _formatUnit(dimension[0]), height: _formatUnit(dimension[1]) };
|
|
3432
|
-
if (typeof dimension === "object")
|
|
3433
|
-
return { width: _formatUnit(dimension.width), height: _formatUnit(dimension.height) };
|
|
3434
|
-
return { width: "", height: "" };
|
|
3435
|
-
}
|
|
3436
|
-
|
|
3437
|
-
// src/string/index.ts
|
|
3438
|
-
function cover(value, mode, symbol = "*") {
|
|
3439
|
-
return value.slice(0, mode[0]) + symbol.repeat(mode[1]) + value.slice(-mode[2]);
|
|
3440
|
-
}
|
|
3441
|
-
function slash(str) {
|
|
3442
|
-
return str.replace(/\\/g, "/");
|
|
3443
|
-
}
|
|
3444
|
-
function ensurePrefix(prefix, str) {
|
|
3445
|
-
if (!str.startsWith(prefix))
|
|
3446
|
-
return prefix + str;
|
|
3447
|
-
return str;
|
|
3448
|
-
}
|
|
3449
|
-
function ensureSuffix(suffix, str) {
|
|
3450
|
-
if (!str.endsWith(suffix))
|
|
3451
|
-
return str + suffix;
|
|
3452
|
-
return str;
|
|
3453
|
-
}
|
|
3454
|
-
function template(str, ...args) {
|
|
3455
|
-
const [firstArg, fallback] = args;
|
|
3456
|
-
if (isObject_default(firstArg)) {
|
|
3457
|
-
const vars = firstArg;
|
|
3458
|
-
return str.replace(/\{(\w+)\}/g, (_, key) => vars[key] || ((typeof fallback === "function" ? fallback(key) : fallback) ?? key));
|
|
3459
|
-
} else {
|
|
3460
|
-
return str.replace(/\{(\d+)\}/g, (_, key) => {
|
|
3461
|
-
const index = Number(key);
|
|
3462
|
-
if (Number.isNaN(index))
|
|
3463
|
-
return key;
|
|
3464
|
-
return args[index];
|
|
3465
|
-
});
|
|
3466
|
-
}
|
|
3467
|
-
}
|
|
3468
|
-
var _reFullWs = /^\s*$/;
|
|
3469
|
-
function unindent(str) {
|
|
3470
|
-
const lines = (typeof str === "string" ? str : str[0]).split("\n");
|
|
3471
|
-
const whitespaceLines = lines.map((line) => _reFullWs.test(line));
|
|
3472
|
-
const commonIndent = lines.reduce((min, line, idx) => {
|
|
3473
|
-
if (whitespaceLines[idx])
|
|
3474
|
-
return min;
|
|
3475
|
-
const indent = line.match(/^\s*/)?.[0].length;
|
|
3476
|
-
return indent === void 0 ? min : Math.min(min, indent);
|
|
3477
|
-
}, Number.POSITIVE_INFINITY);
|
|
3478
|
-
let emptyLinesHead = 0;
|
|
3479
|
-
while (emptyLinesHead < lines.length && whitespaceLines[emptyLinesHead])
|
|
3480
|
-
emptyLinesHead++;
|
|
3481
|
-
let emptyLinesTail = 0;
|
|
3482
|
-
while (emptyLinesTail < lines.length && whitespaceLines[lines.length - emptyLinesTail - 1])
|
|
3483
|
-
emptyLinesTail++;
|
|
3484
|
-
return lines.slice(emptyLinesHead, lines.length - emptyLinesTail).map((line) => line.slice(commonIndent)).join("\n");
|
|
3485
|
-
}
|
|
3486
|
-
|
|
3487
|
-
// src/typeof/index.ts
|
|
3488
|
-
function getTypeof(target) {
|
|
3489
|
-
const value = Object.prototype.toString.call(target).slice(8, -1).toLocaleLowerCase();
|
|
3490
|
-
return value;
|
|
3491
|
-
}
|
|
3492
|
-
function isTypeof(target, type) {
|
|
3493
|
-
return getTypeof(target) === type;
|
|
3494
|
-
}
|
|
3495
3317
|
|
|
3496
3318
|
// src/util/compose-promise.ts
|
|
3497
3319
|
function pCompose(...fns) {
|
|
@@ -3513,13 +3335,30 @@ function compose(...fns) {
|
|
|
3513
3335
|
compose.promise = pCompose;
|
|
3514
3336
|
|
|
3515
3337
|
// src/util/converts.ts
|
|
3516
|
-
function
|
|
3338
|
+
function objectFromFormdata(formData) {
|
|
3517
3339
|
return Object.fromEntries(formData.entries());
|
|
3518
3340
|
}
|
|
3519
|
-
function
|
|
3520
|
-
const
|
|
3521
|
-
for (const [key, value] of Object.entries(object))
|
|
3522
|
-
|
|
3341
|
+
function formdataFromObject(object) {
|
|
3342
|
+
const formdata = new FormData();
|
|
3343
|
+
for (const [key, value] of Object.entries(object))
|
|
3344
|
+
formdata.set(key, value);
|
|
3345
|
+
return formdata;
|
|
3346
|
+
}
|
|
3347
|
+
function nonnanable(value) {
|
|
3348
|
+
return Number.isNaN(Number(value)) ? void 0 : value;
|
|
3349
|
+
}
|
|
3350
|
+
function numberify(value) {
|
|
3351
|
+
return Number.isNaN(Number(value)) ? 0 : Number(value);
|
|
3352
|
+
}
|
|
3353
|
+
function stringify(value) {
|
|
3354
|
+
return String(value);
|
|
3355
|
+
}
|
|
3356
|
+
function numberish(value) {
|
|
3357
|
+
if (value === void 0 || value === null)
|
|
3358
|
+
return "0";
|
|
3359
|
+
if (Number.isNaN(Number(value)))
|
|
3360
|
+
return "0";
|
|
3361
|
+
return value.toString();
|
|
3523
3362
|
}
|
|
3524
3363
|
|
|
3525
3364
|
// src/util/noop.ts
|
|
@@ -3662,6 +3501,13 @@ async function to(promise, error) {
|
|
|
3662
3501
|
});
|
|
3663
3502
|
}
|
|
3664
3503
|
|
|
3504
|
+
// src/util/to-array.ts
|
|
3505
|
+
function toArray(value) {
|
|
3506
|
+
if (!value)
|
|
3507
|
+
return void 0;
|
|
3508
|
+
return Array.isArray(value) ? value : [value];
|
|
3509
|
+
}
|
|
3510
|
+
|
|
3665
3511
|
// src/util/util.ts
|
|
3666
3512
|
function arange(x1, x2, stp = 1, z = [], z0 = z.length) {
|
|
3667
3513
|
if (!x2)
|
|
@@ -3686,14 +3532,210 @@ function whenever(value, callback) {
|
|
|
3686
3532
|
function call(fn, ...args) {
|
|
3687
3533
|
return fn(...args);
|
|
3688
3534
|
}
|
|
3535
|
+
|
|
3536
|
+
// src/number/index.ts
|
|
3537
|
+
var DEFAULT_BIGNUM_CONFIG = {
|
|
3538
|
+
ROUNDING_MODE: import_bignumber.default.ROUND_UP,
|
|
3539
|
+
DECIMAL_PLACES: 6
|
|
3540
|
+
};
|
|
3541
|
+
var BignumberCLONE = import_bignumber.default.clone(DEFAULT_BIGNUM_CONFIG);
|
|
3542
|
+
var BIG_INTS = {
|
|
3543
|
+
t: { v: 10 ** 12, d: 13, n: "t" },
|
|
3544
|
+
b: { v: 10 ** 9, d: 10, n: "b" },
|
|
3545
|
+
m: { v: 10 ** 6, d: 7, n: "m" },
|
|
3546
|
+
k: { v: 10 ** 3, d: 4, n: "k" }
|
|
3547
|
+
};
|
|
3548
|
+
function bignumber(n = "0", base) {
|
|
3549
|
+
return new BignumberCLONE(numberish(n), base);
|
|
3550
|
+
}
|
|
3551
|
+
bignumber.clone = function(config) {
|
|
3552
|
+
return import_bignumber.default.clone({ ...DEFAULT_BIGNUM_CONFIG, ...config });
|
|
3553
|
+
};
|
|
3554
|
+
function gte(a, b) {
|
|
3555
|
+
return bignumber(a).gte(bignumber(b));
|
|
3556
|
+
}
|
|
3557
|
+
function gt(a, b) {
|
|
3558
|
+
return bignumber(a).gt(bignumber(b));
|
|
3559
|
+
}
|
|
3560
|
+
function lte(a, b) {
|
|
3561
|
+
return bignumber(a).lte(bignumber(b));
|
|
3562
|
+
}
|
|
3563
|
+
function lt(a, b) {
|
|
3564
|
+
return bignumber(a).lt(bignumber(b));
|
|
3565
|
+
}
|
|
3566
|
+
function plus(array, options) {
|
|
3567
|
+
const rounding = options?.r || import_bignumber.default.ROUND_DOWN;
|
|
3568
|
+
const decimal2 = options?.d || 0;
|
|
3569
|
+
return array.filter((v) => bignumber(v).gt(0)).reduce((t, v) => t.plus(bignumber(v)), bignumber(0)).toFixed(decimal2, rounding);
|
|
3570
|
+
}
|
|
3571
|
+
function divs(array, options) {
|
|
3572
|
+
const rounding = options?.r || import_bignumber.default.ROUND_DOWN;
|
|
3573
|
+
const decimal2 = options?.d || 0;
|
|
3574
|
+
return array.reduce((t, v) => t.div(bignumber(v)), bignumber(1)).toFixed(decimal2, rounding);
|
|
3575
|
+
}
|
|
3576
|
+
function average(array, options) {
|
|
3577
|
+
const rounding = options?.r || import_bignumber.default.ROUND_DOWN;
|
|
3578
|
+
const decimal2 = options?.d || 0;
|
|
3579
|
+
if (array.length === 0)
|
|
3580
|
+
return "0";
|
|
3581
|
+
return bignumber(plus(array)).div(array.length).toFixed(decimal2, rounding);
|
|
3582
|
+
}
|
|
3583
|
+
function percentage(total, count, options) {
|
|
3584
|
+
options ??= { d: 3, r: import_bignumber.default.ROUND_DOWN };
|
|
3585
|
+
const rounding = options?.r || import_bignumber.default.ROUND_DOWN;
|
|
3586
|
+
const decimal2 = options?.d || 3;
|
|
3587
|
+
if (bignumber(total).lte(0) || bignumber(count).lte(0))
|
|
3588
|
+
return "0";
|
|
3589
|
+
return bignumber(count).div(bignumber(total)).times(100).toFixed(decimal2, rounding);
|
|
3590
|
+
}
|
|
3591
|
+
function zerofill(value, n = 2, type = "positive") {
|
|
3592
|
+
const _value = integer(value);
|
|
3593
|
+
if (_value.length >= n)
|
|
3594
|
+
return value;
|
|
3595
|
+
const zero = "0".repeat(n - _value.length);
|
|
3596
|
+
if (type === "positive")
|
|
3597
|
+
return zero + value;
|
|
3598
|
+
if (type === "reverse")
|
|
3599
|
+
return zero + value;
|
|
3600
|
+
return "";
|
|
3601
|
+
}
|
|
3602
|
+
function zeromove(value) {
|
|
3603
|
+
return numberish(value).toString().replace(/\.?0+$/, "");
|
|
3604
|
+
}
|
|
3605
|
+
function integer(value) {
|
|
3606
|
+
return new import_bignumber.default(numberish(value)).toFixed(0);
|
|
3607
|
+
}
|
|
3608
|
+
function decimal(value, n = 2) {
|
|
3609
|
+
let [integer2, decimal2] = numberish(value).split(".");
|
|
3610
|
+
if (n <= 0)
|
|
3611
|
+
return integer2;
|
|
3612
|
+
if (!decimal2)
|
|
3613
|
+
decimal2 = "0";
|
|
3614
|
+
decimal2 = decimal2.slice(0, n);
|
|
3615
|
+
decimal2 = decimal2 + "0".repeat(n - decimal2.length);
|
|
3616
|
+
return `${integer2}.${decimal2}`;
|
|
3617
|
+
}
|
|
3618
|
+
function parseNumeric(num, delimiters = ["t", "b", "m"]) {
|
|
3619
|
+
const mappings = [
|
|
3620
|
+
delimiters.includes("t") && ((n) => gte(n, BIG_INTS.t.v) && BIG_INTS.t),
|
|
3621
|
+
delimiters.includes("b") && ((n) => gte(n, BIG_INTS.b.v) && lt(n, BIG_INTS.t.v) && BIG_INTS.b),
|
|
3622
|
+
delimiters.includes("m") && ((n) => gte(n, BIG_INTS.m.v) && lt(n, BIG_INTS.b.v) && BIG_INTS.m),
|
|
3623
|
+
delimiters.includes("k") && ((n) => gte(n, BIG_INTS.k.v) && lt(n, BIG_INTS.m.v) && BIG_INTS.k)
|
|
3624
|
+
];
|
|
3625
|
+
let options;
|
|
3626
|
+
for (const analy of mappings) {
|
|
3627
|
+
const opts = analy && analy(bignumber(num).toFixed(0));
|
|
3628
|
+
opts && (options = opts);
|
|
3629
|
+
}
|
|
3630
|
+
return options || { v: 1, d: 0, n: "" };
|
|
3631
|
+
}
|
|
3632
|
+
function formatNumeric(value = "0", options) {
|
|
3633
|
+
if (options?.default && bignumber(value).isZero())
|
|
3634
|
+
return options?.default;
|
|
3635
|
+
const {
|
|
3636
|
+
rounding = import_bignumber.default.ROUND_DOWN,
|
|
3637
|
+
delimiters,
|
|
3638
|
+
format,
|
|
3639
|
+
decimals = 2
|
|
3640
|
+
} = options || {};
|
|
3641
|
+
const config = parseNumeric(value, delimiters || []);
|
|
3642
|
+
let number = bignumber(value).div(config.v).toFormat(decimals, rounding, {
|
|
3643
|
+
decimalSeparator: ".",
|
|
3644
|
+
groupSeparator: ",",
|
|
3645
|
+
groupSize: 3,
|
|
3646
|
+
secondaryGroupSize: 0,
|
|
3647
|
+
fractionGroupSeparator: " ",
|
|
3648
|
+
fractionGroupSize: 0,
|
|
3649
|
+
...format
|
|
3650
|
+
});
|
|
3651
|
+
number = options?.zeromove ? zeromove(number) : number;
|
|
3652
|
+
return `${number}${config.n}`;
|
|
3653
|
+
}
|
|
3654
|
+
|
|
3655
|
+
// src/size/index.ts
|
|
3656
|
+
function formatUnit(value, unit = "px") {
|
|
3657
|
+
if (!(isString_default(value) || isNumber_default(value)))
|
|
3658
|
+
return "";
|
|
3659
|
+
value = String(value);
|
|
3660
|
+
return /\D/.test(value) ? value : value + unit;
|
|
3661
|
+
}
|
|
3662
|
+
function formatSize(dimension, unit) {
|
|
3663
|
+
const _formatUnit = (value) => formatUnit(value, unit);
|
|
3664
|
+
if (typeof dimension === "string" || typeof dimension === "number")
|
|
3665
|
+
return { width: _formatUnit(dimension), height: _formatUnit(dimension) };
|
|
3666
|
+
if (Array.isArray(dimension))
|
|
3667
|
+
return { width: _formatUnit(dimension[0]), height: _formatUnit(dimension[1]) };
|
|
3668
|
+
if (typeof dimension === "object")
|
|
3669
|
+
return { width: _formatUnit(dimension.width), height: _formatUnit(dimension.height) };
|
|
3670
|
+
return { width: "", height: "" };
|
|
3671
|
+
}
|
|
3672
|
+
|
|
3673
|
+
// src/string/index.ts
|
|
3674
|
+
function cover(value, mode, symbol = "*") {
|
|
3675
|
+
return value.slice(0, mode[0]) + symbol.repeat(mode[1]) + value.slice(-mode[2]);
|
|
3676
|
+
}
|
|
3677
|
+
function slash(str) {
|
|
3678
|
+
return str.replace(/\\/g, "/");
|
|
3679
|
+
}
|
|
3680
|
+
function ensurePrefix(prefix, str) {
|
|
3681
|
+
if (!str.startsWith(prefix))
|
|
3682
|
+
return prefix + str;
|
|
3683
|
+
return str;
|
|
3684
|
+
}
|
|
3685
|
+
function ensureSuffix(suffix, str) {
|
|
3686
|
+
if (!str.endsWith(suffix))
|
|
3687
|
+
return str + suffix;
|
|
3688
|
+
return str;
|
|
3689
|
+
}
|
|
3690
|
+
function template(str, ...args) {
|
|
3691
|
+
const [firstArg, fallback] = args;
|
|
3692
|
+
if (isObject_default(firstArg)) {
|
|
3693
|
+
const vars = firstArg;
|
|
3694
|
+
return str.replace(/\{(\w+)\}/g, (_, key) => vars[key] || ((typeof fallback === "function" ? fallback(key) : fallback) ?? key));
|
|
3695
|
+
} else {
|
|
3696
|
+
return str.replace(/\{(\d+)\}/g, (_, key) => {
|
|
3697
|
+
const index = Number(key);
|
|
3698
|
+
if (Number.isNaN(index))
|
|
3699
|
+
return key;
|
|
3700
|
+
return args[index];
|
|
3701
|
+
});
|
|
3702
|
+
}
|
|
3703
|
+
}
|
|
3704
|
+
var _reFullWs = /^\s*$/;
|
|
3705
|
+
function unindent(str) {
|
|
3706
|
+
const lines = (typeof str === "string" ? str : str[0]).split("\n");
|
|
3707
|
+
const whitespaceLines = lines.map((line) => _reFullWs.test(line));
|
|
3708
|
+
const commonIndent = lines.reduce((min, line, idx) => {
|
|
3709
|
+
if (whitespaceLines[idx])
|
|
3710
|
+
return min;
|
|
3711
|
+
const indent = line.match(/^\s*/)?.[0].length;
|
|
3712
|
+
return indent === void 0 ? min : Math.min(min, indent);
|
|
3713
|
+
}, Number.POSITIVE_INFINITY);
|
|
3714
|
+
let emptyLinesHead = 0;
|
|
3715
|
+
while (emptyLinesHead < lines.length && whitespaceLines[emptyLinesHead])
|
|
3716
|
+
emptyLinesHead++;
|
|
3717
|
+
let emptyLinesTail = 0;
|
|
3718
|
+
while (emptyLinesTail < lines.length && whitespaceLines[lines.length - emptyLinesTail - 1])
|
|
3719
|
+
emptyLinesTail++;
|
|
3720
|
+
return lines.slice(emptyLinesHead, lines.length - emptyLinesTail).map((line) => line.slice(commonIndent)).join("\n");
|
|
3721
|
+
}
|
|
3722
|
+
|
|
3723
|
+
// src/typeof/index.ts
|
|
3724
|
+
function getTypeof(target) {
|
|
3725
|
+
const value = Object.prototype.toString.call(target).slice(8, -1).toLocaleLowerCase();
|
|
3726
|
+
return value;
|
|
3727
|
+
}
|
|
3728
|
+
function isTypeof(target, type) {
|
|
3729
|
+
return getTypeof(target) === type;
|
|
3730
|
+
}
|
|
3689
3731
|
// Annotate the CommonJS export names for ESM import in node:
|
|
3690
3732
|
0 && (module.exports = {
|
|
3691
3733
|
BIG_INTS,
|
|
3692
|
-
|
|
3734
|
+
DEFAULT_BIGNUM_CONFIG,
|
|
3693
3735
|
Deferred,
|
|
3694
3736
|
arange,
|
|
3695
3737
|
average,
|
|
3696
|
-
|
|
3738
|
+
bignumber,
|
|
3697
3739
|
call,
|
|
3698
3740
|
camelCase,
|
|
3699
3741
|
capitalCase,
|
|
@@ -3709,16 +3751,18 @@ function call(fn, ...args) {
|
|
|
3709
3751
|
decimal,
|
|
3710
3752
|
delay,
|
|
3711
3753
|
dialsPhone,
|
|
3754
|
+
divs,
|
|
3712
3755
|
dotCase,
|
|
3713
3756
|
downloadBlobFile,
|
|
3714
3757
|
downloadNetworkFile,
|
|
3715
3758
|
ensurePrefix,
|
|
3716
3759
|
ensureSuffix,
|
|
3717
3760
|
find,
|
|
3718
|
-
formToObject,
|
|
3719
3761
|
formatNumeric,
|
|
3720
3762
|
formatSize,
|
|
3721
3763
|
formatUnit,
|
|
3764
|
+
formdataFromObject,
|
|
3765
|
+
get,
|
|
3722
3766
|
getTypeof,
|
|
3723
3767
|
groupBy,
|
|
3724
3768
|
gt,
|
|
@@ -3783,9 +3827,11 @@ function call(fn, ...args) {
|
|
|
3783
3827
|
merge,
|
|
3784
3828
|
mergeWith,
|
|
3785
3829
|
noCase,
|
|
3830
|
+
nonnanable,
|
|
3786
3831
|
noop,
|
|
3787
|
-
|
|
3788
|
-
|
|
3832
|
+
numberify,
|
|
3833
|
+
numberish,
|
|
3834
|
+
objectFromFormdata,
|
|
3789
3835
|
off,
|
|
3790
3836
|
on,
|
|
3791
3837
|
parseNumeric,
|
|
@@ -3809,8 +3855,10 @@ function call(fn, ...args) {
|
|
|
3809
3855
|
showOpenImagePicker,
|
|
3810
3856
|
slash,
|
|
3811
3857
|
snakeCase,
|
|
3858
|
+
stringify,
|
|
3812
3859
|
template,
|
|
3813
3860
|
to,
|
|
3861
|
+
toArray,
|
|
3814
3862
|
trainCase,
|
|
3815
3863
|
truncate,
|
|
3816
3864
|
unindent,
|
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';
|
|
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
2
|
import Bignumber from 'bignumber.js';
|
|
3
|
-
export { default as 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,7 @@ 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;
|
|
213
224
|
declare const BIG_INTS: {
|
|
214
225
|
t: {
|
|
215
226
|
v: number;
|
|
@@ -232,12 +243,6 @@ declare const BIG_INTS: {
|
|
|
232
243
|
n: string;
|
|
233
244
|
};
|
|
234
245
|
};
|
|
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
246
|
type Delimiter = 'k' | 'm' | 'b' | 't';
|
|
242
247
|
interface DecimalOptions {
|
|
243
248
|
d?: number;
|
|
@@ -255,13 +260,16 @@ interface FormatNumericOptions {
|
|
|
255
260
|
default?: string;
|
|
256
261
|
format?: Bignumber.Format;
|
|
257
262
|
}
|
|
258
|
-
declare function
|
|
259
|
-
declare
|
|
263
|
+
declare function bignumber(n?: Numberish, base?: number): Bignumber;
|
|
264
|
+
declare namespace bignumber {
|
|
265
|
+
var clone: (config: Bignumber.Config) => typeof Bignumber;
|
|
266
|
+
}
|
|
260
267
|
declare function gte(a: Numberish, b: Numberish): boolean;
|
|
261
268
|
declare function gt(a: Numberish, b: Numberish): boolean;
|
|
262
269
|
declare function lte(a: Numberish, b: Numberish): boolean;
|
|
263
270
|
declare function lt(a: Numberish, b: Numberish): boolean;
|
|
264
271
|
declare function plus(array: Numberish[], options?: DecimalOptions): string;
|
|
272
|
+
declare function divs(array: Numberish[], options?: DecimalOptions): string;
|
|
265
273
|
declare function average(array: Numberish[], options?: DecimalOptions): string;
|
|
266
274
|
/**
|
|
267
275
|
* calculate percentage
|
|
@@ -297,7 +305,6 @@ declare function parseNumeric(num: Numberish, delimiters?: Delimiter[]): {
|
|
|
297
305
|
* format number thousand separator and unit
|
|
298
306
|
* @param value
|
|
299
307
|
* @param options
|
|
300
|
-
* @returns
|
|
301
308
|
*/
|
|
302
309
|
declare function formatNumeric(value?: Numberish, options?: FormatNumericOptions): string;
|
|
303
310
|
|
|
@@ -477,12 +484,36 @@ declare namespace compose {
|
|
|
477
484
|
* formData to object
|
|
478
485
|
* @param formData
|
|
479
486
|
*/
|
|
480
|
-
declare function
|
|
487
|
+
declare function objectFromFormdata(formData: FormData): Record<string, string>;
|
|
481
488
|
/**
|
|
482
489
|
* Object to formData
|
|
483
490
|
* @param object
|
|
484
491
|
*/
|
|
485
|
-
declare function
|
|
492
|
+
declare function formdataFromObject(object: Record<string, string | File>): FormData;
|
|
493
|
+
/**
|
|
494
|
+
* Check if a value is not NaN.
|
|
495
|
+
* @param value - The value to check.
|
|
496
|
+
* @returns The value if it is not NaN, otherwise undefined.
|
|
497
|
+
*/
|
|
498
|
+
declare function nonnanable<T>(value: T): T | undefined;
|
|
499
|
+
/**
|
|
500
|
+
* Convert a value to a number.
|
|
501
|
+
* @param value - The value to convert to a number.
|
|
502
|
+
* @returns The number value.
|
|
503
|
+
*/
|
|
504
|
+
declare function numberify(value: any): number;
|
|
505
|
+
/**
|
|
506
|
+
* Convert a value to a string.
|
|
507
|
+
* @param value - The value to convert to a string.
|
|
508
|
+
* @returns The string value.
|
|
509
|
+
*/
|
|
510
|
+
declare function stringify(value: any): string;
|
|
511
|
+
/**
|
|
512
|
+
* Convert a value to a numberish value.
|
|
513
|
+
* @param value - The value to convert to a numberish value.
|
|
514
|
+
* @returns The numberish value.
|
|
515
|
+
*/
|
|
516
|
+
declare function numberish(value: Numberish): string;
|
|
486
517
|
|
|
487
518
|
declare class Deferred<T> extends Promise<T> {
|
|
488
519
|
resolve: (value?: T) => Deferred<T>;
|
|
@@ -595,10 +626,12 @@ declare function randomString(size: number, chars?: string): string;
|
|
|
595
626
|
|
|
596
627
|
declare function to<T, U = Error>(promise: Promise<T> | (() => Promise<T>), error?: object): Promise<[U, undefined] | [null, T]>;
|
|
597
628
|
|
|
629
|
+
declare function toArray<T>(value?: T | T[]): T[] | undefined;
|
|
630
|
+
|
|
598
631
|
declare function arange(x1: number, x2?: number, stp?: number, z?: number[], z0?: number): number[];
|
|
599
632
|
declare function riposte<T>(...args: [cond: boolean, value: T][]): T;
|
|
600
633
|
declare function unwrap<T extends object>(value: T | (() => T)): T;
|
|
601
634
|
declare function whenever<T, C extends (value: Exclude<T, null | undefined>) => any>(value: T, callback: C): ReturnType<C> | undefined;
|
|
602
635
|
declare function call<T extends Fn$1<any>>(fn: T, ...args: Parameters<T>): ReturnType<T>;
|
|
603
636
|
|
|
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,
|
|
637
|
+
export { type AnyFn, type ArgumentsType, type Arrayable, type Assign, type Awaitable, BIG_INTS, 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 };
|