@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.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 BignumberCLONE = 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 BignumberCLONE(numberish(n), base);
|
|
4718
|
+
}
|
|
4719
|
+
bignumber.clone = function(config) {
|
|
4720
|
+
return bignumber_default.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_default.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_default.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_default.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_default.ROUND_DOWN };
|
|
4753
|
+
const rounding = options?.r || bignumber_default.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_default(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_default.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
|
|