@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.cjs
CHANGED
|
@@ -31,11 +31,12 @@ 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
|
-
Bignumber: () =>
|
|
34
|
+
Bignumber: () => Bignumber,
|
|
35
|
+
DEFAULT_BIGNUM_CONFIG: () => DEFAULT_BIGNUM_CONFIG,
|
|
35
36
|
Deferred: () => Deferred,
|
|
36
37
|
arange: () => arange,
|
|
37
38
|
average: () => average,
|
|
38
|
-
|
|
39
|
+
bignumber: () => bignumber,
|
|
39
40
|
call: () => call,
|
|
40
41
|
camelCase: () => camelCase,
|
|
41
42
|
capitalCase: () => capitalCase,
|
|
@@ -51,16 +52,18 @@ __export(index_exports, {
|
|
|
51
52
|
decimal: () => decimal,
|
|
52
53
|
delay: () => delay,
|
|
53
54
|
dialsPhone: () => dialsPhone,
|
|
55
|
+
divs: () => divs,
|
|
54
56
|
dotCase: () => dotCase,
|
|
55
57
|
downloadBlobFile: () => downloadBlobFile,
|
|
56
58
|
downloadNetworkFile: () => downloadNetworkFile,
|
|
57
59
|
ensurePrefix: () => ensurePrefix,
|
|
58
60
|
ensureSuffix: () => ensureSuffix,
|
|
59
61
|
find: () => find_default,
|
|
60
|
-
formToObject: () => formToObject,
|
|
61
62
|
formatNumeric: () => formatNumeric,
|
|
62
63
|
formatSize: () => formatSize,
|
|
63
64
|
formatUnit: () => formatUnit,
|
|
65
|
+
formdataFromObject: () => formdataFromObject,
|
|
66
|
+
get: () => get_default,
|
|
64
67
|
getTypeof: () => getTypeof,
|
|
65
68
|
groupBy: () => groupBy_default,
|
|
66
69
|
gt: () => gt,
|
|
@@ -125,9 +128,11 @@ __export(index_exports, {
|
|
|
125
128
|
merge: () => merge_default,
|
|
126
129
|
mergeWith: () => mergeWith_default,
|
|
127
130
|
noCase: () => noCase,
|
|
131
|
+
nonnanable: () => nonnanable,
|
|
128
132
|
noop: () => noop2,
|
|
129
|
-
|
|
130
|
-
|
|
133
|
+
numberify: () => numberify,
|
|
134
|
+
numberish: () => numberish,
|
|
135
|
+
objectFromFormdata: () => objectFromFormdata,
|
|
131
136
|
off: () => off,
|
|
132
137
|
on: () => on,
|
|
133
138
|
parseNumeric: () => parseNumeric,
|
|
@@ -151,8 +156,10 @@ __export(index_exports, {
|
|
|
151
156
|
showOpenImagePicker: () => showOpenImagePicker,
|
|
152
157
|
slash: () => slash,
|
|
153
158
|
snakeCase: () => snakeCase,
|
|
159
|
+
stringify: () => stringify,
|
|
154
160
|
template: () => template,
|
|
155
161
|
to: () => to,
|
|
162
|
+
toArray: () => toArray,
|
|
156
163
|
trainCase: () => trainCase,
|
|
157
164
|
truncate: () => truncate_default,
|
|
158
165
|
unindent: () => unindent,
|
|
@@ -3308,190 +3315,6 @@ function splitPrefixSuffix(input, options = {}) {
|
|
|
3308
3315
|
|
|
3309
3316
|
// src/number/index.ts
|
|
3310
3317
|
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
3318
|
|
|
3496
3319
|
// src/util/compose-promise.ts
|
|
3497
3320
|
function pCompose(...fns) {
|
|
@@ -3513,13 +3336,30 @@ function compose(...fns) {
|
|
|
3513
3336
|
compose.promise = pCompose;
|
|
3514
3337
|
|
|
3515
3338
|
// src/util/converts.ts
|
|
3516
|
-
function
|
|
3339
|
+
function objectFromFormdata(formData) {
|
|
3517
3340
|
return Object.fromEntries(formData.entries());
|
|
3518
3341
|
}
|
|
3519
|
-
function
|
|
3520
|
-
const
|
|
3521
|
-
for (const [key, value] of Object.entries(object))
|
|
3522
|
-
|
|
3342
|
+
function formdataFromObject(object) {
|
|
3343
|
+
const formdata = new FormData();
|
|
3344
|
+
for (const [key, value] of Object.entries(object))
|
|
3345
|
+
formdata.set(key, value);
|
|
3346
|
+
return formdata;
|
|
3347
|
+
}
|
|
3348
|
+
function nonnanable(value) {
|
|
3349
|
+
return Number.isNaN(Number(value)) ? void 0 : value;
|
|
3350
|
+
}
|
|
3351
|
+
function numberify(value) {
|
|
3352
|
+
return Number.isNaN(Number(value)) ? 0 : Number(value);
|
|
3353
|
+
}
|
|
3354
|
+
function stringify(value) {
|
|
3355
|
+
return String(value);
|
|
3356
|
+
}
|
|
3357
|
+
function numberish(value) {
|
|
3358
|
+
if (value === void 0 || value === null)
|
|
3359
|
+
return "0";
|
|
3360
|
+
if (Number.isNaN(Number(value)))
|
|
3361
|
+
return "0";
|
|
3362
|
+
return value.toString();
|
|
3523
3363
|
}
|
|
3524
3364
|
|
|
3525
3365
|
// src/util/noop.ts
|
|
@@ -3662,6 +3502,13 @@ async function to(promise, error) {
|
|
|
3662
3502
|
});
|
|
3663
3503
|
}
|
|
3664
3504
|
|
|
3505
|
+
// src/util/to-array.ts
|
|
3506
|
+
function toArray(value) {
|
|
3507
|
+
if (!value)
|
|
3508
|
+
return void 0;
|
|
3509
|
+
return Array.isArray(value) ? value : [value];
|
|
3510
|
+
}
|
|
3511
|
+
|
|
3665
3512
|
// src/util/util.ts
|
|
3666
3513
|
function arange(x1, x2, stp = 1, z = [], z0 = z.length) {
|
|
3667
3514
|
if (!x2)
|
|
@@ -3686,14 +3533,211 @@ function whenever(value, callback) {
|
|
|
3686
3533
|
function call(fn, ...args) {
|
|
3687
3534
|
return fn(...args);
|
|
3688
3535
|
}
|
|
3536
|
+
|
|
3537
|
+
// src/number/index.ts
|
|
3538
|
+
var DEFAULT_BIGNUM_CONFIG = {
|
|
3539
|
+
ROUNDING_MODE: import_bignumber.default.ROUND_UP,
|
|
3540
|
+
DECIMAL_PLACES: 6
|
|
3541
|
+
};
|
|
3542
|
+
var Bignumber = import_bignumber.default.clone(DEFAULT_BIGNUM_CONFIG);
|
|
3543
|
+
var BIG_INTS = {
|
|
3544
|
+
t: { v: 10 ** 12, d: 13, n: "t" },
|
|
3545
|
+
b: { v: 10 ** 9, d: 10, n: "b" },
|
|
3546
|
+
m: { v: 10 ** 6, d: 7, n: "m" },
|
|
3547
|
+
k: { v: 10 ** 3, d: 4, n: "k" }
|
|
3548
|
+
};
|
|
3549
|
+
function bignumber(n = "0", base) {
|
|
3550
|
+
return new Bignumber(numberish(n), base);
|
|
3551
|
+
}
|
|
3552
|
+
bignumber.clone = function(config) {
|
|
3553
|
+
return Bignumber.clone({ ...DEFAULT_BIGNUM_CONFIG, ...config });
|
|
3554
|
+
};
|
|
3555
|
+
function gte(a, b) {
|
|
3556
|
+
return bignumber(a).gte(bignumber(b));
|
|
3557
|
+
}
|
|
3558
|
+
function gt(a, b) {
|
|
3559
|
+
return bignumber(a).gt(bignumber(b));
|
|
3560
|
+
}
|
|
3561
|
+
function lte(a, b) {
|
|
3562
|
+
return bignumber(a).lte(bignumber(b));
|
|
3563
|
+
}
|
|
3564
|
+
function lt(a, b) {
|
|
3565
|
+
return bignumber(a).lt(bignumber(b));
|
|
3566
|
+
}
|
|
3567
|
+
function plus(array, options) {
|
|
3568
|
+
const rounding = options?.r || Bignumber.ROUND_DOWN;
|
|
3569
|
+
const decimal2 = options?.d || 0;
|
|
3570
|
+
return array.filter((v) => bignumber(v).gt(0)).reduce((t, v) => t.plus(bignumber(v)), bignumber(0)).toFixed(decimal2, rounding);
|
|
3571
|
+
}
|
|
3572
|
+
function divs(array, options) {
|
|
3573
|
+
const rounding = options?.r || Bignumber.ROUND_DOWN;
|
|
3574
|
+
const decimal2 = options?.d || 0;
|
|
3575
|
+
return array.reduce((t, v) => t.div(bignumber(v)), bignumber(1)).toFixed(decimal2, rounding);
|
|
3576
|
+
}
|
|
3577
|
+
function average(array, options) {
|
|
3578
|
+
const rounding = options?.r || Bignumber.ROUND_DOWN;
|
|
3579
|
+
const decimal2 = options?.d || 0;
|
|
3580
|
+
if (array.length === 0)
|
|
3581
|
+
return "0";
|
|
3582
|
+
return bignumber(plus(array)).div(array.length).toFixed(decimal2, rounding);
|
|
3583
|
+
}
|
|
3584
|
+
function percentage(total, count, options) {
|
|
3585
|
+
options ??= { d: 3, r: Bignumber.ROUND_DOWN };
|
|
3586
|
+
const rounding = options?.r || Bignumber.ROUND_DOWN;
|
|
3587
|
+
const decimal2 = options?.d || 3;
|
|
3588
|
+
if (bignumber(total).lte(0) || bignumber(count).lte(0))
|
|
3589
|
+
return "0";
|
|
3590
|
+
return bignumber(count).div(bignumber(total)).times(100).toFixed(decimal2, rounding);
|
|
3591
|
+
}
|
|
3592
|
+
function zerofill(value, n = 2, type = "positive") {
|
|
3593
|
+
const _value = integer(value);
|
|
3594
|
+
if (_value.length >= n)
|
|
3595
|
+
return value;
|
|
3596
|
+
const zero = "0".repeat(n - _value.length);
|
|
3597
|
+
if (type === "positive")
|
|
3598
|
+
return zero + value;
|
|
3599
|
+
if (type === "reverse")
|
|
3600
|
+
return zero + value;
|
|
3601
|
+
return "";
|
|
3602
|
+
}
|
|
3603
|
+
function zeromove(value) {
|
|
3604
|
+
return numberish(value).toString().replace(/\.?0+$/, "");
|
|
3605
|
+
}
|
|
3606
|
+
function integer(value) {
|
|
3607
|
+
return new Bignumber(numberish(value)).toFixed(0);
|
|
3608
|
+
}
|
|
3609
|
+
function decimal(value, n = 2) {
|
|
3610
|
+
let [integer2, decimal2] = numberish(value).split(".");
|
|
3611
|
+
if (n <= 0)
|
|
3612
|
+
return integer2;
|
|
3613
|
+
if (!decimal2)
|
|
3614
|
+
decimal2 = "0";
|
|
3615
|
+
decimal2 = decimal2.slice(0, n);
|
|
3616
|
+
decimal2 = decimal2 + "0".repeat(n - decimal2.length);
|
|
3617
|
+
return `${integer2}.${decimal2}`;
|
|
3618
|
+
}
|
|
3619
|
+
function parseNumeric(num, delimiters = ["t", "b", "m"]) {
|
|
3620
|
+
const mappings = [
|
|
3621
|
+
delimiters.includes("t") && ((n) => gte(n, BIG_INTS.t.v) && BIG_INTS.t),
|
|
3622
|
+
delimiters.includes("b") && ((n) => gte(n, BIG_INTS.b.v) && lt(n, BIG_INTS.t.v) && BIG_INTS.b),
|
|
3623
|
+
delimiters.includes("m") && ((n) => gte(n, BIG_INTS.m.v) && lt(n, BIG_INTS.b.v) && BIG_INTS.m),
|
|
3624
|
+
delimiters.includes("k") && ((n) => gte(n, BIG_INTS.k.v) && lt(n, BIG_INTS.m.v) && BIG_INTS.k)
|
|
3625
|
+
];
|
|
3626
|
+
let options;
|
|
3627
|
+
for (const analy of mappings) {
|
|
3628
|
+
const opts = analy && analy(bignumber(num).toFixed(0));
|
|
3629
|
+
opts && (options = opts);
|
|
3630
|
+
}
|
|
3631
|
+
return options || { v: 1, d: 0, n: "" };
|
|
3632
|
+
}
|
|
3633
|
+
function formatNumeric(value = "0", options) {
|
|
3634
|
+
if (options?.default && bignumber(value).isZero())
|
|
3635
|
+
return options?.default;
|
|
3636
|
+
const {
|
|
3637
|
+
rounding = Bignumber.ROUND_DOWN,
|
|
3638
|
+
delimiters,
|
|
3639
|
+
format,
|
|
3640
|
+
decimals = 2
|
|
3641
|
+
} = options || {};
|
|
3642
|
+
const config = parseNumeric(value, delimiters || []);
|
|
3643
|
+
let number = bignumber(value).div(config.v).toFormat(decimals, rounding, {
|
|
3644
|
+
decimalSeparator: ".",
|
|
3645
|
+
groupSeparator: ",",
|
|
3646
|
+
groupSize: 3,
|
|
3647
|
+
secondaryGroupSize: 0,
|
|
3648
|
+
fractionGroupSeparator: " ",
|
|
3649
|
+
fractionGroupSize: 0,
|
|
3650
|
+
...format
|
|
3651
|
+
});
|
|
3652
|
+
number = options?.zeromove ? zeromove(number) : number;
|
|
3653
|
+
return `${number}${config.n}`;
|
|
3654
|
+
}
|
|
3655
|
+
|
|
3656
|
+
// src/size/index.ts
|
|
3657
|
+
function formatUnit(value, unit = "px") {
|
|
3658
|
+
if (!(isString_default(value) || isNumber_default(value)))
|
|
3659
|
+
return "";
|
|
3660
|
+
value = String(value);
|
|
3661
|
+
return /\D/.test(value) ? value : value + unit;
|
|
3662
|
+
}
|
|
3663
|
+
function formatSize(dimension, unit) {
|
|
3664
|
+
const _formatUnit = (value) => formatUnit(value, unit);
|
|
3665
|
+
if (typeof dimension === "string" || typeof dimension === "number")
|
|
3666
|
+
return { width: _formatUnit(dimension), height: _formatUnit(dimension) };
|
|
3667
|
+
if (Array.isArray(dimension))
|
|
3668
|
+
return { width: _formatUnit(dimension[0]), height: _formatUnit(dimension[1]) };
|
|
3669
|
+
if (typeof dimension === "object")
|
|
3670
|
+
return { width: _formatUnit(dimension.width), height: _formatUnit(dimension.height) };
|
|
3671
|
+
return { width: "", height: "" };
|
|
3672
|
+
}
|
|
3673
|
+
|
|
3674
|
+
// src/string/index.ts
|
|
3675
|
+
function cover(value, mode, symbol = "*") {
|
|
3676
|
+
return value.slice(0, mode[0]) + symbol.repeat(mode[1]) + value.slice(-mode[2]);
|
|
3677
|
+
}
|
|
3678
|
+
function slash(str) {
|
|
3679
|
+
return str.replace(/\\/g, "/");
|
|
3680
|
+
}
|
|
3681
|
+
function ensurePrefix(prefix, str) {
|
|
3682
|
+
if (!str.startsWith(prefix))
|
|
3683
|
+
return prefix + str;
|
|
3684
|
+
return str;
|
|
3685
|
+
}
|
|
3686
|
+
function ensureSuffix(suffix, str) {
|
|
3687
|
+
if (!str.endsWith(suffix))
|
|
3688
|
+
return str + suffix;
|
|
3689
|
+
return str;
|
|
3690
|
+
}
|
|
3691
|
+
function template(str, ...args) {
|
|
3692
|
+
const [firstArg, fallback] = args;
|
|
3693
|
+
if (isObject_default(firstArg)) {
|
|
3694
|
+
const vars = firstArg;
|
|
3695
|
+
return str.replace(/\{(\w+)\}/g, (_, key) => vars[key] || ((typeof fallback === "function" ? fallback(key) : fallback) ?? key));
|
|
3696
|
+
} else {
|
|
3697
|
+
return str.replace(/\{(\d+)\}/g, (_, key) => {
|
|
3698
|
+
const index = Number(key);
|
|
3699
|
+
if (Number.isNaN(index))
|
|
3700
|
+
return key;
|
|
3701
|
+
return args[index];
|
|
3702
|
+
});
|
|
3703
|
+
}
|
|
3704
|
+
}
|
|
3705
|
+
var _reFullWs = /^\s*$/;
|
|
3706
|
+
function unindent(str) {
|
|
3707
|
+
const lines = (typeof str === "string" ? str : str[0]).split("\n");
|
|
3708
|
+
const whitespaceLines = lines.map((line) => _reFullWs.test(line));
|
|
3709
|
+
const commonIndent = lines.reduce((min, line, idx) => {
|
|
3710
|
+
if (whitespaceLines[idx])
|
|
3711
|
+
return min;
|
|
3712
|
+
const indent = line.match(/^\s*/)?.[0].length;
|
|
3713
|
+
return indent === void 0 ? min : Math.min(min, indent);
|
|
3714
|
+
}, Number.POSITIVE_INFINITY);
|
|
3715
|
+
let emptyLinesHead = 0;
|
|
3716
|
+
while (emptyLinesHead < lines.length && whitespaceLines[emptyLinesHead])
|
|
3717
|
+
emptyLinesHead++;
|
|
3718
|
+
let emptyLinesTail = 0;
|
|
3719
|
+
while (emptyLinesTail < lines.length && whitespaceLines[lines.length - emptyLinesTail - 1])
|
|
3720
|
+
emptyLinesTail++;
|
|
3721
|
+
return lines.slice(emptyLinesHead, lines.length - emptyLinesTail).map((line) => line.slice(commonIndent)).join("\n");
|
|
3722
|
+
}
|
|
3723
|
+
|
|
3724
|
+
// src/typeof/index.ts
|
|
3725
|
+
function getTypeof(target) {
|
|
3726
|
+
const value = Object.prototype.toString.call(target).slice(8, -1).toLocaleLowerCase();
|
|
3727
|
+
return value;
|
|
3728
|
+
}
|
|
3729
|
+
function isTypeof(target, type) {
|
|
3730
|
+
return getTypeof(target) === type;
|
|
3731
|
+
}
|
|
3689
3732
|
// Annotate the CommonJS export names for ESM import in node:
|
|
3690
3733
|
0 && (module.exports = {
|
|
3691
3734
|
BIG_INTS,
|
|
3692
3735
|
Bignumber,
|
|
3736
|
+
DEFAULT_BIGNUM_CONFIG,
|
|
3693
3737
|
Deferred,
|
|
3694
3738
|
arange,
|
|
3695
3739
|
average,
|
|
3696
|
-
|
|
3740
|
+
bignumber,
|
|
3697
3741
|
call,
|
|
3698
3742
|
camelCase,
|
|
3699
3743
|
capitalCase,
|
|
@@ -3709,16 +3753,18 @@ function call(fn, ...args) {
|
|
|
3709
3753
|
decimal,
|
|
3710
3754
|
delay,
|
|
3711
3755
|
dialsPhone,
|
|
3756
|
+
divs,
|
|
3712
3757
|
dotCase,
|
|
3713
3758
|
downloadBlobFile,
|
|
3714
3759
|
downloadNetworkFile,
|
|
3715
3760
|
ensurePrefix,
|
|
3716
3761
|
ensureSuffix,
|
|
3717
3762
|
find,
|
|
3718
|
-
formToObject,
|
|
3719
3763
|
formatNumeric,
|
|
3720
3764
|
formatSize,
|
|
3721
3765
|
formatUnit,
|
|
3766
|
+
formdataFromObject,
|
|
3767
|
+
get,
|
|
3722
3768
|
getTypeof,
|
|
3723
3769
|
groupBy,
|
|
3724
3770
|
gt,
|
|
@@ -3783,9 +3829,11 @@ function call(fn, ...args) {
|
|
|
3783
3829
|
merge,
|
|
3784
3830
|
mergeWith,
|
|
3785
3831
|
noCase,
|
|
3832
|
+
nonnanable,
|
|
3786
3833
|
noop,
|
|
3787
|
-
|
|
3788
|
-
|
|
3834
|
+
numberify,
|
|
3835
|
+
numberish,
|
|
3836
|
+
objectFromFormdata,
|
|
3789
3837
|
off,
|
|
3790
3838
|
on,
|
|
3791
3839
|
parseNumeric,
|
|
@@ -3809,8 +3857,10 @@ function call(fn, ...args) {
|
|
|
3809
3857
|
showOpenImagePicker,
|
|
3810
3858
|
slash,
|
|
3811
3859
|
snakeCase,
|
|
3860
|
+
stringify,
|
|
3812
3861
|
template,
|
|
3813
3862
|
to,
|
|
3863
|
+
toArray,
|
|
3814
3864
|
trainCase,
|
|
3815
3865
|
truncate,
|
|
3816
3866
|
unindent,
|