@base-web-kits/base-tools-web 1.2.0-alpha.0 → 1.2.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/async/index.d.ts +2 -2
- package/dist/async/index.d.ts.map +1 -1
- package/dist/base-tools-web.umd.global.js +49 -49
- package/dist/base-tools-web.umd.global.js.map +1 -1
- package/dist/index.cjs +39 -974
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +223 -989
- package/dist/index.js.map +1 -1
- package/dist/network/request.d.ts +32 -27
- package/dist/network/request.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/web/async/index.ts +6 -6
- package/src/web/network/request.ts +62 -57
package/dist/index.cjs
CHANGED
|
@@ -9,7 +9,6 @@ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
|
9
9
|
var __getProtoOf = Object.getPrototypeOf;
|
|
10
10
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
11
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
12
|
-
var __pow = Math.pow;
|
|
13
12
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
14
13
|
var __spreadValues = (a, b) => {
|
|
15
14
|
for (var prop in b || (b = {}))
|
|
@@ -35,7 +34,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
35
34
|
}
|
|
36
35
|
return to;
|
|
37
36
|
};
|
|
38
|
-
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
39
37
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
40
38
|
// If the importer is in node compatibility mode or this is not an ESM
|
|
41
39
|
// file that has been converted to a CommonJS file using a Babel-
|
|
@@ -45,7 +43,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
45
43
|
mod
|
|
46
44
|
));
|
|
47
45
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
48
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
49
46
|
var __async = (__this, __arguments, generator) => {
|
|
50
47
|
return new Promise((resolve, reject) => {
|
|
51
48
|
var fulfilled = (value) => {
|
|
@@ -327,10 +324,10 @@ function execCopyFromHtml(html) {
|
|
|
327
324
|
div.innerHTML = html;
|
|
328
325
|
document.body.appendChild(div);
|
|
329
326
|
const selection = window.getSelection();
|
|
330
|
-
const
|
|
331
|
-
|
|
327
|
+
const range2 = document.createRange();
|
|
328
|
+
range2.selectNodeContents(div);
|
|
332
329
|
selection == null ? void 0 : selection.removeAllRanges();
|
|
333
|
-
selection == null ? void 0 : selection.addRange(
|
|
330
|
+
selection == null ? void 0 : selection.addRange(range2);
|
|
334
331
|
const ok = document.execCommand("copy");
|
|
335
332
|
document.body.removeChild(div);
|
|
336
333
|
selection == null ? void 0 : selection.removeAllRanges();
|
|
@@ -639,149 +636,6 @@ function preloadImage(src) {
|
|
|
639
636
|
});
|
|
640
637
|
}
|
|
641
638
|
|
|
642
|
-
// src/ts/index.ts
|
|
643
|
-
var ts_exports = {};
|
|
644
|
-
__export(ts_exports, {
|
|
645
|
-
BigNumber: () => import_bignumber.default,
|
|
646
|
-
EventBus: () => EventBus,
|
|
647
|
-
appendUrlParam: () => appendUrlParam,
|
|
648
|
-
arrayMove: () => arrayMove,
|
|
649
|
-
buildOSSUrl: () => buildOSSUrl,
|
|
650
|
-
createTimeRandId: () => createTimeRandId,
|
|
651
|
-
createUUID: () => createUUID,
|
|
652
|
-
createViewRandId: () => createViewRandId,
|
|
653
|
-
dayjs: () => import_dayjs.default,
|
|
654
|
-
getAgeByBirthdate: () => getAgeByBirthdate,
|
|
655
|
-
getByteLength: () => getByteLength,
|
|
656
|
-
getCountdownParts: () => getCountdownParts,
|
|
657
|
-
getDateRangeAfter: () => getDateRangeAfter,
|
|
658
|
-
getDateRangeBefore: () => getDateRangeBefore,
|
|
659
|
-
getFileSuffix: () => getFileSuffix,
|
|
660
|
-
getFileType: () => getFileType,
|
|
661
|
-
getOSSAudio: () => getOSSAudio,
|
|
662
|
-
getOSSHls: () => getOSSHls,
|
|
663
|
-
getOSSImg: () => getOSSImg,
|
|
664
|
-
getOSSVideo: () => getOSSVideo,
|
|
665
|
-
getObjectKeys: () => getObjectKeys,
|
|
666
|
-
getObjectValue: () => getObjectValue,
|
|
667
|
-
getQnAudio: () => getQnAudio,
|
|
668
|
-
getQnHls: () => getQnHls,
|
|
669
|
-
getQnImg: () => getQnImg,
|
|
670
|
-
getQnVideo: () => getQnVideo,
|
|
671
|
-
isBankCard: () => isBankCard,
|
|
672
|
-
isChinese: () => isChinese,
|
|
673
|
-
isChineseName: () => isChineseName,
|
|
674
|
-
isDigits: () => isDigits,
|
|
675
|
-
isEmail: () => isEmail,
|
|
676
|
-
isHKMOPermit: () => isHKMOPermit,
|
|
677
|
-
isHexColor: () => isHexColor,
|
|
678
|
-
isIP: () => isIP,
|
|
679
|
-
isIPRange: () => isIPRange,
|
|
680
|
-
isIPv6: () => isIPv6,
|
|
681
|
-
isIdentityCard: () => isIdentityCard,
|
|
682
|
-
isLandline: () => isLandline,
|
|
683
|
-
isLatitude: () => isLatitude,
|
|
684
|
-
isLetter: () => isLetter,
|
|
685
|
-
isLicensePlate: () => isLicensePlate,
|
|
686
|
-
isLongitude: () => isLongitude,
|
|
687
|
-
isMilitaryId: () => isMilitaryId,
|
|
688
|
-
isMobilePhone: () => isMobilePhone,
|
|
689
|
-
isNumeric: () => isNumeric,
|
|
690
|
-
isOfficerId: () => isOfficerId,
|
|
691
|
-
isPassport: () => isPassport,
|
|
692
|
-
isPhone: () => isPhone,
|
|
693
|
-
isPortNumber: () => isPortNumber,
|
|
694
|
-
isSoldierId: () => isSoldierId,
|
|
695
|
-
isTaiwanPermit: () => isTaiwanPermit,
|
|
696
|
-
isTaxID: () => isTaxID,
|
|
697
|
-
isURL: () => isURL,
|
|
698
|
-
mathCompare: () => mathCompare,
|
|
699
|
-
mathDiv: () => mathDiv,
|
|
700
|
-
mathEqual: () => mathEqual,
|
|
701
|
-
mathFixed: () => mathFixed,
|
|
702
|
-
mathGreaterThan: () => mathGreaterThan,
|
|
703
|
-
mathGreaterThanOrEqual: () => mathGreaterThanOrEqual,
|
|
704
|
-
mathLessThan: () => mathLessThan,
|
|
705
|
-
mathLessThanOrEqual: () => mathLessThanOrEqual,
|
|
706
|
-
mathMinus: () => mathMinus,
|
|
707
|
-
mathPlus: () => mathPlus,
|
|
708
|
-
mathPow: () => mathPow,
|
|
709
|
-
mathRound: () => mathRound,
|
|
710
|
-
mathTimes: () => mathTimes,
|
|
711
|
-
randomBoolean: () => randomBoolean,
|
|
712
|
-
setObjectValue: () => setObjectValue,
|
|
713
|
-
toAsync: () => toAsync,
|
|
714
|
-
toChineseCurrency: () => toChineseCurrency,
|
|
715
|
-
toChineseNum: () => toChineseNum,
|
|
716
|
-
toDayjs: () => toDayjs,
|
|
717
|
-
toMaskName: () => toMaskName,
|
|
718
|
-
toMaskPhone: () => toMaskPhone,
|
|
719
|
-
toMaskText: () => toMaskText,
|
|
720
|
-
toThousandth: () => toThousandth,
|
|
721
|
-
withDistance: () => withDistance,
|
|
722
|
-
withUnit: () => withUnit,
|
|
723
|
-
withUnitPx: () => withUnitPx,
|
|
724
|
-
zeroPad: () => zeroPad
|
|
725
|
-
});
|
|
726
|
-
|
|
727
|
-
// src/ts/array/index.ts
|
|
728
|
-
function arrayMove(list, fromIndex, toIndex) {
|
|
729
|
-
const newList = [...list];
|
|
730
|
-
const [removed] = newList.splice(fromIndex, 1);
|
|
731
|
-
newList.splice(toIndex, 0, removed);
|
|
732
|
-
return newList;
|
|
733
|
-
}
|
|
734
|
-
|
|
735
|
-
// src/ts/async/index.ts
|
|
736
|
-
function toAsync(p) {
|
|
737
|
-
return __async(this, null, function* () {
|
|
738
|
-
try {
|
|
739
|
-
const data = yield p;
|
|
740
|
-
return [data, null];
|
|
741
|
-
} catch (err) {
|
|
742
|
-
return [null, err];
|
|
743
|
-
}
|
|
744
|
-
});
|
|
745
|
-
}
|
|
746
|
-
|
|
747
|
-
// src/ts/bean/EventBus.ts
|
|
748
|
-
var import_mitt = __toESM(require("mitt"), 1);
|
|
749
|
-
var EventBus = class {
|
|
750
|
-
constructor() {
|
|
751
|
-
__publicField(this, "_emitter", (0, import_mitt.default)());
|
|
752
|
-
}
|
|
753
|
-
/** 订阅 */
|
|
754
|
-
on(type, fn) {
|
|
755
|
-
this._emitter.on(type, fn);
|
|
756
|
-
return this;
|
|
757
|
-
}
|
|
758
|
-
/** 订阅一次 */
|
|
759
|
-
once(type, fn) {
|
|
760
|
-
const wrap = (event) => {
|
|
761
|
-
this._emitter.off(type, wrap);
|
|
762
|
-
fn(event);
|
|
763
|
-
};
|
|
764
|
-
this._emitter.on(type, wrap);
|
|
765
|
-
return this;
|
|
766
|
-
}
|
|
767
|
-
/** 发布 */
|
|
768
|
-
emit(type, event) {
|
|
769
|
-
this._emitter.emit(type, event);
|
|
770
|
-
return this;
|
|
771
|
-
}
|
|
772
|
-
/** 移除 */
|
|
773
|
-
off(type, fn) {
|
|
774
|
-
this._emitter.off(type, fn);
|
|
775
|
-
return this;
|
|
776
|
-
}
|
|
777
|
-
/** 清空 */
|
|
778
|
-
clear() {
|
|
779
|
-
this._emitter.all.clear();
|
|
780
|
-
return this;
|
|
781
|
-
}
|
|
782
|
-
};
|
|
783
|
-
var EventBus_default = new EventBus();
|
|
784
|
-
|
|
785
639
|
// src/ts/day/index.ts
|
|
786
640
|
var import_dayjs = __toESM(require("dayjs"), 1);
|
|
787
641
|
var import_customParseFormat = __toESM(require("dayjs/plugin/customParseFormat"), 1);
|
|
@@ -790,198 +644,6 @@ var import_timezone = __toESM(require("dayjs/plugin/timezone"), 1);
|
|
|
790
644
|
var import_relativeTime = __toESM(require("dayjs/plugin/relativeTime"), 1);
|
|
791
645
|
var import_advancedFormat = __toESM(require("dayjs/plugin/advancedFormat"), 1);
|
|
792
646
|
var import_zh_cn = require("dayjs/locale/zh-cn");
|
|
793
|
-
|
|
794
|
-
// src/ts/number/big.ts
|
|
795
|
-
var import_bignumber = __toESM(require("bignumber.js"), 1);
|
|
796
|
-
function big(x) {
|
|
797
|
-
return x instanceof import_bignumber.default ? x : new import_bignumber.default(x);
|
|
798
|
-
}
|
|
799
|
-
function mathPlus(...rest) {
|
|
800
|
-
let acc = big(rest[0]);
|
|
801
|
-
for (const x of rest.slice(1)) acc = acc.plus(big(x));
|
|
802
|
-
return acc.toNumber();
|
|
803
|
-
}
|
|
804
|
-
function mathMinus(...rest) {
|
|
805
|
-
let acc = big(rest[0]);
|
|
806
|
-
for (const x of rest.slice(1)) acc = acc.minus(big(x));
|
|
807
|
-
return acc.toNumber();
|
|
808
|
-
}
|
|
809
|
-
function mathTimes(...rest) {
|
|
810
|
-
let acc = big(rest[0]);
|
|
811
|
-
for (const x of rest.slice(1)) acc = acc.times(big(x));
|
|
812
|
-
return acc.toNumber();
|
|
813
|
-
}
|
|
814
|
-
function mathDiv(...rest) {
|
|
815
|
-
let acc = big(rest[0]);
|
|
816
|
-
for (const x of rest.slice(1)) acc = acc.div(big(x));
|
|
817
|
-
return acc.toNumber();
|
|
818
|
-
}
|
|
819
|
-
function mathPow(x, y) {
|
|
820
|
-
return big(x).pow(big(y)).toNumber();
|
|
821
|
-
}
|
|
822
|
-
function mathRound(x, dp = 0, rm = import_bignumber.default.ROUND_HALF_UP) {
|
|
823
|
-
return big(x).decimalPlaces(dp, rm).toNumber();
|
|
824
|
-
}
|
|
825
|
-
function mathFixed(x, dp = 2, rm = import_bignumber.default.ROUND_HALF_UP) {
|
|
826
|
-
return big(x).toFixed(dp, rm);
|
|
827
|
-
}
|
|
828
|
-
function mathCompare(a, b) {
|
|
829
|
-
return big(a).comparedTo(big(b));
|
|
830
|
-
}
|
|
831
|
-
function mathEqual(a, b) {
|
|
832
|
-
return big(a).isEqualTo(big(b));
|
|
833
|
-
}
|
|
834
|
-
function mathGreaterThan(a, b) {
|
|
835
|
-
return big(a).isGreaterThan(big(b));
|
|
836
|
-
}
|
|
837
|
-
function mathGreaterThanOrEqual(a, b) {
|
|
838
|
-
return big(a).isGreaterThanOrEqualTo(big(b));
|
|
839
|
-
}
|
|
840
|
-
function mathLessThan(a, b) {
|
|
841
|
-
return big(a).isLessThan(big(b));
|
|
842
|
-
}
|
|
843
|
-
function mathLessThanOrEqual(a, b) {
|
|
844
|
-
return big(a).isLessThanOrEqualTo(big(b));
|
|
845
|
-
}
|
|
846
|
-
|
|
847
|
-
// src/ts/number/format.ts
|
|
848
|
-
function zeroPad(n, len = 2) {
|
|
849
|
-
return String(n).padStart(len, "0");
|
|
850
|
-
}
|
|
851
|
-
function withUnit(num, unit = "") {
|
|
852
|
-
if (num === null || num === void 0 || num === "") return "";
|
|
853
|
-
if (typeof num === "number") return `${num}${unit}`;
|
|
854
|
-
const str = String(num).trim();
|
|
855
|
-
if (str === "") return "";
|
|
856
|
-
return isNaN(+str) ? str : `${str}${unit}`;
|
|
857
|
-
}
|
|
858
|
-
function withUnitPx(num) {
|
|
859
|
-
return withUnit(num, "px");
|
|
860
|
-
}
|
|
861
|
-
function withDistance(m) {
|
|
862
|
-
const n = Number(m != null ? m : 0);
|
|
863
|
-
if (!Number.isFinite(n)) return "0m";
|
|
864
|
-
return n >= 1e3 ? `${+(n / 1e3).toFixed(2)}km` : `${+n.toFixed(2)}m`;
|
|
865
|
-
}
|
|
866
|
-
function toThousandth(str) {
|
|
867
|
-
const v = String(str != null ? str : "").trim();
|
|
868
|
-
if (v === "") return "";
|
|
869
|
-
let sign = "";
|
|
870
|
-
let num = v;
|
|
871
|
-
if (num[0] === "-" || num[0] === "+") {
|
|
872
|
-
sign = num[0];
|
|
873
|
-
num = num.slice(1);
|
|
874
|
-
}
|
|
875
|
-
const [intPart, decPart] = num.split(".");
|
|
876
|
-
const groupedInt = intPart.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
877
|
-
return decPart !== void 0 && decPart !== "" ? `${sign}${groupedInt}.${decPart}` : `${sign}${groupedInt}`;
|
|
878
|
-
}
|
|
879
|
-
function toChineseNum(num) {
|
|
880
|
-
const numInt = Math.trunc(+num);
|
|
881
|
-
if (numInt === 0) return "\u96F6";
|
|
882
|
-
const digit = ["\u96F6", "\u4E00", "\u4E8C", "\u4E09", "\u56DB", "\u4E94", "\u516D", "\u4E03", "\u516B", "\u4E5D"];
|
|
883
|
-
const unit = ["", "\u5341", "\u767E", "\u5343"];
|
|
884
|
-
const bigUnit = ["", "\u4E07", "\u4EBF", "\u5146"];
|
|
885
|
-
const section4 = (n2) => {
|
|
886
|
-
let str = "", zeroFlag = false;
|
|
887
|
-
for (let i = 0; i < 4; i++) {
|
|
888
|
-
const d = n2 % 10;
|
|
889
|
-
n2 = Math.floor(n2 / 10);
|
|
890
|
-
if (d === 0) {
|
|
891
|
-
zeroFlag = true;
|
|
892
|
-
continue;
|
|
893
|
-
}
|
|
894
|
-
if (zeroFlag) str = digit[0] + str;
|
|
895
|
-
str = digit[d] + unit[i] + str;
|
|
896
|
-
zeroFlag = false;
|
|
897
|
-
}
|
|
898
|
-
return str;
|
|
899
|
-
};
|
|
900
|
-
let res = "";
|
|
901
|
-
let sectionIndex = 0;
|
|
902
|
-
let n = Math.abs(numInt);
|
|
903
|
-
while (n > 0) {
|
|
904
|
-
const seg = n % 1e4;
|
|
905
|
-
n = Math.floor(n / 1e4);
|
|
906
|
-
if (seg) {
|
|
907
|
-
const segStr = section4(seg);
|
|
908
|
-
res = segStr + (sectionIndex ? bigUnit[sectionIndex] : "") + res;
|
|
909
|
-
} else if (res && !res.startsWith("\u96F6")) {
|
|
910
|
-
res = `\u96F6${res}`;
|
|
911
|
-
}
|
|
912
|
-
sectionIndex++;
|
|
913
|
-
}
|
|
914
|
-
res = res.replace(/^一十/, "\u5341");
|
|
915
|
-
return numInt < 0 ? `\u8D1F${res}` : res;
|
|
916
|
-
}
|
|
917
|
-
function toChineseCurrency(amount, opts = {}) {
|
|
918
|
-
var _a, _b, _c;
|
|
919
|
-
const dp = (_a = opts.precision) != null ? _a : 2;
|
|
920
|
-
const rm = (_b = opts.rm) != null ? _b : import_bignumber.default.ROUND_HALF_UP;
|
|
921
|
-
const yuan = (_c = opts.yuanChar) != null ? _c : "\u5143";
|
|
922
|
-
if (amount === null || amount === void 0) return "";
|
|
923
|
-
const bn = new import_bignumber.default(amount);
|
|
924
|
-
if (!bn.isFinite()) return "";
|
|
925
|
-
const s = bn.toFixed(dp, rm);
|
|
926
|
-
const sign = s.startsWith("-") ? "\u8D1F" : "";
|
|
927
|
-
const [intStr, decStr = ""] = s.replace(/^-/, "").split(".");
|
|
928
|
-
const digit = ["\u96F6", "\u58F9", "\u8D30", "\u53C1", "\u8086", "\u4F0D", "\u9646", "\u67D2", "\u634C", "\u7396"];
|
|
929
|
-
const unit = ["", "\u62FE", "\u4F70", "\u4EDF"];
|
|
930
|
-
const bigUnit = ["", "\u4E07", "\u4EBF", "\u5146"];
|
|
931
|
-
const smallUnit = ["\u89D2", "\u5206", "\u5398"];
|
|
932
|
-
const section4 = (n) => {
|
|
933
|
-
let str = "";
|
|
934
|
-
let zeroFlag = false;
|
|
935
|
-
for (let i = 0; i < 4; i++) {
|
|
936
|
-
const d = n.mod(10).toNumber();
|
|
937
|
-
n = n.idiv(10);
|
|
938
|
-
if (d === 0) {
|
|
939
|
-
zeroFlag = true;
|
|
940
|
-
continue;
|
|
941
|
-
}
|
|
942
|
-
if (zeroFlag) str = digit[0] + str;
|
|
943
|
-
str = digit[d] + unit[i] + str;
|
|
944
|
-
zeroFlag = false;
|
|
945
|
-
}
|
|
946
|
-
return str.replace(/零+$/g, "");
|
|
947
|
-
};
|
|
948
|
-
const intNum = new import_bignumber.default(intStr);
|
|
949
|
-
let res = "";
|
|
950
|
-
if (intNum.isZero()) {
|
|
951
|
-
res = digit[0];
|
|
952
|
-
} else {
|
|
953
|
-
let n = intNum.abs();
|
|
954
|
-
let sectionIndex = 0;
|
|
955
|
-
while (n.gt(0)) {
|
|
956
|
-
const seg = n.mod(1e4);
|
|
957
|
-
n = n.idiv(1e4);
|
|
958
|
-
if (seg.gt(0)) {
|
|
959
|
-
const segStr = section4(seg);
|
|
960
|
-
const needZero = res && !res.startsWith(digit[0]) && (seg.lt(1e3) || seg.mod(1e3).isZero());
|
|
961
|
-
const bu = sectionIndex ? bigUnit[sectionIndex] : "";
|
|
962
|
-
res = segStr + bu + (needZero ? digit[0] : "") + res;
|
|
963
|
-
} else if (res && !res.startsWith(digit[0])) {
|
|
964
|
-
res = digit[0] + res;
|
|
965
|
-
}
|
|
966
|
-
sectionIndex++;
|
|
967
|
-
}
|
|
968
|
-
res = res.replace(/^壹拾/, "\u62FE");
|
|
969
|
-
}
|
|
970
|
-
let frac = "";
|
|
971
|
-
for (let i = 0; i < Math.min(3, dp); i++) {
|
|
972
|
-
const ch = decStr[i] || "0";
|
|
973
|
-
const d = ch.charCodeAt(0) - 48;
|
|
974
|
-
if (d > 0) frac += digit[d] + smallUnit[i];
|
|
975
|
-
}
|
|
976
|
-
return frac ? `${sign}${res}${yuan}${frac}` : `${sign}${res}${yuan}\u6574`;
|
|
977
|
-
}
|
|
978
|
-
|
|
979
|
-
// src/ts/number/random.ts
|
|
980
|
-
function randomBoolean() {
|
|
981
|
-
return Math.random() < 0.5;
|
|
982
|
-
}
|
|
983
|
-
|
|
984
|
-
// src/ts/day/index.ts
|
|
985
647
|
import_dayjs.default.extend(import_customParseFormat.default);
|
|
986
648
|
import_dayjs.default.extend(import_utc.default);
|
|
987
649
|
import_dayjs.default.extend(import_timezone.default);
|
|
@@ -1008,218 +670,13 @@ function toDayjs(t, fmt) {
|
|
|
1008
670
|
}
|
|
1009
671
|
return (0, import_dayjs.default)(t, fmt);
|
|
1010
672
|
}
|
|
1011
|
-
function getDateRangeBefore(offset, fmt = "YYYY-MM-DD") {
|
|
1012
|
-
const now = toDayjs(Date.now());
|
|
1013
|
-
const n = Math.max(0, Math.trunc(offset));
|
|
1014
|
-
const hasTime = /H|h|m|s|S|A|a|x|X/.test(fmt);
|
|
1015
|
-
const startDay = now.add(-n, "day");
|
|
1016
|
-
const endDay = now;
|
|
1017
|
-
const start = (hasTime ? startDay.startOf("day") : startDay).format(fmt);
|
|
1018
|
-
const end = (hasTime ? endDay.endOf("day") : endDay).format(fmt);
|
|
1019
|
-
return [start, end];
|
|
1020
|
-
}
|
|
1021
|
-
function getDateRangeAfter(offset, fmt = "YYYY-MM-DD") {
|
|
1022
|
-
const now = toDayjs(Date.now());
|
|
1023
|
-
const n = Math.max(0, Math.trunc(offset));
|
|
1024
|
-
const hasTime = /H|h|m|s|S|A|a|x|X/.test(fmt);
|
|
1025
|
-
const startDay = now;
|
|
1026
|
-
const endDay = now.add(n, "day");
|
|
1027
|
-
const start = (hasTime ? startDay.startOf("day") : startDay).format(fmt);
|
|
1028
|
-
const end = (hasTime ? endDay.endOf("day") : endDay).format(fmt);
|
|
1029
|
-
return [start, end];
|
|
1030
|
-
}
|
|
1031
|
-
function getCountdownParts(diff) {
|
|
1032
|
-
if (diff <= 0) return { d: "00", h: "00", m: "00", s: "00", ms: "000" };
|
|
1033
|
-
const d = Math.floor(diff / (1e3 * 60 * 60 * 24));
|
|
1034
|
-
const h = Math.floor(diff / (1e3 * 60 * 60) % 24);
|
|
1035
|
-
const m = Math.floor(diff / (1e3 * 60) % 60);
|
|
1036
|
-
const s = Math.floor(diff / 1e3 % 60);
|
|
1037
|
-
const ms = diff % 1e3;
|
|
1038
|
-
return {
|
|
1039
|
-
d: zeroPad(d),
|
|
1040
|
-
h: zeroPad(h),
|
|
1041
|
-
m: zeroPad(m),
|
|
1042
|
-
s: zeroPad(s),
|
|
1043
|
-
ms: zeroPad(ms, 3)
|
|
1044
|
-
};
|
|
1045
|
-
}
|
|
1046
|
-
function getAgeByBirthdate(birthdate) {
|
|
1047
|
-
const birth = toDayjs(birthdate, "YYYY-MM-DD");
|
|
1048
|
-
const now = toDayjs(Date.now());
|
|
1049
|
-
const totalMonths = (now.year() - birth.year()) * 12 + (now.month() - birth.month());
|
|
1050
|
-
const adjustedMonths = now.date() < birth.date() ? totalMonths - 1 : totalMonths;
|
|
1051
|
-
if (adjustedMonths >= 12) {
|
|
1052
|
-
let age = Math.floor(adjustedMonths / 12);
|
|
1053
|
-
const birthdayThisYear = birth.add(age, "year");
|
|
1054
|
-
if (now.isBefore(birthdayThisYear)) {
|
|
1055
|
-
age--;
|
|
1056
|
-
}
|
|
1057
|
-
return { age, type: "year" };
|
|
1058
|
-
}
|
|
1059
|
-
return { age: adjustedMonths, type: "month" };
|
|
1060
|
-
}
|
|
1061
673
|
|
|
1062
674
|
// src/ts/es-toolkit/index.ts
|
|
1063
|
-
var
|
|
1064
|
-
__reExport(es_toolkit_exports, require("es-toolkit"));
|
|
1065
|
-
|
|
1066
|
-
// src/ts/index.ts
|
|
1067
|
-
__reExport(ts_exports, es_toolkit_exports);
|
|
675
|
+
var import_es_toolkit = require("es-toolkit");
|
|
1068
676
|
|
|
1069
677
|
// src/ts/object/index.ts
|
|
1070
678
|
var import_compat = require("es-toolkit/compat");
|
|
1071
|
-
function getObjectKeys(obj) {
|
|
1072
|
-
return Object.keys(obj);
|
|
1073
|
-
}
|
|
1074
679
|
var getObjectValue = import_compat.get;
|
|
1075
|
-
var setObjectValue = import_compat.set;
|
|
1076
|
-
|
|
1077
|
-
// src/ts/string/format.ts
|
|
1078
|
-
function toMaskText(s, keepLeft = 1, keepRight = 0, maskChar = "*") {
|
|
1079
|
-
if (!s) return "";
|
|
1080
|
-
const v = String(s);
|
|
1081
|
-
const l = Math.max(0, keepLeft);
|
|
1082
|
-
const r = Math.max(0, keepRight);
|
|
1083
|
-
const len = v.length;
|
|
1084
|
-
const left = Math.min(l, len);
|
|
1085
|
-
const right = Math.min(r, len - left);
|
|
1086
|
-
const mid = len - left - right;
|
|
1087
|
-
if (mid <= 0) return v;
|
|
1088
|
-
const m = maskChar && maskChar.length > 0 ? maskChar : "*";
|
|
1089
|
-
return v.slice(0, left) + m.repeat(mid) + v.slice(len - right);
|
|
1090
|
-
}
|
|
1091
|
-
function toMaskPhone(phone) {
|
|
1092
|
-
return toMaskText(phone, 3, 4);
|
|
1093
|
-
}
|
|
1094
|
-
function toMaskName(name) {
|
|
1095
|
-
if (!name) return "";
|
|
1096
|
-
const v = String(name);
|
|
1097
|
-
return v.length <= 2 ? toMaskText(v, 1, 0) : toMaskText(v, 1, 1);
|
|
1098
|
-
}
|
|
1099
|
-
|
|
1100
|
-
// src/ts/string/random.ts
|
|
1101
|
-
function createUUID() {
|
|
1102
|
-
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
|
1103
|
-
const r = Math.random() * 16 | 0, v = c === "x" ? r : r & 3 | 8;
|
|
1104
|
-
return v.toString(16);
|
|
1105
|
-
});
|
|
1106
|
-
}
|
|
1107
|
-
function createViewRandId(prefix = "id_") {
|
|
1108
|
-
return `${prefix}${Math.random().toString(36).substring(2, 16)}`;
|
|
1109
|
-
}
|
|
1110
|
-
function createTimeRandId(digits = 6) {
|
|
1111
|
-
const base = __pow(10, digits - 1);
|
|
1112
|
-
const range = 9 * base;
|
|
1113
|
-
const int = Math.floor(Math.random() * range) + base;
|
|
1114
|
-
return `${Date.now()}${int}`;
|
|
1115
|
-
}
|
|
1116
|
-
|
|
1117
|
-
// src/ts/string/other.ts
|
|
1118
|
-
function getByteLength(data) {
|
|
1119
|
-
if (typeof data === "string") {
|
|
1120
|
-
let byteLen = 0;
|
|
1121
|
-
for (let i = 0; i < data.length; i++) {
|
|
1122
|
-
const code = data.charCodeAt(i);
|
|
1123
|
-
if (code <= 127) {
|
|
1124
|
-
byteLen += 1;
|
|
1125
|
-
} else if (code <= 2047) {
|
|
1126
|
-
byteLen += 2;
|
|
1127
|
-
} else if (code >= 55296 && code <= 56319) {
|
|
1128
|
-
byteLen += 4;
|
|
1129
|
-
i++;
|
|
1130
|
-
} else {
|
|
1131
|
-
byteLen += 3;
|
|
1132
|
-
}
|
|
1133
|
-
}
|
|
1134
|
-
return byteLen;
|
|
1135
|
-
}
|
|
1136
|
-
if ("byteLength" in data) return data.byteLength;
|
|
1137
|
-
if ("size" in data) return data.size;
|
|
1138
|
-
throw new TypeError("getByteLength: Unsupported type");
|
|
1139
|
-
}
|
|
1140
|
-
|
|
1141
|
-
// src/ts/url/file/index.ts
|
|
1142
|
-
var FILE_TYPE = {
|
|
1143
|
-
img: ["png", "jpg", "jpeg", "gif", "svg", "webp"],
|
|
1144
|
-
video: ["mp4", "mov", "m4v"],
|
|
1145
|
-
voice: ["mp3", "wav", "m4a"],
|
|
1146
|
-
excel: ["csv", "xls", "xlsx", "xlsm", "ods"],
|
|
1147
|
-
word: ["txt", "doc", "docx", "pdf", "md", "wps"],
|
|
1148
|
-
zip: ["zip", "gz", "tar", "rar", "7z"],
|
|
1149
|
-
ppt: ["ppt", "pptx", "odp"],
|
|
1150
|
-
app: ["apk", "ipa"]
|
|
1151
|
-
};
|
|
1152
|
-
function getFileSuffix(fileName) {
|
|
1153
|
-
if (fileName.startsWith(".")) return "";
|
|
1154
|
-
const idx = fileName.lastIndexOf(".");
|
|
1155
|
-
return idx > 0 ? fileName.slice(idx + 1).toLowerCase() : "";
|
|
1156
|
-
}
|
|
1157
|
-
function getFileType(fileName) {
|
|
1158
|
-
const suffix = getFileSuffix(fileName);
|
|
1159
|
-
if (!suffix) return "unknown";
|
|
1160
|
-
const keys = getObjectKeys(FILE_TYPE);
|
|
1161
|
-
for (const key of keys) {
|
|
1162
|
-
if (FILE_TYPE[key].includes(suffix)) {
|
|
1163
|
-
return key;
|
|
1164
|
-
}
|
|
1165
|
-
}
|
|
1166
|
-
return "unknown";
|
|
1167
|
-
}
|
|
1168
|
-
|
|
1169
|
-
// src/ts/url/oss/index.ts
|
|
1170
|
-
function getOSSImg(src, option) {
|
|
1171
|
-
return buildOSSUrl(src, "image", option);
|
|
1172
|
-
}
|
|
1173
|
-
function getOSSVideo(src, option) {
|
|
1174
|
-
return buildOSSUrl(src, "video", option);
|
|
1175
|
-
}
|
|
1176
|
-
function getOSSAudio(src, option) {
|
|
1177
|
-
return buildOSSUrl(src, "audio", option);
|
|
1178
|
-
}
|
|
1179
|
-
function getOSSHls(src, option) {
|
|
1180
|
-
return buildOSSUrl(src, "hls", option);
|
|
1181
|
-
}
|
|
1182
|
-
function buildOSSUrl(src, type, option) {
|
|
1183
|
-
if (!src || !option) return src;
|
|
1184
|
-
if (src.startsWith("blob:")) return src;
|
|
1185
|
-
if (src.includes(".svg")) return src;
|
|
1186
|
-
const segs = [];
|
|
1187
|
-
for (const [k, v] of Object.entries(option)) {
|
|
1188
|
-
const seg = k === "watermark" ? getWatermark(v) : getOSSSegs(k, v);
|
|
1189
|
-
if (seg) segs.push(seg);
|
|
1190
|
-
}
|
|
1191
|
-
if (!segs.length) return src;
|
|
1192
|
-
const base = src.split("?")[0];
|
|
1193
|
-
return `${base}?x-oss-process=${type}/${segs.join("/")}`;
|
|
1194
|
-
}
|
|
1195
|
-
function getOSSSegs(type, option) {
|
|
1196
|
-
if (!option && option !== 0) return "";
|
|
1197
|
-
if (option === true) return type;
|
|
1198
|
-
if (typeof option === "number" || typeof option === "string") return `${type},${option}`;
|
|
1199
|
-
const segs = Object.entries(option).map(([k, v]) => `${k}_${v}`).join(",");
|
|
1200
|
-
return segs ? `${type},${segs}` : "";
|
|
1201
|
-
}
|
|
1202
|
-
function getWatermark(w) {
|
|
1203
|
-
if (!w) return "";
|
|
1204
|
-
if (w.image) w.image = toBase64Url(w.image);
|
|
1205
|
-
if (w.text) w.text = toBase64Url(w.text);
|
|
1206
|
-
if (w.type) w.type = toBase64Url(w.type);
|
|
1207
|
-
return getOSSSegs("watermark", w);
|
|
1208
|
-
}
|
|
1209
|
-
function toBase64Url(s) {
|
|
1210
|
-
let b64 = "";
|
|
1211
|
-
if (typeof Buffer !== "undefined") {
|
|
1212
|
-
const buf = Buffer.from(s, "utf-8");
|
|
1213
|
-
b64 = buf.toString("base64");
|
|
1214
|
-
} else {
|
|
1215
|
-
try {
|
|
1216
|
-
b64 = btoa(unescape(encodeURIComponent(s)));
|
|
1217
|
-
} catch (e) {
|
|
1218
|
-
b64 = "";
|
|
1219
|
-
}
|
|
1220
|
-
}
|
|
1221
|
-
return b64.replace(/=+$/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
1222
|
-
}
|
|
1223
680
|
|
|
1224
681
|
// src/ts/url/param/index.ts
|
|
1225
682
|
function appendUrlParam(url, param) {
|
|
@@ -1240,401 +697,29 @@ function appendUrlParam(url, param) {
|
|
|
1240
697
|
return base + (qs ? `?${qs}` : "") + hash;
|
|
1241
698
|
}
|
|
1242
699
|
|
|
1243
|
-
// src/ts/url/qn/index.ts
|
|
1244
|
-
function getQnImg(src, option) {
|
|
1245
|
-
var _a;
|
|
1246
|
-
if (!src || !option) return src;
|
|
1247
|
-
if (src.startsWith("blob:")) return src;
|
|
1248
|
-
if (src.includes(".svg")) return src;
|
|
1249
|
-
const segs = [];
|
|
1250
|
-
if (option.imageslim) segs.push("imageslim");
|
|
1251
|
-
if (option.imageView2) segs.push(getImageView2(option.imageView2));
|
|
1252
|
-
const mogr = getImageMogr2((_a = option.imageMogr2) != null ? _a : option);
|
|
1253
|
-
if (mogr) segs.push(mogr);
|
|
1254
|
-
if (option.watermark) segs.push(getWatermark2(option.watermark));
|
|
1255
|
-
if (option.imageInfo) segs.push("imageInfo");
|
|
1256
|
-
if (!segs.length) return src;
|
|
1257
|
-
const base = src.split("?")[0];
|
|
1258
|
-
return `${base}?${segs.join("|")}`;
|
|
1259
|
-
}
|
|
1260
|
-
function getQnVideo(src, option) {
|
|
1261
|
-
if (!src || !option) return src;
|
|
1262
|
-
if (src.startsWith("blob:")) return src;
|
|
1263
|
-
if (src.includes(".svg")) return src;
|
|
1264
|
-
const segs = [];
|
|
1265
|
-
if (option.avthumb) segs.push(getAvthumb(option.avthumb));
|
|
1266
|
-
if (option.vframe) segs.push(getVframe(option.vframe));
|
|
1267
|
-
if (!segs.length) return src;
|
|
1268
|
-
const base = src.split("?")[0];
|
|
1269
|
-
return `${base}?${segs.join("|")}`;
|
|
1270
|
-
}
|
|
1271
|
-
function getQnAudio(src, option) {
|
|
1272
|
-
if (!src || !option) return src;
|
|
1273
|
-
if (src.startsWith("blob:")) return src;
|
|
1274
|
-
const segs = [];
|
|
1275
|
-
if (option.avthumb) segs.push(getAvthumb(option.avthumb));
|
|
1276
|
-
if (!segs.length) return src;
|
|
1277
|
-
const base = src.split("?")[0];
|
|
1278
|
-
return `${base}?${segs.join("|")}`;
|
|
1279
|
-
}
|
|
1280
|
-
function getQnHls(src, option) {
|
|
1281
|
-
if (!src || !option) return src;
|
|
1282
|
-
if (src.startsWith("blob:")) return src;
|
|
1283
|
-
const seg = getAvcvt(option);
|
|
1284
|
-
if (!seg) return src;
|
|
1285
|
-
const base = src.split("?")[0];
|
|
1286
|
-
return `${base}?${seg}`;
|
|
1287
|
-
}
|
|
1288
|
-
function getImageView2(opt) {
|
|
1289
|
-
if (!opt) return "";
|
|
1290
|
-
const mode = typeof opt.mode === "number" ? opt.mode : 0;
|
|
1291
|
-
const kv = [];
|
|
1292
|
-
for (const [k, v] of Object.entries(opt)) {
|
|
1293
|
-
if (k === "mode") continue;
|
|
1294
|
-
if (typeof v === "boolean") {
|
|
1295
|
-
if (v) kv.push(`${k}/1`);
|
|
1296
|
-
} else if (typeof v === "number" || typeof v === "string") {
|
|
1297
|
-
kv.push(`${k}/${v}`);
|
|
1298
|
-
}
|
|
1299
|
-
}
|
|
1300
|
-
return kv.length ? `imageView2/${mode}/${kv.join("/")}` : `imageView2/${mode}`;
|
|
1301
|
-
}
|
|
1302
|
-
function getImageMogr2(opt) {
|
|
1303
|
-
if (!opt) return "";
|
|
1304
|
-
const parts = [];
|
|
1305
|
-
const tn = opt.thumbnail;
|
|
1306
|
-
if (typeof tn !== "undefined") parts.push(`thumbnail/${tn}`);
|
|
1307
|
-
const cp = opt.crop;
|
|
1308
|
-
if (typeof cp !== "undefined") parts.push(`crop/${cp}`);
|
|
1309
|
-
const rot = opt.rotate;
|
|
1310
|
-
if (typeof rot === "number") parts.push(`rotate/${rot}`);
|
|
1311
|
-
const ao = opt["auto-orient"];
|
|
1312
|
-
if (ao) parts.push("auto-orient");
|
|
1313
|
-
const fmt = opt.format;
|
|
1314
|
-
if (typeof fmt === "string") parts.push(`format/${fmt}`);
|
|
1315
|
-
const il = opt.interlace;
|
|
1316
|
-
if (il === 0 || il === 1) parts.push(`interlace/${il}`);
|
|
1317
|
-
const bg = opt.background;
|
|
1318
|
-
if (typeof bg === "string") parts.push(`background/${bg}`);
|
|
1319
|
-
const q = opt.q;
|
|
1320
|
-
if (typeof q === "number") parts.push(`q/${q}`);
|
|
1321
|
-
const blur = opt.blur;
|
|
1322
|
-
if (typeof blur !== "undefined") {
|
|
1323
|
-
if (typeof blur === "string") parts.push(`blur/${blur}`);
|
|
1324
|
-
else parts.push(`blur/${blur.r}x${blur.s}`);
|
|
1325
|
-
}
|
|
1326
|
-
const colors = opt.colors;
|
|
1327
|
-
if (typeof colors === "number") parts.push(`colors/${colors}`);
|
|
1328
|
-
return parts.length ? `imageMogr2/${parts.join("/")}` : "";
|
|
1329
|
-
}
|
|
1330
|
-
function getWatermark2(w) {
|
|
1331
|
-
if (!w) return "";
|
|
1332
|
-
const mode = w.type === "image" ? 1 : w.type === "text" ? 2 : typeof w.type === "number" ? w.type : 2;
|
|
1333
|
-
const segs = [`watermark/${mode}`];
|
|
1334
|
-
if (mode === 1 && w.image) segs.push(`image/${toBase64Url2(w.image)}`);
|
|
1335
|
-
if (mode === 2 && w.text) segs.push(`text/${toBase64Url2(w.text)}`);
|
|
1336
|
-
if (w.font) segs.push(`font/${toBase64Url2(w.font)}`);
|
|
1337
|
-
if (typeof w.fontsize === "number") segs.push(`fontsize/${w.fontsize}`);
|
|
1338
|
-
if (w.fill) segs.push(`fill/${toBase64Url2(w.fill)}`);
|
|
1339
|
-
if (w.gravity) segs.push(`gravity/${w.gravity}`);
|
|
1340
|
-
if (typeof w.dx === "number") segs.push(`dx/${w.dx}`);
|
|
1341
|
-
if (typeof w.dy === "number") segs.push(`dy/${w.dy}`);
|
|
1342
|
-
if (typeof w.dissolve === "number") segs.push(`dissolve/${w.dissolve}`);
|
|
1343
|
-
return segs.join("/");
|
|
1344
|
-
}
|
|
1345
|
-
function toBase64Url2(s) {
|
|
1346
|
-
let b64 = "";
|
|
1347
|
-
if (typeof Buffer !== "undefined") {
|
|
1348
|
-
const buf = Buffer.from(s, "utf-8");
|
|
1349
|
-
b64 = buf.toString("base64");
|
|
1350
|
-
} else {
|
|
1351
|
-
try {
|
|
1352
|
-
b64 = btoa(unescape(encodeURIComponent(s)));
|
|
1353
|
-
} catch (e) {
|
|
1354
|
-
b64 = "";
|
|
1355
|
-
}
|
|
1356
|
-
}
|
|
1357
|
-
return b64.replace(/=+$/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
1358
|
-
}
|
|
1359
|
-
function getAvthumb(opt) {
|
|
1360
|
-
const parts = [];
|
|
1361
|
-
if (opt.format) parts.push(`avthumb/${opt.format}`);
|
|
1362
|
-
else parts.push("avthumb");
|
|
1363
|
-
if (opt.s) parts.push(`s/${opt.s}`);
|
|
1364
|
-
if (opt.vcodec) parts.push(`vcodec/${opt.vcodec}`);
|
|
1365
|
-
if (typeof opt.vb !== "undefined") parts.push(`vb/${opt.vb}`);
|
|
1366
|
-
if (typeof opt.r === "number") parts.push(`r/${opt.r}`);
|
|
1367
|
-
if (typeof opt.ab !== "undefined") parts.push(`ab/${opt.ab}`);
|
|
1368
|
-
if (typeof opt.ar === "number") parts.push(`ar/${opt.ar}`);
|
|
1369
|
-
if (opt.acodec) parts.push(`acodec/${opt.acodec}`);
|
|
1370
|
-
return parts.join("/");
|
|
1371
|
-
}
|
|
1372
|
-
function getVframe(opt) {
|
|
1373
|
-
const parts = [];
|
|
1374
|
-
parts.push(`vframe/${opt.format || "jpg"}`);
|
|
1375
|
-
if (typeof opt.offset === "number") parts.push(`offset/${opt.offset}`);
|
|
1376
|
-
if (typeof opt.w === "number") parts.push(`w/${opt.w}`);
|
|
1377
|
-
if (typeof opt.h === "number") parts.push(`h/${opt.h}`);
|
|
1378
|
-
return parts.join("/");
|
|
1379
|
-
}
|
|
1380
|
-
function getAvcvt(opt) {
|
|
1381
|
-
const parts = [];
|
|
1382
|
-
const level = typeof opt.level === "number" ? `/${opt.level}` : "/3";
|
|
1383
|
-
parts.push(`avcvt${level}`);
|
|
1384
|
-
parts.push(`format/${opt.format || "m3u8"}`);
|
|
1385
|
-
if (typeof opt.segtime === "number") parts.push(`segtime/${opt.segtime}`);
|
|
1386
|
-
if (typeof opt.t === "string") parts.push(`t/${opt.t}`);
|
|
1387
|
-
if (opt.vcodec) parts.push(`vcodec/${opt.vcodec}`);
|
|
1388
|
-
if (typeof opt.vb !== "undefined") parts.push(`vb/${opt.vb}`);
|
|
1389
|
-
if (typeof opt.r === "number") parts.push(`r/${opt.r}`);
|
|
1390
|
-
if (typeof opt.s === "string") parts.push(`s/${opt.s}`);
|
|
1391
|
-
if (opt.acodec) parts.push(`acodec/${opt.acodec}`);
|
|
1392
|
-
if (typeof opt.ab !== "undefined") parts.push(`ab/${opt.ab}`);
|
|
1393
|
-
if (typeof opt.ar === "number") parts.push(`ar/${opt.ar}`);
|
|
1394
|
-
if (typeof opt.output === "string") parts.push(`output/${toBase64Url2(opt.output)}`);
|
|
1395
|
-
return parts.join("/");
|
|
1396
|
-
}
|
|
1397
|
-
|
|
1398
|
-
// src/ts/validator/index.ts
|
|
1399
|
-
function isLetter(s) {
|
|
1400
|
-
return /^[a-zA-Z]*$/.test(s);
|
|
1401
|
-
}
|
|
1402
|
-
function isChinese(s) {
|
|
1403
|
-
const v = String(s != null ? s : "").trim();
|
|
1404
|
-
return /^[\u4E00-\u9FA5]+$/.test(v);
|
|
1405
|
-
}
|
|
1406
|
-
function isDigits(s) {
|
|
1407
|
-
return /^[0-9]+$/.test(s);
|
|
1408
|
-
}
|
|
1409
|
-
function isNumeric(value, options) {
|
|
1410
|
-
const { negative = false, decimal = 2, thousands = false, leadZero = false } = options || {};
|
|
1411
|
-
if (value === null || value === void 0 || value === "") return false;
|
|
1412
|
-
const str = String(value).trim();
|
|
1413
|
-
const sign = negative && str.startsWith("-") ? "-" : "";
|
|
1414
|
-
const body = sign ? str.slice(1) : str;
|
|
1415
|
-
const thousandsPart = thousands ? "(?:[1-9]\\d{0,2}(,\\d{3})*|0)" : "(?:\\d+)";
|
|
1416
|
-
const intPart = thousands ? thousandsPart : leadZero ? "(?:\\d+)" : "(?:0|[1-9]\\d*)";
|
|
1417
|
-
const fracPart = decimal === 0 ? "" : `(\\.\\d{1,${decimal}})`;
|
|
1418
|
-
const pattern = `^${intPart}${fracPart}$`;
|
|
1419
|
-
const reg = new RegExp(pattern);
|
|
1420
|
-
return reg.test(body);
|
|
1421
|
-
}
|
|
1422
|
-
function isMobilePhone(s) {
|
|
1423
|
-
const v = String(s != null ? s : "").trim();
|
|
1424
|
-
return /^1[3-9]\d{9}$/.test(v);
|
|
1425
|
-
}
|
|
1426
|
-
function isLandline(s) {
|
|
1427
|
-
const v = String(s != null ? s : "").trim();
|
|
1428
|
-
return /^0\d{2,3}-?\d{7,8}(?:-\d{1,6})?$/.test(v);
|
|
1429
|
-
}
|
|
1430
|
-
function isPhone(s) {
|
|
1431
|
-
return isMobilePhone(s) || isLandline(s);
|
|
1432
|
-
}
|
|
1433
|
-
function isEmail(s) {
|
|
1434
|
-
const v = String(s != null ? s : "").trim();
|
|
1435
|
-
if (v === "") return false;
|
|
1436
|
-
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])?)+$/;
|
|
1437
|
-
return emailRegex.test(v);
|
|
1438
|
-
}
|
|
1439
|
-
function isChineseName(s) {
|
|
1440
|
-
const v = String(s != null ? s : "").trim();
|
|
1441
|
-
return /^[\u4E00-\u9FA5·]{2,20}$/.test(v);
|
|
1442
|
-
}
|
|
1443
|
-
function isIdentityCard(code) {
|
|
1444
|
-
const v = String(code != null ? code : "").trim();
|
|
1445
|
-
if (v === "") return false;
|
|
1446
|
-
const isValidDate = (yyyymmdd) => {
|
|
1447
|
-
const y = Number(yyyymmdd.slice(0, 4));
|
|
1448
|
-
const m = Number(yyyymmdd.slice(4, 6));
|
|
1449
|
-
const d = Number(yyyymmdd.slice(6, 8));
|
|
1450
|
-
if (y < 1900 || y > 2100) return false;
|
|
1451
|
-
const date = new Date(y, m - 1, d);
|
|
1452
|
-
return date.getFullYear() === y && date.getMonth() === m - 1 && date.getDate() === d;
|
|
1453
|
-
};
|
|
1454
|
-
if (/^\d{17}[\dXx]$/.test(v)) {
|
|
1455
|
-
const birth = v.slice(6, 14);
|
|
1456
|
-
if (!isValidDate(birth)) return false;
|
|
1457
|
-
const weights = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
|
|
1458
|
-
const checkMap = ["1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"];
|
|
1459
|
-
let sum = 0;
|
|
1460
|
-
for (let i = 0; i < 17; i++) sum += Number(v[i]) * weights[i];
|
|
1461
|
-
const mod = sum % 11;
|
|
1462
|
-
const code18 = v[17].toUpperCase();
|
|
1463
|
-
return checkMap[mod] === code18;
|
|
1464
|
-
}
|
|
1465
|
-
if (/^\d{15}$/.test(v)) {
|
|
1466
|
-
const birth = v.slice(6, 12);
|
|
1467
|
-
const y = Number(`19${birth.slice(0, 2)}`);
|
|
1468
|
-
const m = Number(birth.slice(2, 4));
|
|
1469
|
-
const d = Number(birth.slice(4, 6));
|
|
1470
|
-
const date = new Date(y, m - 1, d);
|
|
1471
|
-
return date.getFullYear() === y && date.getMonth() === m - 1 && date.getDate() === d;
|
|
1472
|
-
}
|
|
1473
|
-
if (/^[A-Za-z][12]\d{8}$/.test(v)) return true;
|
|
1474
|
-
if (/^[A-Za-z]{1,2}\d{6}\(?[0-9A]\)?$/.test(v)) return true;
|
|
1475
|
-
if (/^[157]\d{6}\(?\d\)?$/.test(v)) return true;
|
|
1476
|
-
return false;
|
|
1477
|
-
}
|
|
1478
|
-
function isPassport(s) {
|
|
1479
|
-
const t = String(s != null ? s : "").replace(/[-\s]/g, "").trim();
|
|
1480
|
-
if (t === "") return false;
|
|
1481
|
-
if (/^[EG]\d{8}$/.test(t)) return true;
|
|
1482
|
-
if (/^[DPS]\d{7}$/.test(t)) return true;
|
|
1483
|
-
if (/^[A-Za-z]\d{8}$/.test(t)) return true;
|
|
1484
|
-
if (/^[A-Za-z0-9]{6,9}$/.test(t)) return true;
|
|
1485
|
-
return false;
|
|
1486
|
-
}
|
|
1487
|
-
function isHKMOPermit(s) {
|
|
1488
|
-
const t = String(s != null ? s : "").replace(/[-\s]/g, "").trim().toUpperCase();
|
|
1489
|
-
return /^[HM]\d{8,10}$/.test(t);
|
|
1490
|
-
}
|
|
1491
|
-
function isTaiwanPermit(s) {
|
|
1492
|
-
const t = String(s != null ? s : "").replace(/[-\s]/g, "").trim().toUpperCase();
|
|
1493
|
-
if (/^\d{8}$/.test(t)) return true;
|
|
1494
|
-
if (/^[A-Z]\d{8}$/.test(t)) return true;
|
|
1495
|
-
if (/^\d{10}$/.test(t)) return true;
|
|
1496
|
-
return false;
|
|
1497
|
-
}
|
|
1498
|
-
function isOfficerId(s) {
|
|
1499
|
-
const t = String(s != null ? s : "").replace(/[-\s]/g, "").trim().toUpperCase();
|
|
1500
|
-
return /^[A-Z0-9]{7,18}$/.test(t);
|
|
1501
|
-
}
|
|
1502
|
-
function isSoldierId(s) {
|
|
1503
|
-
const t = String(s != null ? s : "").replace(/[-\s]/g, "").trim().toUpperCase();
|
|
1504
|
-
return /^[A-Z0-9]{7,18}$/.test(t);
|
|
1505
|
-
}
|
|
1506
|
-
function isMilitaryId(s) {
|
|
1507
|
-
return isOfficerId(s) || isSoldierId(s);
|
|
1508
|
-
}
|
|
1509
|
-
function isBankCard(s) {
|
|
1510
|
-
const t = String(s != null ? s : "").replace(/[-\s]/g, "").trim();
|
|
1511
|
-
if (!/^\d{12,19}$/.test(t)) return false;
|
|
1512
|
-
let sum = 0;
|
|
1513
|
-
let shouldDouble = false;
|
|
1514
|
-
for (let i = t.length - 1; i >= 0; i--) {
|
|
1515
|
-
let digit = Number(t[i]);
|
|
1516
|
-
if (shouldDouble) {
|
|
1517
|
-
digit *= 2;
|
|
1518
|
-
if (digit > 9) digit -= 9;
|
|
1519
|
-
}
|
|
1520
|
-
sum += digit;
|
|
1521
|
-
shouldDouble = !shouldDouble;
|
|
1522
|
-
}
|
|
1523
|
-
return sum % 10 === 0;
|
|
1524
|
-
}
|
|
1525
|
-
function isLicensePlate(s) {
|
|
1526
|
-
const v = String(s != null ? s : "").trim().toUpperCase();
|
|
1527
|
-
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";
|
|
1528
|
-
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]$`);
|
|
1529
|
-
const ne1 = new RegExp(`^[${prov}][A-HJ-NP-Z][DF][A-HJ-NP-Z0-9]{5}$`);
|
|
1530
|
-
const ne2 = new RegExp(`^[${prov}][A-HJ-NP-Z][A-HJ-NP-Z0-9]{5}[DF]$`);
|
|
1531
|
-
return std.test(v) || ne1.test(v) || ne2.test(v);
|
|
1532
|
-
}
|
|
1533
|
-
function isTaxID(code) {
|
|
1534
|
-
const v = String(code != null ? code : "").trim();
|
|
1535
|
-
if (!/^[0-9A-HJ-NPQRTUWXY]{18}$/.test(v)) return false;
|
|
1536
|
-
const charset = "0123456789ABCDEFGHJKLMNPQRTUWXY";
|
|
1537
|
-
const weights = [1, 3, 9, 27, 19, 26, 16, 17, 20, 29, 25, 13, 8, 24, 10, 30, 28];
|
|
1538
|
-
const map = {};
|
|
1539
|
-
for (let i = 0; i < charset.length; i++) map[charset[i]] = i;
|
|
1540
|
-
let sum = 0;
|
|
1541
|
-
for (let i = 0; i < 17; i++) {
|
|
1542
|
-
sum += map[v[i]] * weights[i];
|
|
1543
|
-
}
|
|
1544
|
-
const logicCheck = (31 - sum % 31) % 31;
|
|
1545
|
-
const expected = charset[logicCheck];
|
|
1546
|
-
return v[17] === expected;
|
|
1547
|
-
}
|
|
1548
|
-
function isHexColor(s) {
|
|
1549
|
-
const v = String(s != null ? s : "").trim();
|
|
1550
|
-
return /^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/.test(v);
|
|
1551
|
-
}
|
|
1552
|
-
function isURL(s) {
|
|
1553
|
-
const v = String(s != null ? s : "").trim();
|
|
1554
|
-
if (v === "") return false;
|
|
1555
|
-
try {
|
|
1556
|
-
const u = new URL(v);
|
|
1557
|
-
return ["http:", "https:", "ftp:"].includes(u.protocol) && !!u.hostname;
|
|
1558
|
-
} catch (e) {
|
|
1559
|
-
return false;
|
|
1560
|
-
}
|
|
1561
|
-
}
|
|
1562
|
-
function isIPv4(s) {
|
|
1563
|
-
const v = String(s != null ? s : "").trim();
|
|
1564
|
-
if (v === "") return false;
|
|
1565
|
-
const parts = v.split(".");
|
|
1566
|
-
if (parts.length !== 4) return false;
|
|
1567
|
-
for (const p of parts) {
|
|
1568
|
-
if (!/^\d+$/.test(p)) return false;
|
|
1569
|
-
if (p.length > 1 && p.startsWith("0")) return false;
|
|
1570
|
-
const n = Number(p);
|
|
1571
|
-
if (n < 0 || n > 255) return false;
|
|
1572
|
-
}
|
|
1573
|
-
return true;
|
|
1574
|
-
}
|
|
1575
|
-
function isIPv6(s) {
|
|
1576
|
-
const v = String(s != null ? s : "").trim();
|
|
1577
|
-
if (v === "") return false;
|
|
1578
|
-
const lastColon = v.lastIndexOf(":");
|
|
1579
|
-
if (lastColon !== -1 && v.includes(".")) {
|
|
1580
|
-
const ipv6Part = v.slice(0, lastColon);
|
|
1581
|
-
const ipv4Part = v.slice(lastColon + 1);
|
|
1582
|
-
return isIPv6(ipv6Part) && isIPv4(ipv4Part);
|
|
1583
|
-
}
|
|
1584
|
-
const dblColonCount = (v.match(/::/g) || []).length;
|
|
1585
|
-
if (dblColonCount > 1) return false;
|
|
1586
|
-
const segments = v.split(":");
|
|
1587
|
-
if (v.startsWith("::")) segments.shift();
|
|
1588
|
-
if (v.endsWith("::")) segments.pop();
|
|
1589
|
-
const segmentsFiltered = segments.filter((seg) => seg !== "");
|
|
1590
|
-
if (dblColonCount === 0 && segmentsFiltered.length !== 8) return false;
|
|
1591
|
-
if (dblColonCount === 1 && segmentsFiltered.length >= 1 && segmentsFiltered.length <= 7) {
|
|
1592
|
-
} else if (dblColonCount === 1 && segments.length === 0) {
|
|
1593
|
-
return true;
|
|
1594
|
-
} else if (dblColonCount === 0 && segmentsFiltered.length === 8) {
|
|
1595
|
-
} else {
|
|
1596
|
-
return false;
|
|
1597
|
-
}
|
|
1598
|
-
return segmentsFiltered.every(
|
|
1599
|
-
(seg) => seg.length >= 1 && seg.length <= 4 && /^[0-9a-fA-F]{1,4}$/.test(seg)
|
|
1600
|
-
);
|
|
1601
|
-
}
|
|
1602
|
-
function isIP(s, version) {
|
|
1603
|
-
if (version === 4 || version === "4") return isIPv4(s);
|
|
1604
|
-
if (version === 6 || version === "6") return isIPv6(s);
|
|
1605
|
-
return isIPv4(s) || isIPv6(s);
|
|
1606
|
-
}
|
|
1607
|
-
function isIPRange(s) {
|
|
1608
|
-
const v = String(s != null ? s : "").trim();
|
|
1609
|
-
if (v === "") return false;
|
|
1610
|
-
const parts = v.split("/");
|
|
1611
|
-
if (parts.length !== 2) return false;
|
|
1612
|
-
const [ip, prefixStr] = parts;
|
|
1613
|
-
if (!/^\d+$/.test(prefixStr)) return false;
|
|
1614
|
-
const prefix = Number(prefixStr);
|
|
1615
|
-
if (ip.includes(":")) {
|
|
1616
|
-
if (!isIPv6(ip)) return false;
|
|
1617
|
-
return prefix >= 0 && prefix <= 128;
|
|
1618
|
-
}
|
|
1619
|
-
if (!isIPv4(ip)) return false;
|
|
1620
|
-
return prefix >= 0 && prefix <= 32;
|
|
1621
|
-
}
|
|
1622
|
-
function isPortNumber(s) {
|
|
1623
|
-
const v = typeof s === "number" ? s : Number(String(s != null ? s : "").trim());
|
|
1624
|
-
return Number.isInteger(v) && v >= 0 && v <= 65535;
|
|
1625
|
-
}
|
|
1626
|
-
function isLatitude(s) {
|
|
1627
|
-
const v = typeof s === "number" ? s : Number(String(s != null ? s : "").trim());
|
|
1628
|
-
return Number.isFinite(v) && v >= -90 && v <= 90;
|
|
1629
|
-
}
|
|
1630
|
-
function isLongitude(s) {
|
|
1631
|
-
const v = typeof s === "number" ? s : Number(String(s != null ? s : "").trim());
|
|
1632
|
-
return Number.isFinite(v) && v >= -180 && v <= 180;
|
|
1633
|
-
}
|
|
1634
|
-
|
|
1635
700
|
// src/web/network/request.ts
|
|
1636
701
|
var requestCache = /* @__PURE__ */ new Map();
|
|
1637
702
|
function request(config) {
|
|
703
|
+
const {
|
|
704
|
+
url,
|
|
705
|
+
data,
|
|
706
|
+
header,
|
|
707
|
+
method = "GET",
|
|
708
|
+
resKey,
|
|
709
|
+
msgKey,
|
|
710
|
+
codeKey,
|
|
711
|
+
successKey,
|
|
712
|
+
successCode,
|
|
713
|
+
reloginCode,
|
|
714
|
+
showLoading = true,
|
|
715
|
+
toastError = true,
|
|
716
|
+
enableChunked = false,
|
|
717
|
+
cacheTime,
|
|
718
|
+
resMap,
|
|
719
|
+
responseType = "json",
|
|
720
|
+
timeout: timeout2 = 6e4,
|
|
721
|
+
onTaskReady
|
|
722
|
+
} = config;
|
|
1638
723
|
const controller = new AbortController();
|
|
1639
724
|
const signal = controller.signal;
|
|
1640
725
|
let chunkCallback = null;
|
|
@@ -1647,30 +732,12 @@ function request(config) {
|
|
|
1647
732
|
chunkCallback = null;
|
|
1648
733
|
}
|
|
1649
734
|
};
|
|
1650
|
-
|
|
735
|
+
onTaskReady == null ? void 0 : onTaskReady(task);
|
|
736
|
+
return new Promise((resolve, reject) => {
|
|
1651
737
|
const execute = () => __async(null, null, function* () {
|
|
1652
738
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1653
|
-
const {
|
|
1654
|
-
url,
|
|
1655
|
-
data,
|
|
1656
|
-
header,
|
|
1657
|
-
method = "GET",
|
|
1658
|
-
resKey,
|
|
1659
|
-
msgKey,
|
|
1660
|
-
codeKey,
|
|
1661
|
-
successKey,
|
|
1662
|
-
successCode,
|
|
1663
|
-
reloginCode,
|
|
1664
|
-
showLoading = true,
|
|
1665
|
-
toastError = true,
|
|
1666
|
-
enableChunked = false,
|
|
1667
|
-
cacheTime,
|
|
1668
|
-
responseInterceptor,
|
|
1669
|
-
responseType = "json",
|
|
1670
|
-
timeout = 6e4
|
|
1671
|
-
} = config;
|
|
1672
739
|
const isGet = method === "GET";
|
|
1673
|
-
const isObjectData = (0,
|
|
740
|
+
const isObjectData = (0, import_es_toolkit.isPlainObject)(data);
|
|
1674
741
|
const isArrayData = !isObjectData && Array.isArray(data);
|
|
1675
742
|
const fillData = isObjectData ? filterRequestData(data) : data;
|
|
1676
743
|
const fillHeader = filterRequestHeader(header);
|
|
@@ -1720,7 +787,7 @@ function request(config) {
|
|
|
1720
787
|
const timeoutId = setTimeout(() => {
|
|
1721
788
|
isTimeout = true;
|
|
1722
789
|
controller.abort();
|
|
1723
|
-
},
|
|
790
|
+
}, timeout2);
|
|
1724
791
|
try {
|
|
1725
792
|
const response = yield fetch(fillUrl, {
|
|
1726
793
|
method,
|
|
@@ -1741,7 +808,7 @@ function request(config) {
|
|
|
1741
808
|
}
|
|
1742
809
|
const resData = yield parseResponse(response, responseType);
|
|
1743
810
|
if (showLoading) (_d = appConfig2.hideLoading) == null ? void 0 : _d.call(appConfig2);
|
|
1744
|
-
const res =
|
|
811
|
+
const res = resMap ? resMap(resData) : resData;
|
|
1745
812
|
const code = getObjectValue(res, codeKey);
|
|
1746
813
|
const scode = successKey ? getObjectValue(res, successKey) : code;
|
|
1747
814
|
const msg = getObjectValue(res, msgKey);
|
|
@@ -1777,8 +844,6 @@ function request(config) {
|
|
|
1777
844
|
});
|
|
1778
845
|
execute();
|
|
1779
846
|
});
|
|
1780
|
-
promise.task = task;
|
|
1781
|
-
return promise;
|
|
1782
847
|
}
|
|
1783
848
|
function filterRequestData(data) {
|
|
1784
849
|
const res = {};
|
|
@@ -1798,8 +863,8 @@ function filterRequestHeader(header) {
|
|
|
1798
863
|
}
|
|
1799
864
|
function logRequestInfo(options) {
|
|
1800
865
|
const { log } = getBaseToolsConfig();
|
|
1801
|
-
const {
|
|
1802
|
-
if (!log || !
|
|
866
|
+
const { showLog = true } = options.config;
|
|
867
|
+
if (!log || !showLog) return;
|
|
1803
868
|
const { config, res, fromCache = false, startTime, status, e } = options;
|
|
1804
869
|
const { url, data, header, method, logExtra } = config;
|
|
1805
870
|
const endTime = Date.now();
|
|
@@ -1817,7 +882,7 @@ function logRequestInfo(options) {
|
|
|
1817
882
|
duration: endTime - startTime
|
|
1818
883
|
}, logExtra);
|
|
1819
884
|
if (status === "success") {
|
|
1820
|
-
info.res = (0,
|
|
885
|
+
info.res = (0, import_es_toolkit.cloneDeep)(res);
|
|
1821
886
|
log("info", info);
|
|
1822
887
|
} else {
|
|
1823
888
|
info.e = e;
|
|
@@ -1913,7 +978,7 @@ function enhanceWebApi(webApi, apiName) {
|
|
|
1913
978
|
toastSuccess = false,
|
|
1914
979
|
toastError = true,
|
|
1915
980
|
showLog = true,
|
|
1916
|
-
|
|
981
|
+
resMap,
|
|
1917
982
|
logExtra
|
|
1918
983
|
} = finalConfig;
|
|
1919
984
|
const {
|
|
@@ -1930,14 +995,14 @@ function enhanceWebApi(webApi, apiName) {
|
|
|
1930
995
|
return new Promise((resolve, reject) => {
|
|
1931
996
|
webApi(option, finalConfig).then((res) => {
|
|
1932
997
|
if (showLoading) hideLoadingFn == null ? void 0 : hideLoadingFn();
|
|
1933
|
-
const finalRes =
|
|
998
|
+
const finalRes = resMap ? resMap(res) : res;
|
|
1934
999
|
if (showLog) {
|
|
1935
1000
|
const logData = __spreadValues({ name: fname, status: "success", option }, logExtra);
|
|
1936
|
-
if (
|
|
1001
|
+
if (resMap) {
|
|
1937
1002
|
logData.res = res;
|
|
1938
|
-
logData.
|
|
1003
|
+
logData.resMap = (0, import_es_toolkit.cloneDeep)(finalRes);
|
|
1939
1004
|
} else {
|
|
1940
|
-
logData.res = (0,
|
|
1005
|
+
logData.res = (0, import_es_toolkit.cloneDeep)(res);
|
|
1941
1006
|
}
|
|
1942
1007
|
log == null ? void 0 : log("info", logData);
|
|
1943
1008
|
}
|
|
@@ -1965,7 +1030,7 @@ function upload(option, config) {
|
|
|
1965
1030
|
return new Promise((resolve, reject) => {
|
|
1966
1031
|
var _a;
|
|
1967
1032
|
const xhr = new XMLHttpRequest();
|
|
1968
|
-
const { url, file, name = "file", header, formData, timeout = 0 } = option;
|
|
1033
|
+
const { url, file, name = "file", header, formData, timeout: timeout2 = 0 } = option;
|
|
1969
1034
|
const fail = (error) => reject(error);
|
|
1970
1035
|
const success = (responseText) => {
|
|
1971
1036
|
try {
|
|
@@ -2007,7 +1072,7 @@ function upload(option, config) {
|
|
|
2007
1072
|
if (v !== void 0 && v !== null && v !== "") xhr.setRequestHeader(k, String(v));
|
|
2008
1073
|
});
|
|
2009
1074
|
}
|
|
2010
|
-
xhr.timeout =
|
|
1075
|
+
xhr.timeout = timeout2;
|
|
2011
1076
|
const data = new FormData();
|
|
2012
1077
|
data.append(name, file);
|
|
2013
1078
|
if (formData) {
|