@base-web-kits/base-tools-web 1.1.8 → 1.1.10
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/base-tools-web.umd.global.js +3 -2
- package/dist/base-tools-web.umd.global.js.map +1 -1
- package/dist/index.cjs +1018 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1016 -13
- package/dist/index.js.map +1 -1
- package/dist/network/request.d.ts +2 -2
- package/dist/network/request.d.ts.map +1 -1
- package/package.json +41 -33
- package/src/web/network/request.ts +8 -5
package/dist/index.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
6
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
9
|
+
var __pow = Math.pow;
|
|
7
10
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
11
|
var __spreadValues = (a, b) => {
|
|
9
12
|
for (var prop in b || (b = {}))
|
|
@@ -17,6 +20,20 @@ var __spreadValues = (a, b) => {
|
|
|
17
20
|
return a;
|
|
18
21
|
};
|
|
19
22
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
23
|
+
var __export = (target, all) => {
|
|
24
|
+
for (var name in all)
|
|
25
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
26
|
+
};
|
|
27
|
+
var __copyProps = (to, from, except, desc) => {
|
|
28
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
29
|
+
for (let key of __getOwnPropNames(from))
|
|
30
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
31
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
32
|
+
}
|
|
33
|
+
return to;
|
|
34
|
+
};
|
|
35
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
36
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
20
37
|
var __async = (__this, __arguments, generator) => {
|
|
21
38
|
return new Promise((resolve, reject) => {
|
|
22
39
|
var fulfilled = (value) => {
|
|
@@ -552,15 +569,1000 @@ function preloadImage(src) {
|
|
|
552
569
|
});
|
|
553
570
|
}
|
|
554
571
|
|
|
572
|
+
// src/ts/index.ts
|
|
573
|
+
var ts_exports = {};
|
|
574
|
+
__export(ts_exports, {
|
|
575
|
+
BigNumber: () => BigNumber,
|
|
576
|
+
EventBus: () => EventBus,
|
|
577
|
+
appendUrlParam: () => appendUrlParam,
|
|
578
|
+
arrayMove: () => arrayMove,
|
|
579
|
+
buildOSSUrl: () => buildOSSUrl,
|
|
580
|
+
createTimeRandId: () => createTimeRandId,
|
|
581
|
+
createUUID: () => createUUID,
|
|
582
|
+
createViewRandId: () => createViewRandId,
|
|
583
|
+
dayjs: () => dayjs,
|
|
584
|
+
getAgeByBirthdate: () => getAgeByBirthdate,
|
|
585
|
+
getByteLength: () => getByteLength,
|
|
586
|
+
getCountdownParts: () => getCountdownParts,
|
|
587
|
+
getDateRangeAfter: () => getDateRangeAfter,
|
|
588
|
+
getDateRangeBefore: () => getDateRangeBefore,
|
|
589
|
+
getFileSuffix: () => getFileSuffix,
|
|
590
|
+
getFileType: () => getFileType,
|
|
591
|
+
getOSSAudio: () => getOSSAudio,
|
|
592
|
+
getOSSHls: () => getOSSHls,
|
|
593
|
+
getOSSImg: () => getOSSImg,
|
|
594
|
+
getOSSVideo: () => getOSSVideo,
|
|
595
|
+
getObjectKeys: () => getObjectKeys,
|
|
596
|
+
getObjectValue: () => getObjectValue,
|
|
597
|
+
getQnAudio: () => getQnAudio,
|
|
598
|
+
getQnHls: () => getQnHls,
|
|
599
|
+
getQnImg: () => getQnImg,
|
|
600
|
+
getQnVideo: () => getQnVideo,
|
|
601
|
+
isBankCard: () => isBankCard,
|
|
602
|
+
isChinese: () => isChinese,
|
|
603
|
+
isChineseName: () => isChineseName,
|
|
604
|
+
isDigits: () => isDigits,
|
|
605
|
+
isEmail: () => isEmail,
|
|
606
|
+
isHKMOPermit: () => isHKMOPermit,
|
|
607
|
+
isHexColor: () => isHexColor,
|
|
608
|
+
isIP: () => isIP,
|
|
609
|
+
isIPRange: () => isIPRange,
|
|
610
|
+
isIPv6: () => isIPv6,
|
|
611
|
+
isIdentityCard: () => isIdentityCard,
|
|
612
|
+
isLandline: () => isLandline,
|
|
613
|
+
isLatitude: () => isLatitude,
|
|
614
|
+
isLetter: () => isLetter,
|
|
615
|
+
isLicensePlate: () => isLicensePlate,
|
|
616
|
+
isLongitude: () => isLongitude,
|
|
617
|
+
isMilitaryId: () => isMilitaryId,
|
|
618
|
+
isMobilePhone: () => isMobilePhone,
|
|
619
|
+
isNumeric: () => isNumeric,
|
|
620
|
+
isOfficerId: () => isOfficerId,
|
|
621
|
+
isPassport: () => isPassport,
|
|
622
|
+
isPhone: () => isPhone,
|
|
623
|
+
isPortNumber: () => isPortNumber,
|
|
624
|
+
isSoldierId: () => isSoldierId,
|
|
625
|
+
isTaiwanPermit: () => isTaiwanPermit,
|
|
626
|
+
isTaxID: () => isTaxID,
|
|
627
|
+
isURL: () => isURL,
|
|
628
|
+
mathCompare: () => mathCompare,
|
|
629
|
+
mathDiv: () => mathDiv,
|
|
630
|
+
mathEqual: () => mathEqual,
|
|
631
|
+
mathFixed: () => mathFixed,
|
|
632
|
+
mathGreaterThan: () => mathGreaterThan,
|
|
633
|
+
mathGreaterThanOrEqual: () => mathGreaterThanOrEqual,
|
|
634
|
+
mathLessThan: () => mathLessThan,
|
|
635
|
+
mathLessThanOrEqual: () => mathLessThanOrEqual,
|
|
636
|
+
mathMinus: () => mathMinus,
|
|
637
|
+
mathPlus: () => mathPlus,
|
|
638
|
+
mathPow: () => mathPow,
|
|
639
|
+
mathRound: () => mathRound,
|
|
640
|
+
mathTimes: () => mathTimes,
|
|
641
|
+
randomBoolean: () => randomBoolean,
|
|
642
|
+
setObjectValue: () => setObjectValue,
|
|
643
|
+
toAsync: () => toAsync,
|
|
644
|
+
toChineseCurrency: () => toChineseCurrency,
|
|
645
|
+
toChineseNum: () => toChineseNum,
|
|
646
|
+
toDayjs: () => toDayjs,
|
|
647
|
+
toMaskName: () => toMaskName,
|
|
648
|
+
toMaskPhone: () => toMaskPhone,
|
|
649
|
+
toMaskText: () => toMaskText,
|
|
650
|
+
toThousandth: () => toThousandth,
|
|
651
|
+
withDistance: () => withDistance,
|
|
652
|
+
withUnit: () => withUnit,
|
|
653
|
+
withUnitPx: () => withUnitPx,
|
|
654
|
+
zeroPad: () => zeroPad
|
|
655
|
+
});
|
|
656
|
+
|
|
657
|
+
// src/ts/array/index.ts
|
|
658
|
+
function arrayMove(list, fromIndex, toIndex) {
|
|
659
|
+
const newList = [...list];
|
|
660
|
+
const [removed] = newList.splice(fromIndex, 1);
|
|
661
|
+
newList.splice(toIndex, 0, removed);
|
|
662
|
+
return newList;
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
// src/ts/async/index.ts
|
|
666
|
+
function toAsync(p) {
|
|
667
|
+
return __async(this, null, function* () {
|
|
668
|
+
try {
|
|
669
|
+
const data = yield p;
|
|
670
|
+
return [data, null];
|
|
671
|
+
} catch (err) {
|
|
672
|
+
return [null, err];
|
|
673
|
+
}
|
|
674
|
+
});
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
// src/ts/bean/EventBus.ts
|
|
678
|
+
import mitt from "mitt";
|
|
679
|
+
var EventBus = class {
|
|
680
|
+
constructor() {
|
|
681
|
+
__publicField(this, "_emitter", mitt());
|
|
682
|
+
}
|
|
683
|
+
/** 订阅 */
|
|
684
|
+
on(type, fn) {
|
|
685
|
+
this._emitter.on(type, fn);
|
|
686
|
+
return this;
|
|
687
|
+
}
|
|
688
|
+
/** 订阅一次 */
|
|
689
|
+
once(type, fn) {
|
|
690
|
+
const wrap = (event) => {
|
|
691
|
+
this._emitter.off(type, wrap);
|
|
692
|
+
fn(event);
|
|
693
|
+
};
|
|
694
|
+
this._emitter.on(type, wrap);
|
|
695
|
+
return this;
|
|
696
|
+
}
|
|
697
|
+
/** 发布 */
|
|
698
|
+
emit(type, event) {
|
|
699
|
+
this._emitter.emit(type, event);
|
|
700
|
+
return this;
|
|
701
|
+
}
|
|
702
|
+
/** 移除 */
|
|
703
|
+
off(type, fn) {
|
|
704
|
+
this._emitter.off(type, fn);
|
|
705
|
+
return this;
|
|
706
|
+
}
|
|
707
|
+
/** 清空 */
|
|
708
|
+
clear() {
|
|
709
|
+
this._emitter.all.clear();
|
|
710
|
+
return this;
|
|
711
|
+
}
|
|
712
|
+
};
|
|
713
|
+
|
|
714
|
+
// src/ts/day/index.ts
|
|
715
|
+
import dayjs from "dayjs";
|
|
716
|
+
import customParseFormat from "dayjs/plugin/customParseFormat";
|
|
717
|
+
import utc from "dayjs/plugin/utc";
|
|
718
|
+
import timezone from "dayjs/plugin/timezone";
|
|
719
|
+
import relativeTime from "dayjs/plugin/relativeTime";
|
|
720
|
+
import advancedFormat from "dayjs/plugin/advancedFormat";
|
|
721
|
+
import "dayjs/locale/zh-cn";
|
|
722
|
+
|
|
723
|
+
// src/ts/number/big.ts
|
|
724
|
+
import BigNumber from "bignumber.js";
|
|
725
|
+
function big(x) {
|
|
726
|
+
return x instanceof BigNumber ? x : new BigNumber(x);
|
|
727
|
+
}
|
|
728
|
+
function mathPlus(...rest) {
|
|
729
|
+
let acc = big(rest[0]);
|
|
730
|
+
for (const x of rest.slice(1)) acc = acc.plus(big(x));
|
|
731
|
+
return acc.toNumber();
|
|
732
|
+
}
|
|
733
|
+
function mathMinus(...rest) {
|
|
734
|
+
let acc = big(rest[0]);
|
|
735
|
+
for (const x of rest.slice(1)) acc = acc.minus(big(x));
|
|
736
|
+
return acc.toNumber();
|
|
737
|
+
}
|
|
738
|
+
function mathTimes(...rest) {
|
|
739
|
+
let acc = big(rest[0]);
|
|
740
|
+
for (const x of rest.slice(1)) acc = acc.times(big(x));
|
|
741
|
+
return acc.toNumber();
|
|
742
|
+
}
|
|
743
|
+
function mathDiv(...rest) {
|
|
744
|
+
let acc = big(rest[0]);
|
|
745
|
+
for (const x of rest.slice(1)) acc = acc.div(big(x));
|
|
746
|
+
return acc.toNumber();
|
|
747
|
+
}
|
|
748
|
+
function mathPow(x, y) {
|
|
749
|
+
return big(x).pow(big(y)).toNumber();
|
|
750
|
+
}
|
|
751
|
+
function mathRound(x, dp = 0, rm = BigNumber.ROUND_HALF_UP) {
|
|
752
|
+
return big(x).decimalPlaces(dp, rm).toNumber();
|
|
753
|
+
}
|
|
754
|
+
function mathFixed(x, dp = 2, rm = BigNumber.ROUND_HALF_UP) {
|
|
755
|
+
return big(x).toFixed(dp, rm);
|
|
756
|
+
}
|
|
757
|
+
function mathCompare(a, b) {
|
|
758
|
+
return big(a).comparedTo(big(b));
|
|
759
|
+
}
|
|
760
|
+
function mathEqual(a, b) {
|
|
761
|
+
return big(a).isEqualTo(big(b));
|
|
762
|
+
}
|
|
763
|
+
function mathGreaterThan(a, b) {
|
|
764
|
+
return big(a).isGreaterThan(big(b));
|
|
765
|
+
}
|
|
766
|
+
function mathGreaterThanOrEqual(a, b) {
|
|
767
|
+
return big(a).isGreaterThanOrEqualTo(big(b));
|
|
768
|
+
}
|
|
769
|
+
function mathLessThan(a, b) {
|
|
770
|
+
return big(a).isLessThan(big(b));
|
|
771
|
+
}
|
|
772
|
+
function mathLessThanOrEqual(a, b) {
|
|
773
|
+
return big(a).isLessThanOrEqualTo(big(b));
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
// src/ts/number/format.ts
|
|
777
|
+
function zeroPad(n, len = 2) {
|
|
778
|
+
return String(n).padStart(len, "0");
|
|
779
|
+
}
|
|
780
|
+
function withUnit(num, unit = "") {
|
|
781
|
+
if (num === null || num === void 0 || num === "") return "";
|
|
782
|
+
if (typeof num === "number") return `${num}${unit}`;
|
|
783
|
+
const str = String(num).trim();
|
|
784
|
+
if (str === "") return "";
|
|
785
|
+
return isNaN(+str) ? str : `${str}${unit}`;
|
|
786
|
+
}
|
|
787
|
+
function withUnitPx(num) {
|
|
788
|
+
return withUnit(num, "px");
|
|
789
|
+
}
|
|
790
|
+
function withDistance(m) {
|
|
791
|
+
const n = Number(m != null ? m : 0);
|
|
792
|
+
if (!Number.isFinite(n)) return "0m";
|
|
793
|
+
return n >= 1e3 ? `${+(n / 1e3).toFixed(2)}km` : `${+n.toFixed(2)}m`;
|
|
794
|
+
}
|
|
795
|
+
function toThousandth(str) {
|
|
796
|
+
const v = String(str != null ? str : "").trim();
|
|
797
|
+
if (v === "") return "";
|
|
798
|
+
let sign = "";
|
|
799
|
+
let num = v;
|
|
800
|
+
if (num[0] === "-" || num[0] === "+") {
|
|
801
|
+
sign = num[0];
|
|
802
|
+
num = num.slice(1);
|
|
803
|
+
}
|
|
804
|
+
const [intPart, decPart] = num.split(".");
|
|
805
|
+
const groupedInt = intPart.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
806
|
+
return decPart !== void 0 && decPart !== "" ? `${sign}${groupedInt}.${decPart}` : `${sign}${groupedInt}`;
|
|
807
|
+
}
|
|
808
|
+
function toChineseNum(num) {
|
|
809
|
+
const numInt = Math.trunc(+num);
|
|
810
|
+
if (numInt === 0) return "\u96F6";
|
|
811
|
+
const digit = ["\u96F6", "\u4E00", "\u4E8C", "\u4E09", "\u56DB", "\u4E94", "\u516D", "\u4E03", "\u516B", "\u4E5D"];
|
|
812
|
+
const unit = ["", "\u5341", "\u767E", "\u5343"];
|
|
813
|
+
const bigUnit = ["", "\u4E07", "\u4EBF", "\u5146"];
|
|
814
|
+
const section4 = (n2) => {
|
|
815
|
+
let str = "", zeroFlag = false;
|
|
816
|
+
for (let i = 0; i < 4; i++) {
|
|
817
|
+
const d = n2 % 10;
|
|
818
|
+
n2 = Math.floor(n2 / 10);
|
|
819
|
+
if (d === 0) {
|
|
820
|
+
zeroFlag = true;
|
|
821
|
+
continue;
|
|
822
|
+
}
|
|
823
|
+
if (zeroFlag) str = digit[0] + str;
|
|
824
|
+
str = digit[d] + unit[i] + str;
|
|
825
|
+
zeroFlag = false;
|
|
826
|
+
}
|
|
827
|
+
return str;
|
|
828
|
+
};
|
|
829
|
+
let res = "";
|
|
830
|
+
let sectionIndex = 0;
|
|
831
|
+
let n = Math.abs(numInt);
|
|
832
|
+
while (n > 0) {
|
|
833
|
+
const seg = n % 1e4;
|
|
834
|
+
n = Math.floor(n / 1e4);
|
|
835
|
+
if (seg) {
|
|
836
|
+
const segStr = section4(seg);
|
|
837
|
+
res = segStr + (sectionIndex ? bigUnit[sectionIndex] : "") + res;
|
|
838
|
+
} else if (res && !res.startsWith("\u96F6")) {
|
|
839
|
+
res = `\u96F6${res}`;
|
|
840
|
+
}
|
|
841
|
+
sectionIndex++;
|
|
842
|
+
}
|
|
843
|
+
res = res.replace(/^一十/, "\u5341");
|
|
844
|
+
return numInt < 0 ? `\u8D1F${res}` : res;
|
|
845
|
+
}
|
|
846
|
+
function toChineseCurrency(amount, opts = {}) {
|
|
847
|
+
var _a, _b, _c;
|
|
848
|
+
const dp = (_a = opts.precision) != null ? _a : 2;
|
|
849
|
+
const rm = (_b = opts.rm) != null ? _b : BigNumber.ROUND_HALF_UP;
|
|
850
|
+
const yuan = (_c = opts.yuanChar) != null ? _c : "\u5143";
|
|
851
|
+
if (amount === null || amount === void 0) return "";
|
|
852
|
+
const bn = new BigNumber(amount);
|
|
853
|
+
if (!bn.isFinite()) return "";
|
|
854
|
+
const s = bn.toFixed(dp, rm);
|
|
855
|
+
const sign = s.startsWith("-") ? "\u8D1F" : "";
|
|
856
|
+
const [intStr, decStr = ""] = s.replace(/^-/, "").split(".");
|
|
857
|
+
const digit = ["\u96F6", "\u58F9", "\u8D30", "\u53C1", "\u8086", "\u4F0D", "\u9646", "\u67D2", "\u634C", "\u7396"];
|
|
858
|
+
const unit = ["", "\u62FE", "\u4F70", "\u4EDF"];
|
|
859
|
+
const bigUnit = ["", "\u4E07", "\u4EBF", "\u5146"];
|
|
860
|
+
const smallUnit = ["\u89D2", "\u5206", "\u5398"];
|
|
861
|
+
const section4 = (n) => {
|
|
862
|
+
let str = "";
|
|
863
|
+
let zeroFlag = false;
|
|
864
|
+
for (let i = 0; i < 4; i++) {
|
|
865
|
+
const d = n.mod(10).toNumber();
|
|
866
|
+
n = n.idiv(10);
|
|
867
|
+
if (d === 0) {
|
|
868
|
+
zeroFlag = true;
|
|
869
|
+
continue;
|
|
870
|
+
}
|
|
871
|
+
if (zeroFlag) str = digit[0] + str;
|
|
872
|
+
str = digit[d] + unit[i] + str;
|
|
873
|
+
zeroFlag = false;
|
|
874
|
+
}
|
|
875
|
+
return str.replace(/零+$/g, "");
|
|
876
|
+
};
|
|
877
|
+
const intNum = new BigNumber(intStr);
|
|
878
|
+
let res = "";
|
|
879
|
+
if (intNum.isZero()) {
|
|
880
|
+
res = digit[0];
|
|
881
|
+
} else {
|
|
882
|
+
let n = intNum.abs();
|
|
883
|
+
let sectionIndex = 0;
|
|
884
|
+
while (n.gt(0)) {
|
|
885
|
+
const seg = n.mod(1e4);
|
|
886
|
+
n = n.idiv(1e4);
|
|
887
|
+
if (seg.gt(0)) {
|
|
888
|
+
const segStr = section4(seg);
|
|
889
|
+
const needZero = res && !res.startsWith(digit[0]) && (seg.lt(1e3) || seg.mod(1e3).isZero());
|
|
890
|
+
const bu = sectionIndex ? bigUnit[sectionIndex] : "";
|
|
891
|
+
res = segStr + bu + (needZero ? digit[0] : "") + res;
|
|
892
|
+
} else if (res && !res.startsWith(digit[0])) {
|
|
893
|
+
res = digit[0] + res;
|
|
894
|
+
}
|
|
895
|
+
sectionIndex++;
|
|
896
|
+
}
|
|
897
|
+
res = res.replace(/^壹拾/, "\u62FE");
|
|
898
|
+
}
|
|
899
|
+
let frac = "";
|
|
900
|
+
for (let i = 0; i < Math.min(3, dp); i++) {
|
|
901
|
+
const ch = decStr[i] || "0";
|
|
902
|
+
const d = ch.charCodeAt(0) - 48;
|
|
903
|
+
if (d > 0) frac += digit[d] + smallUnit[i];
|
|
904
|
+
}
|
|
905
|
+
return frac ? `${sign}${res}${yuan}${frac}` : `${sign}${res}${yuan}\u6574`;
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
// src/ts/number/random.ts
|
|
909
|
+
function randomBoolean() {
|
|
910
|
+
return Math.random() < 0.5;
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
// src/ts/day/index.ts
|
|
914
|
+
dayjs.extend(customParseFormat);
|
|
915
|
+
dayjs.extend(utc);
|
|
916
|
+
dayjs.extend(timezone);
|
|
917
|
+
dayjs.extend(relativeTime);
|
|
918
|
+
dayjs.extend(advancedFormat);
|
|
919
|
+
dayjs.locale("zh-cn");
|
|
920
|
+
function toDayjs(t, fmt) {
|
|
921
|
+
if (t === null || t === void 0) return dayjs();
|
|
922
|
+
if (typeof t === "number") {
|
|
923
|
+
const s = String(Math.trunc(t));
|
|
924
|
+
return dayjs(s.length === 10 ? t * 1e3 : t, fmt);
|
|
925
|
+
}
|
|
926
|
+
if (typeof t === "string") {
|
|
927
|
+
const s = t.trim();
|
|
928
|
+
if (/^\d{10}$/.test(s)) return dayjs(Number(s) * 1e3, fmt);
|
|
929
|
+
if (/^\d{13}$/.test(s)) return dayjs(Number(s), fmt);
|
|
930
|
+
if (/^\d{4}-\d{2}-\d{2}$/.test(s)) return dayjs(s, fmt || "YYYY-MM-DD");
|
|
931
|
+
if (/^\d{4}\/\d{2}\/\d{2}$/.test(s)) return dayjs(s, fmt || "YYYY/MM/DD");
|
|
932
|
+
if (/^\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2}$/.test(s))
|
|
933
|
+
return dayjs(s, fmt || "YYYY-MM-DD HH:mm:ss");
|
|
934
|
+
if (/^\d{4}\/\d{2}\/\d{2}\s+\d{2}:\d{2}:\d{2}$/.test(s))
|
|
935
|
+
return dayjs(s, fmt || "YYYY/MM/DD HH:mm:ss");
|
|
936
|
+
return dayjs(s, fmt);
|
|
937
|
+
}
|
|
938
|
+
return dayjs(t, fmt);
|
|
939
|
+
}
|
|
940
|
+
function getDateRangeBefore(offset, fmt = "YYYY-MM-DD") {
|
|
941
|
+
const now = toDayjs(Date.now());
|
|
942
|
+
const n = Math.max(0, Math.trunc(offset));
|
|
943
|
+
const hasTime = /H|h|m|s|S|A|a|x|X/.test(fmt);
|
|
944
|
+
const startDay = now.add(-n, "day");
|
|
945
|
+
const endDay = now;
|
|
946
|
+
const start = (hasTime ? startDay.startOf("day") : startDay).format(fmt);
|
|
947
|
+
const end = (hasTime ? endDay.endOf("day") : endDay).format(fmt);
|
|
948
|
+
return [start, end];
|
|
949
|
+
}
|
|
950
|
+
function getDateRangeAfter(offset, fmt = "YYYY-MM-DD") {
|
|
951
|
+
const now = toDayjs(Date.now());
|
|
952
|
+
const n = Math.max(0, Math.trunc(offset));
|
|
953
|
+
const hasTime = /H|h|m|s|S|A|a|x|X/.test(fmt);
|
|
954
|
+
const startDay = now;
|
|
955
|
+
const endDay = now.add(n, "day");
|
|
956
|
+
const start = (hasTime ? startDay.startOf("day") : startDay).format(fmt);
|
|
957
|
+
const end = (hasTime ? endDay.endOf("day") : endDay).format(fmt);
|
|
958
|
+
return [start, end];
|
|
959
|
+
}
|
|
960
|
+
function getCountdownParts(diff) {
|
|
961
|
+
if (diff <= 0) return { d: "00", h: "00", m: "00", s: "00", ms: "000" };
|
|
962
|
+
const d = Math.floor(diff / (1e3 * 60 * 60 * 24));
|
|
963
|
+
const h = Math.floor(diff / (1e3 * 60 * 60) % 24);
|
|
964
|
+
const m = Math.floor(diff / (1e3 * 60) % 60);
|
|
965
|
+
const s = Math.floor(diff / 1e3 % 60);
|
|
966
|
+
const ms = diff % 1e3;
|
|
967
|
+
return {
|
|
968
|
+
d: zeroPad(d),
|
|
969
|
+
h: zeroPad(h),
|
|
970
|
+
m: zeroPad(m),
|
|
971
|
+
s: zeroPad(s),
|
|
972
|
+
ms: zeroPad(ms, 3)
|
|
973
|
+
};
|
|
974
|
+
}
|
|
975
|
+
function getAgeByBirthdate(birthdate) {
|
|
976
|
+
const birth = toDayjs(birthdate, "YYYY-MM-DD");
|
|
977
|
+
const now = toDayjs(Date.now());
|
|
978
|
+
const totalMonths = (now.year() - birth.year()) * 12 + (now.month() - birth.month());
|
|
979
|
+
const adjustedMonths = now.date() < birth.date() ? totalMonths - 1 : totalMonths;
|
|
980
|
+
if (adjustedMonths >= 12) {
|
|
981
|
+
let age = Math.floor(adjustedMonths / 12);
|
|
982
|
+
const birthdayThisYear = birth.add(age, "year");
|
|
983
|
+
if (now.isBefore(birthdayThisYear)) {
|
|
984
|
+
age--;
|
|
985
|
+
}
|
|
986
|
+
return { age, type: "year" };
|
|
987
|
+
}
|
|
988
|
+
return { age: adjustedMonths, type: "month" };
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
// src/ts/es-toolkit/index.ts
|
|
992
|
+
var es_toolkit_exports = {};
|
|
993
|
+
__reExport(es_toolkit_exports, es_toolkit_star);
|
|
994
|
+
import * as es_toolkit_star from "es-toolkit";
|
|
995
|
+
|
|
996
|
+
// src/ts/index.ts
|
|
997
|
+
__reExport(ts_exports, es_toolkit_exports);
|
|
998
|
+
|
|
999
|
+
// src/ts/object/index.ts
|
|
1000
|
+
import { get, set } from "es-toolkit/compat";
|
|
1001
|
+
function getObjectKeys(obj) {
|
|
1002
|
+
return Object.keys(obj);
|
|
1003
|
+
}
|
|
1004
|
+
var getObjectValue = get;
|
|
1005
|
+
var setObjectValue = set;
|
|
1006
|
+
|
|
1007
|
+
// src/ts/string/format.ts
|
|
1008
|
+
function toMaskText(s, keepLeft = 1, keepRight = 0, maskChar = "*") {
|
|
1009
|
+
if (!s) return "";
|
|
1010
|
+
const v = String(s);
|
|
1011
|
+
const l = Math.max(0, keepLeft);
|
|
1012
|
+
const r = Math.max(0, keepRight);
|
|
1013
|
+
const len = v.length;
|
|
1014
|
+
const left = Math.min(l, len);
|
|
1015
|
+
const right = Math.min(r, len - left);
|
|
1016
|
+
const mid = len - left - right;
|
|
1017
|
+
if (mid <= 0) return v;
|
|
1018
|
+
const m = maskChar && maskChar.length > 0 ? maskChar : "*";
|
|
1019
|
+
return v.slice(0, left) + m.repeat(mid) + v.slice(len - right);
|
|
1020
|
+
}
|
|
1021
|
+
function toMaskPhone(phone) {
|
|
1022
|
+
return toMaskText(phone, 3, 4);
|
|
1023
|
+
}
|
|
1024
|
+
function toMaskName(name) {
|
|
1025
|
+
if (!name) return "";
|
|
1026
|
+
const v = String(name);
|
|
1027
|
+
return v.length <= 2 ? toMaskText(v, 1, 0) : toMaskText(v, 1, 1);
|
|
1028
|
+
}
|
|
1029
|
+
|
|
1030
|
+
// src/ts/string/random.ts
|
|
1031
|
+
function createUUID() {
|
|
1032
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
|
1033
|
+
const r = Math.random() * 16 | 0, v = c === "x" ? r : r & 3 | 8;
|
|
1034
|
+
return v.toString(16);
|
|
1035
|
+
});
|
|
1036
|
+
}
|
|
1037
|
+
function createViewRandId(prefix = "id_") {
|
|
1038
|
+
return `${prefix}${Math.random().toString(36).substring(2, 16)}`;
|
|
1039
|
+
}
|
|
1040
|
+
function createTimeRandId(digits = 6) {
|
|
1041
|
+
const base = __pow(10, digits - 1);
|
|
1042
|
+
const range = 9 * base;
|
|
1043
|
+
const int = Math.floor(Math.random() * range) + base;
|
|
1044
|
+
return `${Date.now()}${int}`;
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
// src/ts/string/other.ts
|
|
1048
|
+
function getByteLength(data) {
|
|
1049
|
+
if (typeof data === "string") {
|
|
1050
|
+
let byteLen = 0;
|
|
1051
|
+
for (let i = 0; i < data.length; i++) {
|
|
1052
|
+
const code = data.charCodeAt(i);
|
|
1053
|
+
if (code <= 127) {
|
|
1054
|
+
byteLen += 1;
|
|
1055
|
+
} else if (code <= 2047) {
|
|
1056
|
+
byteLen += 2;
|
|
1057
|
+
} else if (code >= 55296 && code <= 56319) {
|
|
1058
|
+
byteLen += 4;
|
|
1059
|
+
i++;
|
|
1060
|
+
} else {
|
|
1061
|
+
byteLen += 3;
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
return byteLen;
|
|
1065
|
+
}
|
|
1066
|
+
if ("byteLength" in data) return data.byteLength;
|
|
1067
|
+
if ("size" in data) return data.size;
|
|
1068
|
+
throw new TypeError("getByteLength: Unsupported type");
|
|
1069
|
+
}
|
|
1070
|
+
|
|
1071
|
+
// src/ts/url/file/index.ts
|
|
1072
|
+
var FILE_TYPE = {
|
|
1073
|
+
img: ["png", "jpg", "jpeg", "gif", "svg", "webp"],
|
|
1074
|
+
video: ["mp4", "mov", "m4v"],
|
|
1075
|
+
voice: ["mp3", "wav", "m4a"],
|
|
1076
|
+
excel: ["csv", "xls", "xlsx", "xlsm", "ods"],
|
|
1077
|
+
word: ["txt", "doc", "docx", "pdf", "md", "wps"],
|
|
1078
|
+
zip: ["zip", "gz", "tar", "rar", "7z"],
|
|
1079
|
+
ppt: ["ppt", "pptx", "odp"],
|
|
1080
|
+
app: ["apk", "ipa"]
|
|
1081
|
+
};
|
|
1082
|
+
function getFileSuffix(fileName) {
|
|
1083
|
+
if (fileName.startsWith(".")) return "";
|
|
1084
|
+
const idx = fileName.lastIndexOf(".");
|
|
1085
|
+
return idx > 0 ? fileName.slice(idx + 1).toLowerCase() : "";
|
|
1086
|
+
}
|
|
1087
|
+
function getFileType(fileName) {
|
|
1088
|
+
const suffix = getFileSuffix(fileName);
|
|
1089
|
+
if (!suffix) return "unknown";
|
|
1090
|
+
const keys = getObjectKeys(FILE_TYPE);
|
|
1091
|
+
for (const key of keys) {
|
|
1092
|
+
if (FILE_TYPE[key].includes(suffix)) {
|
|
1093
|
+
return key;
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
return "unknown";
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1099
|
+
// src/ts/url/oss/index.ts
|
|
1100
|
+
function getOSSImg(src, option) {
|
|
1101
|
+
return buildOSSUrl(src, "image", option);
|
|
1102
|
+
}
|
|
1103
|
+
function getOSSVideo(src, option) {
|
|
1104
|
+
return buildOSSUrl(src, "video", option);
|
|
1105
|
+
}
|
|
1106
|
+
function getOSSAudio(src, option) {
|
|
1107
|
+
return buildOSSUrl(src, "audio", option);
|
|
1108
|
+
}
|
|
1109
|
+
function getOSSHls(src, option) {
|
|
1110
|
+
return buildOSSUrl(src, "hls", option);
|
|
1111
|
+
}
|
|
1112
|
+
function buildOSSUrl(src, type, option) {
|
|
1113
|
+
if (!src || !option) return src;
|
|
1114
|
+
if (src.startsWith("blob:")) return src;
|
|
1115
|
+
if (src.includes(".svg")) return src;
|
|
1116
|
+
const segs = [];
|
|
1117
|
+
for (const [k, v] of Object.entries(option)) {
|
|
1118
|
+
const seg = k === "watermark" ? getWatermark(v) : getOSSSegs(k, v);
|
|
1119
|
+
if (seg) segs.push(seg);
|
|
1120
|
+
}
|
|
1121
|
+
if (!segs.length) return src;
|
|
1122
|
+
const base = src.split("?")[0];
|
|
1123
|
+
return `${base}?x-oss-process=${type}/${segs.join("/")}`;
|
|
1124
|
+
}
|
|
1125
|
+
function getOSSSegs(type, option) {
|
|
1126
|
+
if (!option && option !== 0) return "";
|
|
1127
|
+
if (option === true) return type;
|
|
1128
|
+
if (typeof option === "number" || typeof option === "string") return `${type},${option}`;
|
|
1129
|
+
const segs = Object.entries(option).map(([k, v]) => `${k}_${v}`).join(",");
|
|
1130
|
+
return segs ? `${type},${segs}` : "";
|
|
1131
|
+
}
|
|
1132
|
+
function getWatermark(w) {
|
|
1133
|
+
if (!w) return "";
|
|
1134
|
+
if (w.image) w.image = toBase64Url(w.image);
|
|
1135
|
+
if (w.text) w.text = toBase64Url(w.text);
|
|
1136
|
+
if (w.type) w.type = toBase64Url(w.type);
|
|
1137
|
+
return getOSSSegs("watermark", w);
|
|
1138
|
+
}
|
|
1139
|
+
function toBase64Url(s) {
|
|
1140
|
+
let b64 = "";
|
|
1141
|
+
if (typeof Buffer !== "undefined") {
|
|
1142
|
+
const buf = Buffer.from(s, "utf-8");
|
|
1143
|
+
b64 = buf.toString("base64");
|
|
1144
|
+
} else {
|
|
1145
|
+
try {
|
|
1146
|
+
b64 = btoa(unescape(encodeURIComponent(s)));
|
|
1147
|
+
} catch (e) {
|
|
1148
|
+
b64 = "";
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
return b64.replace(/=+$/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
1152
|
+
}
|
|
1153
|
+
|
|
1154
|
+
// src/ts/url/param/index.ts
|
|
1155
|
+
function appendUrlParam(url, param) {
|
|
1156
|
+
if (!param || typeof param !== "object") return url;
|
|
1157
|
+
const hashIndex = url.indexOf("#");
|
|
1158
|
+
const baseWithoutHash = hashIndex >= 0 ? url.slice(0, hashIndex) : url;
|
|
1159
|
+
const hash = hashIndex >= 0 ? url.slice(hashIndex) : "";
|
|
1160
|
+
const [base, existingQs] = baseWithoutHash.split("?");
|
|
1161
|
+
const parts = [];
|
|
1162
|
+
if (existingQs) parts.push(existingQs);
|
|
1163
|
+
for (const key in param) {
|
|
1164
|
+
const rawVal = param[key];
|
|
1165
|
+
if (rawVal === null || rawVal === void 0) continue;
|
|
1166
|
+
const val = typeof rawVal === "object" ? JSON.stringify(rawVal) : String(rawVal);
|
|
1167
|
+
parts.push(`${encodeURIComponent(key)}=${encodeURIComponent(val)}`);
|
|
1168
|
+
}
|
|
1169
|
+
const qs = parts.filter(Boolean).join("&");
|
|
1170
|
+
return base + (qs ? `?${qs}` : "") + hash;
|
|
1171
|
+
}
|
|
1172
|
+
|
|
1173
|
+
// src/ts/url/qn/index.ts
|
|
1174
|
+
function getQnImg(src, option) {
|
|
1175
|
+
var _a;
|
|
1176
|
+
if (!src || !option) return src;
|
|
1177
|
+
if (src.startsWith("blob:")) return src;
|
|
1178
|
+
if (src.includes(".svg")) return src;
|
|
1179
|
+
const segs = [];
|
|
1180
|
+
if (option.imageslim) segs.push("imageslim");
|
|
1181
|
+
if (option.imageView2) segs.push(getImageView2(option.imageView2));
|
|
1182
|
+
const mogr = getImageMogr2((_a = option.imageMogr2) != null ? _a : option);
|
|
1183
|
+
if (mogr) segs.push(mogr);
|
|
1184
|
+
if (option.watermark) segs.push(getWatermark2(option.watermark));
|
|
1185
|
+
if (option.imageInfo) segs.push("imageInfo");
|
|
1186
|
+
if (!segs.length) return src;
|
|
1187
|
+
const base = src.split("?")[0];
|
|
1188
|
+
return `${base}?${segs.join("|")}`;
|
|
1189
|
+
}
|
|
1190
|
+
function getQnVideo(src, option) {
|
|
1191
|
+
if (!src || !option) return src;
|
|
1192
|
+
if (src.startsWith("blob:")) return src;
|
|
1193
|
+
if (src.includes(".svg")) return src;
|
|
1194
|
+
const segs = [];
|
|
1195
|
+
if (option.avthumb) segs.push(getAvthumb(option.avthumb));
|
|
1196
|
+
if (option.vframe) segs.push(getVframe(option.vframe));
|
|
1197
|
+
if (!segs.length) return src;
|
|
1198
|
+
const base = src.split("?")[0];
|
|
1199
|
+
return `${base}?${segs.join("|")}`;
|
|
1200
|
+
}
|
|
1201
|
+
function getQnAudio(src, option) {
|
|
1202
|
+
if (!src || !option) return src;
|
|
1203
|
+
if (src.startsWith("blob:")) return src;
|
|
1204
|
+
const segs = [];
|
|
1205
|
+
if (option.avthumb) segs.push(getAvthumb(option.avthumb));
|
|
1206
|
+
if (!segs.length) return src;
|
|
1207
|
+
const base = src.split("?")[0];
|
|
1208
|
+
return `${base}?${segs.join("|")}`;
|
|
1209
|
+
}
|
|
1210
|
+
function getQnHls(src, option) {
|
|
1211
|
+
if (!src || !option) return src;
|
|
1212
|
+
if (src.startsWith("blob:")) return src;
|
|
1213
|
+
const seg = getAvcvt(option);
|
|
1214
|
+
if (!seg) return src;
|
|
1215
|
+
const base = src.split("?")[0];
|
|
1216
|
+
return `${base}?${seg}`;
|
|
1217
|
+
}
|
|
1218
|
+
function getImageView2(opt) {
|
|
1219
|
+
if (!opt) return "";
|
|
1220
|
+
const mode = typeof opt.mode === "number" ? opt.mode : 0;
|
|
1221
|
+
const kv = [];
|
|
1222
|
+
for (const [k, v] of Object.entries(opt)) {
|
|
1223
|
+
if (k === "mode") continue;
|
|
1224
|
+
if (typeof v === "boolean") {
|
|
1225
|
+
if (v) kv.push(`${k}/1`);
|
|
1226
|
+
} else if (typeof v === "number" || typeof v === "string") {
|
|
1227
|
+
kv.push(`${k}/${v}`);
|
|
1228
|
+
}
|
|
1229
|
+
}
|
|
1230
|
+
return kv.length ? `imageView2/${mode}/${kv.join("/")}` : `imageView2/${mode}`;
|
|
1231
|
+
}
|
|
1232
|
+
function getImageMogr2(opt) {
|
|
1233
|
+
if (!opt) return "";
|
|
1234
|
+
const parts = [];
|
|
1235
|
+
const tn = opt.thumbnail;
|
|
1236
|
+
if (typeof tn !== "undefined") parts.push(`thumbnail/${tn}`);
|
|
1237
|
+
const cp = opt.crop;
|
|
1238
|
+
if (typeof cp !== "undefined") parts.push(`crop/${cp}`);
|
|
1239
|
+
const rot = opt.rotate;
|
|
1240
|
+
if (typeof rot === "number") parts.push(`rotate/${rot}`);
|
|
1241
|
+
const ao = opt["auto-orient"];
|
|
1242
|
+
if (ao) parts.push("auto-orient");
|
|
1243
|
+
const fmt = opt.format;
|
|
1244
|
+
if (typeof fmt === "string") parts.push(`format/${fmt}`);
|
|
1245
|
+
const il = opt.interlace;
|
|
1246
|
+
if (il === 0 || il === 1) parts.push(`interlace/${il}`);
|
|
1247
|
+
const bg = opt.background;
|
|
1248
|
+
if (typeof bg === "string") parts.push(`background/${bg}`);
|
|
1249
|
+
const q = opt.q;
|
|
1250
|
+
if (typeof q === "number") parts.push(`q/${q}`);
|
|
1251
|
+
const blur = opt.blur;
|
|
1252
|
+
if (typeof blur !== "undefined") {
|
|
1253
|
+
if (typeof blur === "string") parts.push(`blur/${blur}`);
|
|
1254
|
+
else parts.push(`blur/${blur.r}x${blur.s}`);
|
|
1255
|
+
}
|
|
1256
|
+
const colors = opt.colors;
|
|
1257
|
+
if (typeof colors === "number") parts.push(`colors/${colors}`);
|
|
1258
|
+
return parts.length ? `imageMogr2/${parts.join("/")}` : "";
|
|
1259
|
+
}
|
|
1260
|
+
function getWatermark2(w) {
|
|
1261
|
+
if (!w) return "";
|
|
1262
|
+
const mode = w.type === "image" ? 1 : w.type === "text" ? 2 : typeof w.type === "number" ? w.type : 2;
|
|
1263
|
+
const segs = [`watermark/${mode}`];
|
|
1264
|
+
if (mode === 1 && w.image) segs.push(`image/${toBase64Url2(w.image)}`);
|
|
1265
|
+
if (mode === 2 && w.text) segs.push(`text/${toBase64Url2(w.text)}`);
|
|
1266
|
+
if (w.font) segs.push(`font/${toBase64Url2(w.font)}`);
|
|
1267
|
+
if (typeof w.fontsize === "number") segs.push(`fontsize/${w.fontsize}`);
|
|
1268
|
+
if (w.fill) segs.push(`fill/${toBase64Url2(w.fill)}`);
|
|
1269
|
+
if (w.gravity) segs.push(`gravity/${w.gravity}`);
|
|
1270
|
+
if (typeof w.dx === "number") segs.push(`dx/${w.dx}`);
|
|
1271
|
+
if (typeof w.dy === "number") segs.push(`dy/${w.dy}`);
|
|
1272
|
+
if (typeof w.dissolve === "number") segs.push(`dissolve/${w.dissolve}`);
|
|
1273
|
+
return segs.join("/");
|
|
1274
|
+
}
|
|
1275
|
+
function toBase64Url2(s) {
|
|
1276
|
+
let b64 = "";
|
|
1277
|
+
if (typeof Buffer !== "undefined") {
|
|
1278
|
+
const buf = Buffer.from(s, "utf-8");
|
|
1279
|
+
b64 = buf.toString("base64");
|
|
1280
|
+
} else {
|
|
1281
|
+
try {
|
|
1282
|
+
b64 = btoa(unescape(encodeURIComponent(s)));
|
|
1283
|
+
} catch (e) {
|
|
1284
|
+
b64 = "";
|
|
1285
|
+
}
|
|
1286
|
+
}
|
|
1287
|
+
return b64.replace(/=+$/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
1288
|
+
}
|
|
1289
|
+
function getAvthumb(opt) {
|
|
1290
|
+
const parts = [];
|
|
1291
|
+
if (opt.format) parts.push(`avthumb/${opt.format}`);
|
|
1292
|
+
else parts.push("avthumb");
|
|
1293
|
+
if (opt.s) parts.push(`s/${opt.s}`);
|
|
1294
|
+
if (opt.vcodec) parts.push(`vcodec/${opt.vcodec}`);
|
|
1295
|
+
if (typeof opt.vb !== "undefined") parts.push(`vb/${opt.vb}`);
|
|
1296
|
+
if (typeof opt.r === "number") parts.push(`r/${opt.r}`);
|
|
1297
|
+
if (typeof opt.ab !== "undefined") parts.push(`ab/${opt.ab}`);
|
|
1298
|
+
if (typeof opt.ar === "number") parts.push(`ar/${opt.ar}`);
|
|
1299
|
+
if (opt.acodec) parts.push(`acodec/${opt.acodec}`);
|
|
1300
|
+
return parts.join("/");
|
|
1301
|
+
}
|
|
1302
|
+
function getVframe(opt) {
|
|
1303
|
+
const parts = [];
|
|
1304
|
+
parts.push(`vframe/${opt.format || "jpg"}`);
|
|
1305
|
+
if (typeof opt.offset === "number") parts.push(`offset/${opt.offset}`);
|
|
1306
|
+
if (typeof opt.w === "number") parts.push(`w/${opt.w}`);
|
|
1307
|
+
if (typeof opt.h === "number") parts.push(`h/${opt.h}`);
|
|
1308
|
+
return parts.join("/");
|
|
1309
|
+
}
|
|
1310
|
+
function getAvcvt(opt) {
|
|
1311
|
+
const parts = [];
|
|
1312
|
+
const level = typeof opt.level === "number" ? `/${opt.level}` : "/3";
|
|
1313
|
+
parts.push(`avcvt${level}`);
|
|
1314
|
+
parts.push(`format/${opt.format || "m3u8"}`);
|
|
1315
|
+
if (typeof opt.segtime === "number") parts.push(`segtime/${opt.segtime}`);
|
|
1316
|
+
if (typeof opt.t === "string") parts.push(`t/${opt.t}`);
|
|
1317
|
+
if (opt.vcodec) parts.push(`vcodec/${opt.vcodec}`);
|
|
1318
|
+
if (typeof opt.vb !== "undefined") parts.push(`vb/${opt.vb}`);
|
|
1319
|
+
if (typeof opt.r === "number") parts.push(`r/${opt.r}`);
|
|
1320
|
+
if (typeof opt.s === "string") parts.push(`s/${opt.s}`);
|
|
1321
|
+
if (opt.acodec) parts.push(`acodec/${opt.acodec}`);
|
|
1322
|
+
if (typeof opt.ab !== "undefined") parts.push(`ab/${opt.ab}`);
|
|
1323
|
+
if (typeof opt.ar === "number") parts.push(`ar/${opt.ar}`);
|
|
1324
|
+
if (typeof opt.output === "string") parts.push(`output/${toBase64Url2(opt.output)}`);
|
|
1325
|
+
return parts.join("/");
|
|
1326
|
+
}
|
|
1327
|
+
|
|
1328
|
+
// src/ts/validator/index.ts
|
|
1329
|
+
function isLetter(s) {
|
|
1330
|
+
return /^[a-zA-Z]*$/.test(s);
|
|
1331
|
+
}
|
|
1332
|
+
function isChinese(s) {
|
|
1333
|
+
const v = String(s != null ? s : "").trim();
|
|
1334
|
+
return /^[\u4E00-\u9FA5]+$/.test(v);
|
|
1335
|
+
}
|
|
1336
|
+
function isDigits(s) {
|
|
1337
|
+
return /^[0-9]+$/.test(s);
|
|
1338
|
+
}
|
|
1339
|
+
function isNumeric(value, options) {
|
|
1340
|
+
const { negative = false, decimal = 2, thousands = false, leadZero = false } = options || {};
|
|
1341
|
+
if (value === null || value === void 0 || value === "") return false;
|
|
1342
|
+
const str = String(value).trim();
|
|
1343
|
+
const sign = negative && str.startsWith("-") ? "-" : "";
|
|
1344
|
+
const body = sign ? str.slice(1) : str;
|
|
1345
|
+
const thousandsPart = thousands ? "(?:[1-9]\\d{0,2}(,\\d{3})*|0)" : "(?:\\d+)";
|
|
1346
|
+
const intPart = thousands ? thousandsPart : leadZero ? "(?:\\d+)" : "(?:0|[1-9]\\d*)";
|
|
1347
|
+
const fracPart = decimal === 0 ? "" : `(\\.\\d{1,${decimal}})`;
|
|
1348
|
+
const pattern = `^${intPart}${fracPart}$`;
|
|
1349
|
+
const reg = new RegExp(pattern);
|
|
1350
|
+
return reg.test(body);
|
|
1351
|
+
}
|
|
1352
|
+
function isMobilePhone(s) {
|
|
1353
|
+
const v = String(s != null ? s : "").trim();
|
|
1354
|
+
return /^1[3-9]\d{9}$/.test(v);
|
|
1355
|
+
}
|
|
1356
|
+
function isLandline(s) {
|
|
1357
|
+
const v = String(s != null ? s : "").trim();
|
|
1358
|
+
return /^0\d{2,3}-?\d{7,8}(?:-\d{1,6})?$/.test(v);
|
|
1359
|
+
}
|
|
1360
|
+
function isPhone(s) {
|
|
1361
|
+
return isMobilePhone(s) || isLandline(s);
|
|
1362
|
+
}
|
|
1363
|
+
function isEmail(s) {
|
|
1364
|
+
const v = String(s != null ? s : "").trim();
|
|
1365
|
+
if (v === "") return false;
|
|
1366
|
+
const emailRegex = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?(?:\.[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?)+$/;
|
|
1367
|
+
return emailRegex.test(v);
|
|
1368
|
+
}
|
|
1369
|
+
function isChineseName(s) {
|
|
1370
|
+
const v = String(s != null ? s : "").trim();
|
|
1371
|
+
return /^[\u4E00-\u9FA5·]{2,20}$/.test(v);
|
|
1372
|
+
}
|
|
1373
|
+
function isIdentityCard(code) {
|
|
1374
|
+
const v = String(code != null ? code : "").trim();
|
|
1375
|
+
if (v === "") return false;
|
|
1376
|
+
const isValidDate = (yyyymmdd) => {
|
|
1377
|
+
const y = Number(yyyymmdd.slice(0, 4));
|
|
1378
|
+
const m = Number(yyyymmdd.slice(4, 6));
|
|
1379
|
+
const d = Number(yyyymmdd.slice(6, 8));
|
|
1380
|
+
if (y < 1900 || y > 2100) return false;
|
|
1381
|
+
const date = new Date(y, m - 1, d);
|
|
1382
|
+
return date.getFullYear() === y && date.getMonth() === m - 1 && date.getDate() === d;
|
|
1383
|
+
};
|
|
1384
|
+
if (/^\d{17}[\dXx]$/.test(v)) {
|
|
1385
|
+
const birth = v.slice(6, 14);
|
|
1386
|
+
if (!isValidDate(birth)) return false;
|
|
1387
|
+
const weights = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
|
|
1388
|
+
const checkMap = ["1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"];
|
|
1389
|
+
let sum = 0;
|
|
1390
|
+
for (let i = 0; i < 17; i++) sum += Number(v[i]) * weights[i];
|
|
1391
|
+
const mod = sum % 11;
|
|
1392
|
+
const code18 = v[17].toUpperCase();
|
|
1393
|
+
return checkMap[mod] === code18;
|
|
1394
|
+
}
|
|
1395
|
+
if (/^\d{15}$/.test(v)) {
|
|
1396
|
+
const birth = v.slice(6, 12);
|
|
1397
|
+
const y = Number(`19${birth.slice(0, 2)}`);
|
|
1398
|
+
const m = Number(birth.slice(2, 4));
|
|
1399
|
+
const d = Number(birth.slice(4, 6));
|
|
1400
|
+
const date = new Date(y, m - 1, d);
|
|
1401
|
+
return date.getFullYear() === y && date.getMonth() === m - 1 && date.getDate() === d;
|
|
1402
|
+
}
|
|
1403
|
+
if (/^[A-Za-z][12]\d{8}$/.test(v)) return true;
|
|
1404
|
+
if (/^[A-Za-z]{1,2}\d{6}\(?[0-9A]\)?$/.test(v)) return true;
|
|
1405
|
+
if (/^[157]\d{6}\(?\d\)?$/.test(v)) return true;
|
|
1406
|
+
return false;
|
|
1407
|
+
}
|
|
1408
|
+
function isPassport(s) {
|
|
1409
|
+
const t = String(s != null ? s : "").replace(/[-\s]/g, "").trim();
|
|
1410
|
+
if (t === "") return false;
|
|
1411
|
+
if (/^[EG]\d{8}$/.test(t)) return true;
|
|
1412
|
+
if (/^[DPS]\d{7}$/.test(t)) return true;
|
|
1413
|
+
if (/^[A-Za-z]\d{8}$/.test(t)) return true;
|
|
1414
|
+
if (/^[A-Za-z0-9]{6,9}$/.test(t)) return true;
|
|
1415
|
+
return false;
|
|
1416
|
+
}
|
|
1417
|
+
function isHKMOPermit(s) {
|
|
1418
|
+
const t = String(s != null ? s : "").replace(/[-\s]/g, "").trim().toUpperCase();
|
|
1419
|
+
return /^[HM]\d{8,10}$/.test(t);
|
|
1420
|
+
}
|
|
1421
|
+
function isTaiwanPermit(s) {
|
|
1422
|
+
const t = String(s != null ? s : "").replace(/[-\s]/g, "").trim().toUpperCase();
|
|
1423
|
+
if (/^\d{8}$/.test(t)) return true;
|
|
1424
|
+
if (/^[A-Z]\d{8}$/.test(t)) return true;
|
|
1425
|
+
if (/^\d{10}$/.test(t)) return true;
|
|
1426
|
+
return false;
|
|
1427
|
+
}
|
|
1428
|
+
function isOfficerId(s) {
|
|
1429
|
+
const t = String(s != null ? s : "").replace(/[-\s]/g, "").trim().toUpperCase();
|
|
1430
|
+
return /^[A-Z0-9]{7,18}$/.test(t);
|
|
1431
|
+
}
|
|
1432
|
+
function isSoldierId(s) {
|
|
1433
|
+
const t = String(s != null ? s : "").replace(/[-\s]/g, "").trim().toUpperCase();
|
|
1434
|
+
return /^[A-Z0-9]{7,18}$/.test(t);
|
|
1435
|
+
}
|
|
1436
|
+
function isMilitaryId(s) {
|
|
1437
|
+
return isOfficerId(s) || isSoldierId(s);
|
|
1438
|
+
}
|
|
1439
|
+
function isBankCard(s) {
|
|
1440
|
+
const t = String(s != null ? s : "").replace(/[-\s]/g, "").trim();
|
|
1441
|
+
if (!/^\d{12,19}$/.test(t)) return false;
|
|
1442
|
+
let sum = 0;
|
|
1443
|
+
let shouldDouble = false;
|
|
1444
|
+
for (let i = t.length - 1; i >= 0; i--) {
|
|
1445
|
+
let digit = Number(t[i]);
|
|
1446
|
+
if (shouldDouble) {
|
|
1447
|
+
digit *= 2;
|
|
1448
|
+
if (digit > 9) digit -= 9;
|
|
1449
|
+
}
|
|
1450
|
+
sum += digit;
|
|
1451
|
+
shouldDouble = !shouldDouble;
|
|
1452
|
+
}
|
|
1453
|
+
return sum % 10 === 0;
|
|
1454
|
+
}
|
|
1455
|
+
function isLicensePlate(s) {
|
|
1456
|
+
const v = String(s != null ? s : "").trim().toUpperCase();
|
|
1457
|
+
const prov = "\u4EAC\u6CAA\u6D25\u6E1D\u5180\u8C6B\u4E91\u8FBD\u9ED1\u6E58\u7696\u9C81\u65B0\u82CF\u6D59\u8D63\u9102\u6842\u7518\u664B\u8499\u9655\u5409\u95FD\u8D35\u9752\u85CF\u5DDD\u5B81\u743C\u7CA4";
|
|
1458
|
+
const std = new RegExp(`^[${prov}][A-HJ-NP-Z][A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9\u6302\u5B66\u8B66\u6E2F\u6FB3]$`);
|
|
1459
|
+
const ne1 = new RegExp(`^[${prov}][A-HJ-NP-Z][DF][A-HJ-NP-Z0-9]{5}$`);
|
|
1460
|
+
const ne2 = new RegExp(`^[${prov}][A-HJ-NP-Z][A-HJ-NP-Z0-9]{5}[DF]$`);
|
|
1461
|
+
return std.test(v) || ne1.test(v) || ne2.test(v);
|
|
1462
|
+
}
|
|
1463
|
+
function isTaxID(code) {
|
|
1464
|
+
const v = String(code != null ? code : "").trim();
|
|
1465
|
+
if (!/^[0-9A-HJ-NPQRTUWXY]{18}$/.test(v)) return false;
|
|
1466
|
+
const charset = "0123456789ABCDEFGHJKLMNPQRTUWXY";
|
|
1467
|
+
const weights = [1, 3, 9, 27, 19, 26, 16, 17, 20, 29, 25, 13, 8, 24, 10, 30, 28];
|
|
1468
|
+
const map = {};
|
|
1469
|
+
for (let i = 0; i < charset.length; i++) map[charset[i]] = i;
|
|
1470
|
+
let sum = 0;
|
|
1471
|
+
for (let i = 0; i < 17; i++) {
|
|
1472
|
+
sum += map[v[i]] * weights[i];
|
|
1473
|
+
}
|
|
1474
|
+
const logicCheck = (31 - sum % 31) % 31;
|
|
1475
|
+
const expected = charset[logicCheck];
|
|
1476
|
+
return v[17] === expected;
|
|
1477
|
+
}
|
|
1478
|
+
function isHexColor(s) {
|
|
1479
|
+
const v = String(s != null ? s : "").trim();
|
|
1480
|
+
return /^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/.test(v);
|
|
1481
|
+
}
|
|
1482
|
+
function isURL(s) {
|
|
1483
|
+
const v = String(s != null ? s : "").trim();
|
|
1484
|
+
if (v === "") return false;
|
|
1485
|
+
try {
|
|
1486
|
+
const u = new URL(v);
|
|
1487
|
+
return ["http:", "https:", "ftp:"].includes(u.protocol) && !!u.hostname;
|
|
1488
|
+
} catch (e) {
|
|
1489
|
+
return false;
|
|
1490
|
+
}
|
|
1491
|
+
}
|
|
1492
|
+
function isIPv4(s) {
|
|
1493
|
+
const v = String(s != null ? s : "").trim();
|
|
1494
|
+
if (v === "") return false;
|
|
1495
|
+
const parts = v.split(".");
|
|
1496
|
+
if (parts.length !== 4) return false;
|
|
1497
|
+
for (const p of parts) {
|
|
1498
|
+
if (!/^\d+$/.test(p)) return false;
|
|
1499
|
+
if (p.length > 1 && p.startsWith("0")) return false;
|
|
1500
|
+
const n = Number(p);
|
|
1501
|
+
if (n < 0 || n > 255) return false;
|
|
1502
|
+
}
|
|
1503
|
+
return true;
|
|
1504
|
+
}
|
|
1505
|
+
function isIPv6(s) {
|
|
1506
|
+
const v = String(s != null ? s : "").trim();
|
|
1507
|
+
if (v === "") return false;
|
|
1508
|
+
const lastColon = v.lastIndexOf(":");
|
|
1509
|
+
if (lastColon !== -1 && v.includes(".")) {
|
|
1510
|
+
const ipv6Part = v.slice(0, lastColon);
|
|
1511
|
+
const ipv4Part = v.slice(lastColon + 1);
|
|
1512
|
+
return isIPv6(ipv6Part) && isIPv4(ipv4Part);
|
|
1513
|
+
}
|
|
1514
|
+
const dblColonCount = (v.match(/::/g) || []).length;
|
|
1515
|
+
if (dblColonCount > 1) return false;
|
|
1516
|
+
const segments = v.split(":");
|
|
1517
|
+
if (v.startsWith("::")) segments.shift();
|
|
1518
|
+
if (v.endsWith("::")) segments.pop();
|
|
1519
|
+
const segmentsFiltered = segments.filter((seg) => seg !== "");
|
|
1520
|
+
if (dblColonCount === 0 && segmentsFiltered.length !== 8) return false;
|
|
1521
|
+
if (dblColonCount === 1 && segmentsFiltered.length >= 1 && segmentsFiltered.length <= 7) {
|
|
1522
|
+
} else if (dblColonCount === 1 && segments.length === 0) {
|
|
1523
|
+
return true;
|
|
1524
|
+
} else if (dblColonCount === 0 && segmentsFiltered.length === 8) {
|
|
1525
|
+
} else {
|
|
1526
|
+
return false;
|
|
1527
|
+
}
|
|
1528
|
+
return segmentsFiltered.every(
|
|
1529
|
+
(seg) => seg.length >= 1 && seg.length <= 4 && /^[0-9a-fA-F]{1,4}$/.test(seg)
|
|
1530
|
+
);
|
|
1531
|
+
}
|
|
1532
|
+
function isIP(s, version) {
|
|
1533
|
+
if (version === 4 || version === "4") return isIPv4(s);
|
|
1534
|
+
if (version === 6 || version === "6") return isIPv6(s);
|
|
1535
|
+
return isIPv4(s) || isIPv6(s);
|
|
1536
|
+
}
|
|
1537
|
+
function isIPRange(s) {
|
|
1538
|
+
const v = String(s != null ? s : "").trim();
|
|
1539
|
+
if (v === "") return false;
|
|
1540
|
+
const parts = v.split("/");
|
|
1541
|
+
if (parts.length !== 2) return false;
|
|
1542
|
+
const [ip, prefixStr] = parts;
|
|
1543
|
+
if (!/^\d+$/.test(prefixStr)) return false;
|
|
1544
|
+
const prefix = Number(prefixStr);
|
|
1545
|
+
if (ip.includes(":")) {
|
|
1546
|
+
if (!isIPv6(ip)) return false;
|
|
1547
|
+
return prefix >= 0 && prefix <= 128;
|
|
1548
|
+
}
|
|
1549
|
+
if (!isIPv4(ip)) return false;
|
|
1550
|
+
return prefix >= 0 && prefix <= 32;
|
|
1551
|
+
}
|
|
1552
|
+
function isPortNumber(s) {
|
|
1553
|
+
const v = typeof s === "number" ? s : Number(String(s != null ? s : "").trim());
|
|
1554
|
+
return Number.isInteger(v) && v >= 0 && v <= 65535;
|
|
1555
|
+
}
|
|
1556
|
+
function isLatitude(s) {
|
|
1557
|
+
const v = typeof s === "number" ? s : Number(String(s != null ? s : "").trim());
|
|
1558
|
+
return Number.isFinite(v) && v >= -90 && v <= 90;
|
|
1559
|
+
}
|
|
1560
|
+
function isLongitude(s) {
|
|
1561
|
+
const v = typeof s === "number" ? s : Number(String(s != null ? s : "").trim());
|
|
1562
|
+
return Number.isFinite(v) && v >= -180 && v <= 180;
|
|
1563
|
+
}
|
|
1564
|
+
|
|
555
1565
|
// src/web/network/request.ts
|
|
556
|
-
import {
|
|
557
|
-
appendUrlParam,
|
|
558
|
-
cloneDeep,
|
|
559
|
-
getObjectValue,
|
|
560
|
-
isPlainObject,
|
|
561
|
-
pickBy,
|
|
562
|
-
toDayjs
|
|
563
|
-
} from "@base-web-kits/base-tools-ts";
|
|
564
1566
|
var requestCache = /* @__PURE__ */ new Map();
|
|
565
1567
|
function request(config) {
|
|
566
1568
|
const controller = new AbortController();
|
|
@@ -598,14 +1600,15 @@ function request(config) {
|
|
|
598
1600
|
timeout = 6e4
|
|
599
1601
|
} = config;
|
|
600
1602
|
const isGet = method === "GET";
|
|
601
|
-
const isObjectData = isPlainObject(data);
|
|
1603
|
+
const isObjectData = (0, ts_exports.isPlainObject)(data);
|
|
602
1604
|
const isArrayData = !isObjectData && Array.isArray(data);
|
|
603
|
-
const fillData = isObjectData ? pickBy(data, (val) => val !== void 0) : data;
|
|
604
|
-
const
|
|
1605
|
+
const fillData = isObjectData ? (0, ts_exports.pickBy)(data, (val) => val !== void 0) : data;
|
|
1606
|
+
const emptyValue = [void 0, null, ""];
|
|
1607
|
+
const fillHeader = header ? (0, ts_exports.pickBy)(header, (val) => !emptyValue.includes(val)) : {};
|
|
605
1608
|
const contentTypeKey = Object.keys(fillHeader).find(
|
|
606
1609
|
(k) => k.toLowerCase() === "content-type"
|
|
607
1610
|
);
|
|
608
|
-
const contentType = contentTypeKey ? fillHeader[contentTypeKey].toLowerCase() : "";
|
|
1611
|
+
const contentType = contentTypeKey ? String(fillHeader[contentTypeKey]).toLowerCase() : "";
|
|
609
1612
|
if (!isGet && fillData && (isObjectData || isArrayData) && !contentType) {
|
|
610
1613
|
fillHeader["Content-Type"] = "application/json";
|
|
611
1614
|
}
|
|
@@ -728,7 +1731,7 @@ function logRequestInfo(options) {
|
|
|
728
1731
|
duration: endTime - startTime
|
|
729
1732
|
}, extraLog);
|
|
730
1733
|
if (status === "success") {
|
|
731
|
-
info.res = cloneDeep(res);
|
|
1734
|
+
info.res = (0, ts_exports.cloneDeep)(res);
|
|
732
1735
|
log("info", info);
|
|
733
1736
|
} else {
|
|
734
1737
|
info.e = e;
|