@base-web-kits/base-tools-web 0.9.14 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,15 +15,6 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
21
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
- // If the importer is in node compatibility mode or this is not an ESM
23
- // file that has been converted to a CommonJS file using a Babel-
24
- // compatible transform (i.e. "__esModule" has not been set), then set
25
- // "default" to the CommonJS "module.exports" for node compatibility.
26
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
- mod
28
- ));
29
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
19
 
31
20
  // src/web/index.ts
@@ -48,9 +37,9 @@ __export(index_exports, {
48
37
  getLocalStorage: () => getLocalStorage,
49
38
  getOS: () => getOS,
50
39
  getUA: () => getUA,
51
- getUrlQuery: () => getUrlQuery,
52
- getUrlQueryAll: () => getUrlQueryAll,
53
- getUrlQueryNumber: () => getUrlQueryNumber,
40
+ getUrlNumber: () => getUrlNumber,
41
+ getUrlParam: () => getUrlParam,
42
+ getUrlParams: () => getUrlParams,
54
43
  getWindowHeight: () => getWindowHeight,
55
44
  getWindowScrollLeft: () => getWindowScrollLeft,
56
45
  getWindowScrollTop: () => getWindowScrollTop,
@@ -597,1093 +586,28 @@ function removeLocalStorage(key) {
597
586
  localStorage.removeItem(key);
598
587
  }
599
588
 
600
- // src/ts/index.ts
601
- var ts_exports = {};
602
- __export(ts_exports, {
603
- BigNumber: () => import_bignumber.default,
604
- EventBus: () => EventBus,
605
- appendUrlParam: () => appendUrlParam,
606
- arrayMove: () => arrayMove,
607
- big: () => big,
608
- bigCompare: () => bigCompare,
609
- bigDiv: () => bigDiv,
610
- bigEqual: () => bigEqual,
611
- bigFixed: () => bigFixed,
612
- bigGreaterThan: () => bigGreaterThan,
613
- bigGreaterThanOrEqualTo: () => bigGreaterThanOrEqualTo,
614
- bigLessThan: () => bigLessThan,
615
- bigLessThanOrEqual: () => bigLessThanOrEqual,
616
- bigMinus: () => bigMinus,
617
- bigPlus: () => bigPlus,
618
- bigPow: () => bigPow,
619
- bigRound: () => bigRound,
620
- bigTimes: () => bigTimes,
621
- buildOSSUrl: () => buildOSSUrl,
622
- createRandId: () => createRandId,
623
- createTimeRandId: () => createTimeRandId,
624
- createUUID: () => createUUID,
625
- dayjs: () => import_dayjs.default,
626
- getAgeByBirthdate: () => getAgeByBirthdate,
627
- getByteLength: () => getByteLength,
628
- getCountdownParts: () => getCountdownParts,
629
- getDateRangeAfter: () => getDateRangeAfter,
630
- getDateRangeBefore: () => getDateRangeBefore,
631
- getFileSuffix: () => getFileSuffix,
632
- getFileType: () => getFileType,
633
- getOSSAudio: () => getOSSAudio,
634
- getOSSHls: () => getOSSHls,
635
- getOSSImg: () => getOSSImg,
636
- getOSSVideo: () => getOSSVideo,
637
- getObjectKeys: () => getObjectKeys,
638
- getQnAudio: () => getQnAudio,
639
- getQnHls: () => getQnHls,
640
- getQnImg: () => getQnImg,
641
- getQnVideo: () => getQnVideo,
642
- getUrlNumber: () => getUrlNumber,
643
- getUrlParam: () => getUrlParam,
644
- getUrlParamAll: () => getUrlParamAll,
645
- isBankCard: () => isBankCard,
646
- isChinese: () => isChinese,
647
- isChineseName: () => isChineseName,
648
- isDigits: () => isDigits,
649
- isEmail: () => isEmail,
650
- isHKMOPermit: () => isHKMOPermit,
651
- isHexColor: () => isHexColor,
652
- isIP: () => isIP,
653
- isIPRange: () => isIPRange,
654
- isIPv6: () => isIPv6,
655
- isIdentityCard: () => isIdentityCard,
656
- isJSON: () => isJSON,
657
- isLandline: () => isLandline,
658
- isLatitude: () => isLatitude,
659
- isLetter: () => isLetter,
660
- isLicensePlate: () => isLicensePlate,
661
- isLongitude: () => isLongitude,
662
- isMilitaryId: () => isMilitaryId,
663
- isMobilePhone: () => isMobilePhone,
664
- isNumeric: () => isNumeric,
665
- isOfficerId: () => isOfficerId,
666
- isPassport: () => isPassport,
667
- isPhone: () => isPhone,
668
- isPortNumber: () => isPortNumber,
669
- isSoldierId: () => isSoldierId,
670
- isTaiwanPermit: () => isTaiwanPermit,
671
- isTaxID: () => isTaxID,
672
- isURL: () => isURL,
673
- randomBoolean: () => randomBoolean,
674
- randomFloat: () => randomFloat,
675
- randomInt: () => randomInt,
676
- toAsync: () => toAsync,
677
- toChineseCurrency: () => toChineseCurrency,
678
- toChineseNum: () => toChineseNum,
679
- toDayjs: () => toDayjs,
680
- toMaskName: () => toMaskName,
681
- toMaskPhone: () => toMaskPhone,
682
- toMaskText: () => toMaskText,
683
- toThousandth: () => toThousandth,
684
- withDistance: () => withDistance,
685
- withUnit: () => withUnit,
686
- withUnitPx: () => withUnitPx,
687
- zeroPad: () => zeroPad
688
- });
689
-
690
- // src/ts/array/index.ts
691
- function arrayMove(list, fromIndex, toIndex) {
692
- const newList = [...list];
693
- const [removed] = newList.splice(fromIndex, 1);
694
- newList.splice(toIndex, 0, removed);
695
- return newList;
696
- }
697
-
698
- // src/ts/async/index.ts
699
- async function toAsync(p) {
700
- try {
701
- const data = await p;
702
- return [data, null];
703
- } catch (err) {
704
- return [null, err];
705
- }
706
- }
707
-
708
- // src/ts/bean/EventBus.ts
709
- var import_mitt = __toESM(require("mitt"), 1);
710
- var EventBus = class {
711
- _emitter = (0, import_mitt.default)();
712
- /** 订阅 */
713
- on(type, fn) {
714
- this._emitter.on(type, fn);
715
- return this;
716
- }
717
- /** 订阅一次 */
718
- once(type, fn) {
719
- const wrap = (event) => {
720
- this._emitter.off(type, wrap);
721
- fn(event);
722
- };
723
- this._emitter.on(type, wrap);
724
- return this;
725
- }
726
- /** 发布 */
727
- emit(type, event) {
728
- this._emitter.emit(type, event);
729
- return this;
730
- }
731
- /** 移除 */
732
- off(type, fn) {
733
- this._emitter.off(type, fn);
734
- return this;
735
- }
736
- /** 清空 */
737
- clear() {
738
- this._emitter.all.clear();
739
- return this;
740
- }
741
- };
742
-
743
- // src/ts/day/index.ts
744
- var import_dayjs = __toESM(require("dayjs"), 1);
745
- var import_customParseFormat = __toESM(require("dayjs/plugin/customParseFormat"), 1);
746
- var import_utc = __toESM(require("dayjs/plugin/utc"), 1);
747
- var import_timezone = __toESM(require("dayjs/plugin/timezone"), 1);
748
- var import_relativeTime = __toESM(require("dayjs/plugin/relativeTime"), 1);
749
- var import_advancedFormat = __toESM(require("dayjs/plugin/advancedFormat"), 1);
750
- var import_zh_cn = require("dayjs/locale/zh-cn");
751
-
752
- // src/ts/number/big.ts
753
- var import_bignumber = __toESM(require("bignumber.js"), 1);
754
- function big(x) {
755
- return x instanceof import_bignumber.default ? x : new import_bignumber.default(x);
756
- }
757
- function bigPlus(...rest) {
758
- let acc = big(rest[0]);
759
- for (const x of rest.slice(1)) acc = acc.plus(big(x));
760
- return acc.toNumber();
761
- }
762
- function bigMinus(...rest) {
763
- let acc = big(rest[0]);
764
- for (const x of rest.slice(1)) acc = acc.minus(big(x));
765
- return acc.toNumber();
766
- }
767
- function bigTimes(...rest) {
768
- let acc = big(rest[0]);
769
- for (const x of rest.slice(1)) acc = acc.times(big(x));
770
- return acc.toNumber();
771
- }
772
- function bigDiv(...rest) {
773
- let acc = big(rest[0]);
774
- for (const x of rest.slice(1)) acc = acc.div(big(x));
775
- return acc.toNumber();
776
- }
777
- function bigPow(x, y) {
778
- return big(x).pow(big(y)).toNumber();
779
- }
780
- function bigRound(x, dp = 0, rm = import_bignumber.default.ROUND_HALF_UP) {
781
- return big(x).decimalPlaces(dp, rm).toNumber();
782
- }
783
- function bigFixed(x, dp = 2, rm = import_bignumber.default.ROUND_HALF_UP) {
784
- return big(x).toFixed(dp, rm);
785
- }
786
- function bigCompare(a, b) {
787
- return big(a).comparedTo(big(b));
788
- }
789
- function bigEqual(a, b) {
790
- return big(a).isEqualTo(big(b));
791
- }
792
- function bigGreaterThan(a, b) {
793
- return big(a).isGreaterThan(big(b));
794
- }
795
- function bigGreaterThanOrEqualTo(a, b) {
796
- return big(a).isGreaterThanOrEqualTo(big(b));
797
- }
798
- function bigLessThan(a, b) {
799
- return big(a).isLessThan(big(b));
800
- }
801
- function bigLessThanOrEqual(a, b) {
802
- return big(a).isLessThanOrEqualTo(big(b));
803
- }
804
-
805
- // src/ts/number/format.ts
806
- function zeroPad(n, len = 2) {
807
- return String(n).padStart(len, "0");
808
- }
809
- function withUnit(num, unit = "") {
810
- if (num === null || num === void 0 || num === "") return "";
811
- if (typeof num === "number") return `${num}${unit}`;
812
- const str = String(num).trim();
813
- if (str === "") return "";
814
- return isNaN(+str) ? str : `${str}${unit}`;
815
- }
816
- function withUnitPx(num) {
817
- return withUnit(num, "px");
818
- }
819
- function withDistance(m) {
820
- const n = Number(m ?? 0);
821
- if (!Number.isFinite(n)) return "0m";
822
- return n >= 1e3 ? `${+(n / 1e3).toFixed(2)}km` : `${+n.toFixed(2)}m`;
823
- }
824
- function toThousandth(str) {
825
- const v = String(str ?? "").trim();
826
- if (v === "") return "";
827
- let sign = "";
828
- let num = v;
829
- if (num[0] === "-" || num[0] === "+") {
830
- sign = num[0];
831
- num = num.slice(1);
832
- }
833
- const [intPart, decPart] = num.split(".");
834
- const groupedInt = intPart.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
835
- return decPart !== void 0 && decPart !== "" ? `${sign}${groupedInt}.${decPart}` : `${sign}${groupedInt}`;
836
- }
837
- function toChineseNum(num) {
838
- const numInt = Math.trunc(+num);
839
- if (numInt === 0) return "\u96F6";
840
- const digit = ["\u96F6", "\u4E00", "\u4E8C", "\u4E09", "\u56DB", "\u4E94", "\u516D", "\u4E03", "\u516B", "\u4E5D"];
841
- const unit = ["", "\u5341", "\u767E", "\u5343"];
842
- const bigUnit = ["", "\u4E07", "\u4EBF", "\u5146"];
843
- const section4 = (n2) => {
844
- let str = "", zeroFlag = false;
845
- for (let i = 0; i < 4; i++) {
846
- const d = n2 % 10;
847
- n2 = Math.floor(n2 / 10);
848
- if (d === 0) {
849
- zeroFlag = true;
850
- continue;
851
- }
852
- if (zeroFlag) str = digit[0] + str;
853
- str = digit[d] + unit[i] + str;
854
- zeroFlag = false;
855
- }
856
- return str;
857
- };
858
- let res = "";
859
- let sectionIndex = 0;
860
- let n = Math.abs(numInt);
861
- while (n > 0) {
862
- const seg = n % 1e4;
863
- n = Math.floor(n / 1e4);
864
- if (seg) {
865
- const segStr = section4(seg);
866
- res = segStr + (sectionIndex ? bigUnit[sectionIndex] : "") + res;
867
- } else if (res && !res.startsWith("\u96F6")) {
868
- res = `\u96F6${res}`;
869
- }
870
- sectionIndex++;
871
- }
872
- res = res.replace(/^一十/, "\u5341");
873
- return numInt < 0 ? `\u8D1F${res}` : res;
874
- }
875
- function toChineseCurrency(amount, opts = {}) {
876
- const dp = opts.precision ?? 2;
877
- const rm = opts.rm ?? import_bignumber.default.ROUND_HALF_UP;
878
- const yuan = opts.yuanChar ?? "\u5143";
879
- if (amount === null || amount === void 0) return "";
880
- const bn = new import_bignumber.default(amount);
881
- if (!bn.isFinite()) return "";
882
- const s = bn.toFixed(dp, rm);
883
- const sign = s.startsWith("-") ? "\u8D1F" : "";
884
- const [intStr, decStr = ""] = s.replace(/^-/, "").split(".");
885
- const digit = ["\u96F6", "\u58F9", "\u8D30", "\u53C1", "\u8086", "\u4F0D", "\u9646", "\u67D2", "\u634C", "\u7396"];
886
- const unit = ["", "\u62FE", "\u4F70", "\u4EDF"];
887
- const bigUnit = ["", "\u4E07", "\u4EBF", "\u5146"];
888
- const smallUnit = ["\u89D2", "\u5206", "\u5398"];
889
- const section4 = (n) => {
890
- let str = "";
891
- let zeroFlag = false;
892
- for (let i = 0; i < 4; i++) {
893
- const d = n.mod(10).toNumber();
894
- n = n.idiv(10);
895
- if (d === 0) {
896
- zeroFlag = true;
897
- continue;
898
- }
899
- if (zeroFlag) str = digit[0] + str;
900
- str = digit[d] + unit[i] + str;
901
- zeroFlag = false;
902
- }
903
- return str.replace(/零+$/g, "");
904
- };
905
- const intNum = new import_bignumber.default(intStr);
906
- let res = "";
907
- if (intNum.isZero()) {
908
- res = digit[0];
909
- } else {
910
- let n = intNum.abs();
911
- let sectionIndex = 0;
912
- while (n.gt(0)) {
913
- const seg = n.mod(1e4);
914
- n = n.idiv(1e4);
915
- if (seg.gt(0)) {
916
- const segStr = section4(seg);
917
- const needZero = res && !res.startsWith(digit[0]) && (seg.lt(1e3) || seg.mod(1e3).isZero());
918
- const bu = sectionIndex ? bigUnit[sectionIndex] : "";
919
- res = segStr + bu + (needZero ? digit[0] : "") + res;
920
- } else if (res && !res.startsWith(digit[0])) {
921
- res = digit[0] + res;
922
- }
923
- sectionIndex++;
924
- }
925
- res = res.replace(/^壹拾/, "\u62FE");
926
- }
927
- let frac = "";
928
- for (let i = 0; i < Math.min(3, dp); i++) {
929
- const ch = decStr[i] || "0";
930
- const d = ch.charCodeAt(0) - 48;
931
- if (d > 0) frac += digit[d] + smallUnit[i];
932
- }
933
- return frac ? `${sign}${res}${yuan}${frac}` : `${sign}${res}${yuan}\u6574`;
934
- }
935
-
936
- // src/ts/number/random.ts
937
- function randomInt(a, b) {
938
- if (!Number.isFinite(a) || !Number.isFinite(b)) {
939
- throw new TypeError("min \u548C max \u5FC5\u987B\u662F\u6709\u9650\u6570\u503C");
940
- }
941
- const low = Math.min(a, b);
942
- const high = Math.max(a, b);
943
- const minInt = Math.ceil(low);
944
- const maxInt = Math.floor(high);
945
- if (maxInt < minInt) {
946
- throw new RangeError("\u53D6\u6574\u540E\u533A\u95F4\u4E3A\u7A7A");
947
- }
948
- if (maxInt === minInt) return minInt;
949
- return Math.floor(Math.random() * (maxInt - minInt + 1)) + minInt;
950
- }
951
- function randomFloat(a, b) {
952
- if (!Number.isFinite(a) || !Number.isFinite(b)) {
953
- throw new TypeError("min \u548C max \u5FC5\u987B\u662F\u6709\u9650\u6570\u503C");
954
- }
955
- const low = Math.min(a, b);
956
- const high = Math.max(a, b);
957
- if (high === low) return low;
958
- return Math.random() * (high - low) + low;
959
- }
960
- function randomBoolean() {
961
- return Math.random() < 0.5;
962
- }
963
-
964
- // src/ts/day/index.ts
965
- import_dayjs.default.extend(import_customParseFormat.default);
966
- import_dayjs.default.extend(import_utc.default);
967
- import_dayjs.default.extend(import_timezone.default);
968
- import_dayjs.default.extend(import_relativeTime.default);
969
- import_dayjs.default.extend(import_advancedFormat.default);
970
- import_dayjs.default.locale("zh-cn");
971
- function toDayjs(t, fmt) {
972
- if (t === null || t === void 0) return (0, import_dayjs.default)();
973
- if (typeof t === "number") {
974
- const s = String(Math.trunc(t));
975
- return (0, import_dayjs.default)(s.length === 10 ? t * 1e3 : t, fmt);
976
- }
977
- if (typeof t === "string") {
978
- const s = t.trim();
979
- if (/^\d{10}$/.test(s)) return (0, import_dayjs.default)(Number(s) * 1e3, fmt);
980
- if (/^\d{13}$/.test(s)) return (0, import_dayjs.default)(Number(s), fmt);
981
- if (/^\d{4}-\d{2}-\d{2}$/.test(s)) return (0, import_dayjs.default)(s, fmt || "YYYY-MM-DD");
982
- if (/^\d{4}\/\d{2}\/\d{2}$/.test(s)) return (0, import_dayjs.default)(s, fmt || "YYYY/MM/DD");
983
- if (/^\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2}$/.test(s))
984
- return (0, import_dayjs.default)(s, fmt || "YYYY-MM-DD HH:mm:ss");
985
- if (/^\d{4}\/\d{2}\/\d{2}\s+\d{2}:\d{2}:\d{2}$/.test(s))
986
- return (0, import_dayjs.default)(s, fmt || "YYYY/MM/DD HH:mm:ss");
987
- return (0, import_dayjs.default)(s, fmt);
988
- }
989
- return (0, import_dayjs.default)(t, fmt);
990
- }
991
- function getDateRangeBefore(offset, fmt = "YYYY-MM-DD") {
992
- const now = toDayjs(Date.now());
993
- const n = Math.max(0, Math.trunc(offset));
994
- const hasTime = /H|h|m|s|S|A|a|x|X/.test(fmt);
995
- const startDay = now.add(-n, "day");
996
- const endDay = now;
997
- const start = (hasTime ? startDay.startOf("day") : startDay).format(fmt);
998
- const end = (hasTime ? endDay.endOf("day") : endDay).format(fmt);
999
- return [start, end];
1000
- }
1001
- function getDateRangeAfter(offset, fmt = "YYYY-MM-DD") {
1002
- const now = toDayjs(Date.now());
1003
- const n = Math.max(0, Math.trunc(offset));
1004
- const hasTime = /H|h|m|s|S|A|a|x|X/.test(fmt);
1005
- const startDay = now;
1006
- const endDay = now.add(n, "day");
1007
- const start = (hasTime ? startDay.startOf("day") : startDay).format(fmt);
1008
- const end = (hasTime ? endDay.endOf("day") : endDay).format(fmt);
1009
- return [start, end];
1010
- }
1011
- function getCountdownParts(diff) {
1012
- if (diff <= 0) return { d: "00", h: "00", m: "00", s: "00", ms: "000" };
1013
- const d = Math.floor(diff / (1e3 * 60 * 60 * 24));
1014
- const h = Math.floor(diff / (1e3 * 60 * 60) % 24);
1015
- const m = Math.floor(diff / (1e3 * 60) % 60);
1016
- const s = Math.floor(diff / 1e3 % 60);
1017
- const ms = diff % 1e3;
1018
- return {
1019
- d: zeroPad(d),
1020
- h: zeroPad(h),
1021
- m: zeroPad(m),
1022
- s: zeroPad(s),
1023
- ms: zeroPad(ms, 3)
1024
- };
1025
- }
1026
- function getAgeByBirthdate(birthdate) {
1027
- const birth = toDayjs(birthdate, "YYYY-MM-DD");
1028
- const now = toDayjs(Date.now());
1029
- const totalMonths = (now.year() - birth.year()) * 12 + (now.month() - birth.month());
1030
- const adjustedMonths = now.date() < birth.date() ? totalMonths - 1 : totalMonths;
1031
- if (adjustedMonths >= 12) {
1032
- let age = Math.floor(adjustedMonths / 12);
1033
- const birthdayThisYear = birth.add(age, "year");
1034
- if (now.isBefore(birthdayThisYear)) {
1035
- age--;
1036
- }
1037
- return { age, type: "year" };
1038
- }
1039
- return { age: adjustedMonths, type: "month" };
1040
- }
1041
-
1042
- // src/ts/lodash/index.ts
1043
- var lodash_exports = {};
1044
- __reExport(lodash_exports, require("lodash-es"));
1045
-
1046
- // src/ts/index.ts
1047
- __reExport(ts_exports, lodash_exports);
1048
-
1049
- // src/ts/object/index.ts
1050
- function getObjectKeys(obj) {
1051
- return Object.keys(obj);
1052
- }
1053
-
1054
- // src/ts/string/format.ts
1055
- function toMaskText(s, keepLeft = 1, keepRight = 0, maskChar = "*") {
1056
- if (!s) return "";
1057
- const v = String(s);
1058
- const l = Math.max(0, keepLeft);
1059
- const r = Math.max(0, keepRight);
1060
- const len = v.length;
1061
- const left = Math.min(l, len);
1062
- const right = Math.min(r, len - left);
1063
- const mid = len - left - right;
1064
- if (mid <= 0) return v;
1065
- const m = maskChar && maskChar.length > 0 ? maskChar : "*";
1066
- return v.slice(0, left) + m.repeat(mid) + v.slice(len - right);
1067
- }
1068
- function toMaskPhone(phone) {
1069
- return toMaskText(phone, 3, 4);
1070
- }
1071
- function toMaskName(name) {
1072
- if (!name) return "";
1073
- const v = String(name);
1074
- return v.length <= 2 ? toMaskText(v, 1, 0) : toMaskText(v, 1, 1);
1075
- }
1076
-
1077
- // src/ts/string/random.ts
1078
- function createUUID() {
1079
- return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
1080
- const r = Math.random() * 16 | 0, v = c === "x" ? r : r & 3 | 8;
1081
- return v.toString(16);
1082
- });
1083
- }
1084
- function createRandId(prefix = "id_") {
1085
- return `${prefix}${Math.random().toString(36).substring(2, 16)}`;
1086
- }
1087
- function createTimeRandId(digits = 6) {
1088
- const base = 10 ** (digits - 1);
1089
- const range = 9 * base;
1090
- const randomInt2 = Math.floor(Math.random() * range) + base;
1091
- return `${Date.now()}${randomInt2}`;
1092
- }
1093
-
1094
- // src/ts/string/other.ts
1095
- function getByteLength(data) {
1096
- if (typeof data === "string") {
1097
- let byteLen = 0;
1098
- for (let i = 0; i < data.length; i++) {
1099
- const code = data.charCodeAt(i);
1100
- if (code <= 127) {
1101
- byteLen += 1;
1102
- } else if (code <= 2047) {
1103
- byteLen += 2;
1104
- } else if (code >= 55296 && code <= 56319) {
1105
- byteLen += 4;
1106
- i++;
1107
- } else {
1108
- byteLen += 3;
1109
- }
1110
- }
1111
- return byteLen;
1112
- }
1113
- if ("byteLength" in data) return data.byteLength;
1114
- if ("size" in data) return data.size;
1115
- throw new TypeError("getByteLength: Unsupported type");
1116
- }
1117
-
1118
- // src/ts/url/file/index.ts
1119
- var FILE_TYPE = {
1120
- img: ["png", "jpg", "jpeg", "gif", "svg", "webp"],
1121
- video: ["mp4", "mov", "m4v"],
1122
- voice: ["mp3", "wav", "m4a"],
1123
- excel: ["csv", "xls", "xlsx", "xlsm", "ods"],
1124
- word: ["txt", "doc", "docx", "pdf", "md", "wps"],
1125
- zip: ["zip", "gz", "tar", "rar", "7z"],
1126
- ppt: ["ppt", "pptx", "odp"],
1127
- app: ["apk", "ipa"]
1128
- };
1129
- function getFileSuffix(fileName) {
1130
- if (fileName.startsWith(".")) return "";
1131
- const idx = fileName.lastIndexOf(".");
1132
- return idx > 0 ? fileName.slice(idx + 1).toLowerCase() : "";
1133
- }
1134
- function getFileType(fileName) {
1135
- const suffix = getFileSuffix(fileName);
1136
- if (!suffix) return "unknown";
1137
- const keys = getObjectKeys(FILE_TYPE);
1138
- for (const key of keys) {
1139
- if (FILE_TYPE[key].includes(suffix)) {
1140
- return key;
1141
- }
1142
- }
1143
- return "unknown";
1144
- }
1145
-
1146
- // src/ts/url/oss/index.ts
1147
- function getOSSImg(src, option) {
1148
- return buildOSSUrl(src, "image", option);
1149
- }
1150
- function getOSSVideo(src, option) {
1151
- return buildOSSUrl(src, "video", option);
1152
- }
1153
- function getOSSAudio(src, option) {
1154
- return buildOSSUrl(src, "audio", option);
1155
- }
1156
- function getOSSHls(src, option) {
1157
- return buildOSSUrl(src, "hls", option);
1158
- }
1159
- function buildOSSUrl(src, type, option) {
1160
- if (!src || !option) return src;
1161
- if (src.startsWith("blob:")) return src;
1162
- if (src.includes(".svg")) return src;
1163
- const segs = [];
1164
- for (const [k, v] of Object.entries(option)) {
1165
- const seg = k === "watermark" ? getWatermark(v) : getOSSSegs(k, v);
1166
- if (seg) segs.push(seg);
1167
- }
1168
- if (!segs.length) return src;
1169
- const base = src.split("?")[0];
1170
- return `${base}?x-oss-process=${type}/${segs.join("/")}`;
1171
- }
1172
- function getOSSSegs(type, option) {
1173
- if (!option && option !== 0) return "";
1174
- if (option === true) return type;
1175
- if (typeof option === "number" || typeof option === "string") return `${type},${option}`;
1176
- const segs = Object.entries(option).map(([k, v]) => `${k}_${v}`).join(",");
1177
- return segs ? `${type},${segs}` : "";
1178
- }
1179
- function getWatermark(w) {
1180
- if (!w) return "";
1181
- if (w.image) w.image = toBase64Url(w.image);
1182
- if (w.text) w.text = toBase64Url(w.text);
1183
- if (w.type) w.type = toBase64Url(w.type);
1184
- return getOSSSegs("watermark", w);
1185
- }
1186
- function toBase64Url(s) {
1187
- let b64 = "";
1188
- if (typeof Buffer !== "undefined") {
1189
- const buf = Buffer.from(s, "utf-8");
1190
- b64 = buf.toString("base64");
1191
- } else {
1192
- try {
1193
- b64 = btoa(unescape(encodeURIComponent(s)));
1194
- } catch {
1195
- b64 = "";
1196
- }
1197
- }
1198
- return b64.replace(/=+$/g, "").replace(/\+/g, "-").replace(/\//g, "_");
1199
- }
1200
-
1201
- // src/ts/url/param/index.ts
1202
- function getUrlParam(key, url) {
1203
- const raw = url.includes("?") ? url.slice(url.indexOf("?") + 1) : url.includes("=") ? url : "";
1204
- const qs = raw.split("#")[0];
1205
- if (!qs) return null;
1206
- const pairs = qs.split("&").filter(Boolean);
1207
- const decode = (s) => {
1208
- try {
1209
- return decodeURIComponent(s.replace(/\+/g, " "));
1210
- } catch {
1211
- return s;
1212
- }
1213
- };
1214
- for (const pair of pairs) {
1215
- const i = pair.indexOf("=");
1216
- const k = i >= 0 ? pair.slice(0, i) : pair;
1217
- if (decode(k) === key) {
1218
- const v = i >= 0 ? decode(pair.slice(i + 1)) : "";
1219
- return v !== "null" && v !== "undefined" ? v : null;
1220
- }
1221
- }
1222
- return null;
589
+ // src/web/url/index.ts
590
+ function getUrlParam(key, url = window.location.href) {
591
+ const searchParams = new URL(url.includes("?") ? url : `?${url}`, "http://localhost").searchParams;
592
+ const value = searchParams.get(key);
593
+ return value === "null" || value === "undefined" ? null : value;
1223
594
  }
1224
- function getUrlNumber(key, url) {
595
+ function getUrlNumber(key, url = window.location.href) {
1225
596
  const str = getUrlParam(key, url);
1226
597
  if (!str) return null;
1227
598
  const num = Number(str);
1228
599
  return isNaN(num) ? null : num;
1229
600
  }
1230
- function getUrlParamAll(url) {
1231
- const raw = url.includes("?") ? url.slice(url.indexOf("?") + 1) : url.includes("=") ? url : "";
1232
- const qs = raw.split("#")[0];
601
+ function getUrlParams(url = window.location.href) {
602
+ const searchParams = new URL(url.includes("?") ? url : `?${url}`, "http://localhost").searchParams;
1233
603
  const result = {};
1234
- if (!qs) return result;
1235
- const decode = (s) => {
1236
- try {
1237
- return decodeURIComponent(s.replace(/\+/g, " "));
1238
- } catch {
1239
- return s;
1240
- }
1241
- };
1242
- for (const seg of qs.split("&")) {
1243
- if (!seg) continue;
1244
- const i = seg.indexOf("=");
1245
- const k = i >= 0 ? seg.slice(0, i) : seg;
1246
- const v = i >= 0 ? seg.slice(i + 1) : "";
1247
- const dv = decode(v);
1248
- if (dv !== "null" && dv !== "undefined") {
1249
- result[decode(k)] = dv;
604
+ for (const [key, value] of searchParams.entries()) {
605
+ if (value !== "null" && value !== "undefined") {
606
+ result[key] = value;
1250
607
  }
1251
608
  }
1252
609
  return result;
1253
610
  }
1254
- function appendUrlParam(url, param) {
1255
- if (!param || typeof param !== "object") return url;
1256
- const hashIndex = url.indexOf("#");
1257
- const baseWithoutHash = hashIndex >= 0 ? url.slice(0, hashIndex) : url;
1258
- const hash = hashIndex >= 0 ? url.slice(hashIndex) : "";
1259
- const [base, existingQs] = baseWithoutHash.split("?");
1260
- const parts = [];
1261
- if (existingQs) parts.push(existingQs);
1262
- for (const key in param) {
1263
- const rawVal = param[key];
1264
- if (rawVal === null || rawVal === void 0) continue;
1265
- const val = typeof rawVal === "object" ? JSON.stringify(rawVal) : String(rawVal);
1266
- parts.push(`${encodeURIComponent(key)}=${encodeURIComponent(val)}`);
1267
- }
1268
- const qs = parts.filter(Boolean).join("&");
1269
- return base + (qs ? `?${qs}` : "") + hash;
1270
- }
1271
-
1272
- // src/ts/url/qn/index.ts
1273
- function getQnImg(src, option) {
1274
- if (!src || !option) return src;
1275
- if (src.startsWith("blob:")) return src;
1276
- if (src.includes(".svg")) return src;
1277
- const segs = [];
1278
- if (option.imageslim) segs.push("imageslim");
1279
- if (option.imageView2) segs.push(getImageView2(option.imageView2));
1280
- const mogr = getImageMogr2(option.imageMogr2 ?? option);
1281
- if (mogr) segs.push(mogr);
1282
- if (option.watermark) segs.push(getWatermark2(option.watermark));
1283
- if (option.imageInfo) segs.push("imageInfo");
1284
- if (!segs.length) return src;
1285
- const base = src.split("?")[0];
1286
- return `${base}?${segs.join("|")}`;
1287
- }
1288
- function getQnVideo(src, option) {
1289
- if (!src || !option) return src;
1290
- if (src.startsWith("blob:")) return src;
1291
- if (src.includes(".svg")) return src;
1292
- const segs = [];
1293
- if (option.avthumb) segs.push(getAvthumb(option.avthumb));
1294
- if (option.vframe) segs.push(getVframe(option.vframe));
1295
- if (!segs.length) return src;
1296
- const base = src.split("?")[0];
1297
- return `${base}?${segs.join("|")}`;
1298
- }
1299
- function getQnAudio(src, option) {
1300
- if (!src || !option) return src;
1301
- if (src.startsWith("blob:")) return src;
1302
- const segs = [];
1303
- if (option.avthumb) segs.push(getAvthumb(option.avthumb));
1304
- if (!segs.length) return src;
1305
- const base = src.split("?")[0];
1306
- return `${base}?${segs.join("|")}`;
1307
- }
1308
- function getQnHls(src, option) {
1309
- if (!src || !option) return src;
1310
- if (src.startsWith("blob:")) return src;
1311
- const seg = getAvcvt(option);
1312
- if (!seg) return src;
1313
- const base = src.split("?")[0];
1314
- return `${base}?${seg}`;
1315
- }
1316
- function getImageView2(opt) {
1317
- if (!opt) return "";
1318
- const mode = typeof opt.mode === "number" ? opt.mode : 0;
1319
- const kv = [];
1320
- for (const [k, v] of Object.entries(opt)) {
1321
- if (k === "mode") continue;
1322
- if (typeof v === "boolean") {
1323
- if (v) kv.push(`${k}/1`);
1324
- } else if (typeof v === "number" || typeof v === "string") {
1325
- kv.push(`${k}/${v}`);
1326
- }
1327
- }
1328
- return kv.length ? `imageView2/${mode}/${kv.join("/")}` : `imageView2/${mode}`;
1329
- }
1330
- function getImageMogr2(opt) {
1331
- if (!opt) return "";
1332
- const parts = [];
1333
- const tn = opt.thumbnail;
1334
- if (typeof tn !== "undefined") parts.push(`thumbnail/${tn}`);
1335
- const cp = opt.crop;
1336
- if (typeof cp !== "undefined") parts.push(`crop/${cp}`);
1337
- const rot = opt.rotate;
1338
- if (typeof rot === "number") parts.push(`rotate/${rot}`);
1339
- const ao = opt["auto-orient"];
1340
- if (ao) parts.push("auto-orient");
1341
- const fmt = opt.format;
1342
- if (typeof fmt === "string") parts.push(`format/${fmt}`);
1343
- const il = opt.interlace;
1344
- if (il === 0 || il === 1) parts.push(`interlace/${il}`);
1345
- const bg = opt.background;
1346
- if (typeof bg === "string") parts.push(`background/${bg}`);
1347
- const q = opt.q;
1348
- if (typeof q === "number") parts.push(`q/${q}`);
1349
- const blur = opt.blur;
1350
- if (typeof blur !== "undefined") {
1351
- if (typeof blur === "string") parts.push(`blur/${blur}`);
1352
- else parts.push(`blur/${blur.r}x${blur.s}`);
1353
- }
1354
- const colors = opt.colors;
1355
- if (typeof colors === "number") parts.push(`colors/${colors}`);
1356
- return parts.length ? `imageMogr2/${parts.join("/")}` : "";
1357
- }
1358
- function getWatermark2(w) {
1359
- if (!w) return "";
1360
- const mode = w.type === "image" ? 1 : w.type === "text" ? 2 : typeof w.type === "number" ? w.type : 2;
1361
- const segs = [`watermark/${mode}`];
1362
- if (mode === 1 && w.image) segs.push(`image/${toBase64Url2(w.image)}`);
1363
- if (mode === 2 && w.text) segs.push(`text/${toBase64Url2(w.text)}`);
1364
- if (w.font) segs.push(`font/${toBase64Url2(w.font)}`);
1365
- if (typeof w.fontsize === "number") segs.push(`fontsize/${w.fontsize}`);
1366
- if (w.fill) segs.push(`fill/${toBase64Url2(w.fill)}`);
1367
- if (w.gravity) segs.push(`gravity/${w.gravity}`);
1368
- if (typeof w.dx === "number") segs.push(`dx/${w.dx}`);
1369
- if (typeof w.dy === "number") segs.push(`dy/${w.dy}`);
1370
- if (typeof w.dissolve === "number") segs.push(`dissolve/${w.dissolve}`);
1371
- return segs.join("/");
1372
- }
1373
- function toBase64Url2(s) {
1374
- let b64 = "";
1375
- if (typeof Buffer !== "undefined") {
1376
- const buf = Buffer.from(s, "utf-8");
1377
- b64 = buf.toString("base64");
1378
- } else {
1379
- try {
1380
- b64 = btoa(unescape(encodeURIComponent(s)));
1381
- } catch {
1382
- b64 = "";
1383
- }
1384
- }
1385
- return b64.replace(/=+$/g, "").replace(/\+/g, "-").replace(/\//g, "_");
1386
- }
1387
- function getAvthumb(opt) {
1388
- const parts = [];
1389
- if (opt.format) parts.push(`avthumb/${opt.format}`);
1390
- else parts.push("avthumb");
1391
- if (opt.s) parts.push(`s/${opt.s}`);
1392
- if (opt.vcodec) parts.push(`vcodec/${opt.vcodec}`);
1393
- if (typeof opt.vb !== "undefined") parts.push(`vb/${opt.vb}`);
1394
- if (typeof opt.r === "number") parts.push(`r/${opt.r}`);
1395
- if (typeof opt.ab !== "undefined") parts.push(`ab/${opt.ab}`);
1396
- if (typeof opt.ar === "number") parts.push(`ar/${opt.ar}`);
1397
- if (opt.acodec) parts.push(`acodec/${opt.acodec}`);
1398
- return parts.join("/");
1399
- }
1400
- function getVframe(opt) {
1401
- const parts = [];
1402
- parts.push(`vframe/${opt.format || "jpg"}`);
1403
- if (typeof opt.offset === "number") parts.push(`offset/${opt.offset}`);
1404
- if (typeof opt.w === "number") parts.push(`w/${opt.w}`);
1405
- if (typeof opt.h === "number") parts.push(`h/${opt.h}`);
1406
- return parts.join("/");
1407
- }
1408
- function getAvcvt(opt) {
1409
- const parts = [];
1410
- const level = typeof opt.level === "number" ? `/${opt.level}` : "/3";
1411
- parts.push(`avcvt${level}`);
1412
- parts.push(`format/${opt.format || "m3u8"}`);
1413
- if (typeof opt.segtime === "number") parts.push(`segtime/${opt.segtime}`);
1414
- if (typeof opt.t === "string") parts.push(`t/${opt.t}`);
1415
- if (opt.vcodec) parts.push(`vcodec/${opt.vcodec}`);
1416
- if (typeof opt.vb !== "undefined") parts.push(`vb/${opt.vb}`);
1417
- if (typeof opt.r === "number") parts.push(`r/${opt.r}`);
1418
- if (typeof opt.s === "string") parts.push(`s/${opt.s}`);
1419
- if (opt.acodec) parts.push(`acodec/${opt.acodec}`);
1420
- if (typeof opt.ab !== "undefined") parts.push(`ab/${opt.ab}`);
1421
- if (typeof opt.ar === "number") parts.push(`ar/${opt.ar}`);
1422
- if (typeof opt.output === "string") parts.push(`output/${toBase64Url2(opt.output)}`);
1423
- return parts.join("/");
1424
- }
1425
-
1426
- // src/ts/validator/index.ts
1427
- function isLetter(s) {
1428
- return /^[a-zA-Z]*$/.test(s);
1429
- }
1430
- function isChinese(s) {
1431
- const v = String(s ?? "").trim();
1432
- return /^[\u4E00-\u9FA5]+$/.test(v);
1433
- }
1434
- function isDigits(s) {
1435
- return /^[0-9]+$/.test(s);
1436
- }
1437
- function isNumeric(value, options) {
1438
- const { negative = false, decimal = 2, thousands = false, leadZero = false } = options || {};
1439
- if (value === null || value === void 0 || value === "") return false;
1440
- const str = String(value).trim();
1441
- const sign = negative && str.startsWith("-") ? "-" : "";
1442
- const body = sign ? str.slice(1) : str;
1443
- const thousandsPart = thousands ? "(?:[1-9]\\d{0,2}(,\\d{3})*|0)" : "(?:\\d+)";
1444
- const intPart = thousands ? thousandsPart : leadZero ? "(?:\\d+)" : "(?:0|[1-9]\\d*)";
1445
- const fracPart = decimal === 0 ? "" : `(\\.\\d{1,${decimal}})`;
1446
- const pattern = `^${intPart}${fracPart}$`;
1447
- const reg = new RegExp(pattern);
1448
- return reg.test(body);
1449
- }
1450
- function isMobilePhone(s) {
1451
- const v = String(s ?? "").trim();
1452
- return /^1[3-9]\d{9}$/.test(v);
1453
- }
1454
- function isLandline(s) {
1455
- const v = String(s ?? "").trim();
1456
- return /^0\d{2,3}-?\d{7,8}(?:-\d{1,6})?$/.test(v);
1457
- }
1458
- function isPhone(s) {
1459
- return isMobilePhone(s) || isLandline(s);
1460
- }
1461
- function isEmail(s) {
1462
- const v = String(s ?? "").trim();
1463
- if (v === "") return false;
1464
- 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])?)+$/;
1465
- return emailRegex.test(v);
1466
- }
1467
- function isChineseName(s) {
1468
- const v = String(s ?? "").trim();
1469
- return /^[\u4E00-\u9FA5·]{2,20}$/.test(v);
1470
- }
1471
- function isIdentityCard(code) {
1472
- const v = String(code ?? "").trim();
1473
- if (v === "") return false;
1474
- const isValidDate = (yyyymmdd) => {
1475
- const y = Number(yyyymmdd.slice(0, 4));
1476
- const m = Number(yyyymmdd.slice(4, 6));
1477
- const d = Number(yyyymmdd.slice(6, 8));
1478
- if (y < 1900 || y > 2100) return false;
1479
- const date = new Date(y, m - 1, d);
1480
- return date.getFullYear() === y && date.getMonth() === m - 1 && date.getDate() === d;
1481
- };
1482
- if (/^\d{17}[\dXx]$/.test(v)) {
1483
- const birth = v.slice(6, 14);
1484
- if (!isValidDate(birth)) return false;
1485
- const weights = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
1486
- const checkMap = ["1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"];
1487
- let sum = 0;
1488
- for (let i = 0; i < 17; i++) sum += Number(v[i]) * weights[i];
1489
- const mod = sum % 11;
1490
- const code18 = v[17].toUpperCase();
1491
- return checkMap[mod] === code18;
1492
- }
1493
- if (/^\d{15}$/.test(v)) {
1494
- const birth = v.slice(6, 12);
1495
- const y = Number(`19${birth.slice(0, 2)}`);
1496
- const m = Number(birth.slice(2, 4));
1497
- const d = Number(birth.slice(4, 6));
1498
- const date = new Date(y, m - 1, d);
1499
- return date.getFullYear() === y && date.getMonth() === m - 1 && date.getDate() === d;
1500
- }
1501
- if (/^[A-Za-z][12]\d{8}$/.test(v)) return true;
1502
- if (/^[A-Za-z]{1,2}\d{6}\(?[0-9A]\)?$/.test(v)) return true;
1503
- if (/^[157]\d{6}\(?\d\)?$/.test(v)) return true;
1504
- return false;
1505
- }
1506
- function isPassport(s) {
1507
- const t = String(s ?? "").replace(/[-\s]/g, "").trim();
1508
- if (t === "") return false;
1509
- if (/^[EG]\d{8}$/.test(t)) return true;
1510
- if (/^[DPS]\d{7}$/.test(t)) return true;
1511
- if (/^[A-Za-z]\d{8}$/.test(t)) return true;
1512
- if (/^[A-Za-z0-9]{6,9}$/.test(t)) return true;
1513
- return false;
1514
- }
1515
- function isHKMOPermit(s) {
1516
- const t = String(s ?? "").replace(/[-\s]/g, "").trim().toUpperCase();
1517
- return /^[HM]\d{8,10}$/.test(t);
1518
- }
1519
- function isTaiwanPermit(s) {
1520
- const t = String(s ?? "").replace(/[-\s]/g, "").trim().toUpperCase();
1521
- if (/^\d{8}$/.test(t)) return true;
1522
- if (/^[A-Z]\d{8}$/.test(t)) return true;
1523
- if (/^\d{10}$/.test(t)) return true;
1524
- return false;
1525
- }
1526
- function isOfficerId(s) {
1527
- const t = String(s ?? "").replace(/[-\s]/g, "").trim().toUpperCase();
1528
- return /^[A-Z0-9]{7,18}$/.test(t);
1529
- }
1530
- function isSoldierId(s) {
1531
- const t = String(s ?? "").replace(/[-\s]/g, "").trim().toUpperCase();
1532
- return /^[A-Z0-9]{7,18}$/.test(t);
1533
- }
1534
- function isMilitaryId(s) {
1535
- return isOfficerId(s) || isSoldierId(s);
1536
- }
1537
- function isBankCard(s) {
1538
- const t = String(s ?? "").replace(/[-\s]/g, "").trim();
1539
- if (!/^\d{12,19}$/.test(t)) return false;
1540
- let sum = 0;
1541
- let shouldDouble = false;
1542
- for (let i = t.length - 1; i >= 0; i--) {
1543
- let digit = Number(t[i]);
1544
- if (shouldDouble) {
1545
- digit *= 2;
1546
- if (digit > 9) digit -= 9;
1547
- }
1548
- sum += digit;
1549
- shouldDouble = !shouldDouble;
1550
- }
1551
- return sum % 10 === 0;
1552
- }
1553
- function isLicensePlate(s) {
1554
- const v = String(s ?? "").trim().toUpperCase();
1555
- 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";
1556
- 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]$`);
1557
- const ne1 = new RegExp(`^[${prov}][A-HJ-NP-Z][DF][A-HJ-NP-Z0-9]{5}$`);
1558
- const ne2 = new RegExp(`^[${prov}][A-HJ-NP-Z][A-HJ-NP-Z0-9]{5}[DF]$`);
1559
- return std.test(v) || ne1.test(v) || ne2.test(v);
1560
- }
1561
- function isTaxID(code) {
1562
- const v = String(code ?? "").trim();
1563
- if (!/^[0-9A-HJ-NPQRTUWXY]{18}$/.test(v)) return false;
1564
- const charset = "0123456789ABCDEFGHJKLMNPQRTUWXY";
1565
- const weights = [1, 3, 9, 27, 19, 26, 16, 17, 20, 29, 25, 13, 8, 24, 10, 30, 28];
1566
- const map = {};
1567
- for (let i = 0; i < charset.length; i++) map[charset[i]] = i;
1568
- let sum = 0;
1569
- for (let i = 0; i < 17; i++) {
1570
- sum += map[v[i]] * weights[i];
1571
- }
1572
- const logicCheck = (31 - sum % 31) % 31;
1573
- const expected = charset[logicCheck];
1574
- return v[17] === expected;
1575
- }
1576
- function isJSON(input) {
1577
- if (typeof input === "string") {
1578
- const s = input.trim();
1579
- if (s === "") return false;
1580
- try {
1581
- JSON.parse(s);
1582
- return true;
1583
- } catch {
1584
- return false;
1585
- }
1586
- }
1587
- if (input !== null && typeof input === "object") return true;
1588
- return false;
1589
- }
1590
- function isHexColor(s) {
1591
- const v = String(s ?? "").trim();
1592
- return /^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/.test(v);
1593
- }
1594
- function isURL(s) {
1595
- const v = String(s ?? "").trim();
1596
- if (v === "") return false;
1597
- try {
1598
- const u = new URL(v);
1599
- return ["http:", "https:", "ftp:"].includes(u.protocol) && !!u.hostname;
1600
- } catch {
1601
- return false;
1602
- }
1603
- }
1604
- function isIPv4(s) {
1605
- const v = String(s ?? "").trim();
1606
- if (v === "") return false;
1607
- const parts = v.split(".");
1608
- if (parts.length !== 4) return false;
1609
- for (const p of parts) {
1610
- if (!/^\d+$/.test(p)) return false;
1611
- if (p.length > 1 && p.startsWith("0")) return false;
1612
- const n = Number(p);
1613
- if (n < 0 || n > 255) return false;
1614
- }
1615
- return true;
1616
- }
1617
- function isIPv6(s) {
1618
- const v = String(s ?? "").trim();
1619
- if (v === "") return false;
1620
- const lastColon = v.lastIndexOf(":");
1621
- if (lastColon !== -1 && v.includes(".")) {
1622
- const ipv6Part = v.slice(0, lastColon);
1623
- const ipv4Part = v.slice(lastColon + 1);
1624
- return isIPv6(ipv6Part) && isIPv4(ipv4Part);
1625
- }
1626
- const dblColonCount = (v.match(/::/g) || []).length;
1627
- if (dblColonCount > 1) return false;
1628
- const segments = v.split(":");
1629
- if (v.startsWith("::")) segments.shift();
1630
- if (v.endsWith("::")) segments.pop();
1631
- const segmentsFiltered = segments.filter((seg) => seg !== "");
1632
- if (dblColonCount === 0 && segmentsFiltered.length !== 8) return false;
1633
- if (dblColonCount === 1 && segmentsFiltered.length >= 1 && segmentsFiltered.length <= 7) {
1634
- } else if (dblColonCount === 1 && segments.length === 0) {
1635
- return true;
1636
- } else if (dblColonCount === 0 && segmentsFiltered.length === 8) {
1637
- } else {
1638
- return false;
1639
- }
1640
- return segmentsFiltered.every(
1641
- (seg) => seg.length >= 1 && seg.length <= 4 && /^[0-9a-fA-F]{1,4}$/.test(seg)
1642
- );
1643
- }
1644
- function isIP(s, version) {
1645
- if (version === 4 || version === "4") return isIPv4(s);
1646
- if (version === 6 || version === "6") return isIPv6(s);
1647
- return isIPv4(s) || isIPv6(s);
1648
- }
1649
- function isIPRange(s) {
1650
- const v = String(s ?? "").trim();
1651
- if (v === "") return false;
1652
- const parts = v.split("/");
1653
- if (parts.length !== 2) return false;
1654
- const [ip, prefixStr] = parts;
1655
- if (!/^\d+$/.test(prefixStr)) return false;
1656
- const prefix = Number(prefixStr);
1657
- if (ip.includes(":")) {
1658
- if (!isIPv6(ip)) return false;
1659
- return prefix >= 0 && prefix <= 128;
1660
- }
1661
- if (!isIPv4(ip)) return false;
1662
- return prefix >= 0 && prefix <= 32;
1663
- }
1664
- function isPortNumber(s) {
1665
- const v = typeof s === "number" ? s : Number(String(s ?? "").trim());
1666
- return Number.isInteger(v) && v >= 0 && v <= 65535;
1667
- }
1668
- function isLatitude(s) {
1669
- const v = typeof s === "number" ? s : Number(String(s ?? "").trim());
1670
- return Number.isFinite(v) && v >= -90 && v <= 90;
1671
- }
1672
- function isLongitude(s) {
1673
- const v = typeof s === "number" ? s : Number(String(s ?? "").trim());
1674
- return Number.isFinite(v) && v >= -180 && v <= 180;
1675
- }
1676
-
1677
- // src/web/url/index.ts
1678
- function getUrlQuery(key, url = window.location.href) {
1679
- return getUrlParam(key, url);
1680
- }
1681
- function getUrlQueryNumber(key, url = window.location.href) {
1682
- return getUrlNumber(key, url);
1683
- }
1684
- function getUrlQueryAll(url = window.location.href) {
1685
- return getUrlParamAll(url);
1686
- }
1687
611
  // Annotate the CommonJS export names for ESM import in node:
1688
612
  0 && (module.exports = {
1689
613
  copyBlob,
@@ -1703,9 +627,9 @@ function getUrlQueryAll(url = window.location.href) {
1703
627
  getLocalStorage,
1704
628
  getOS,
1705
629
  getUA,
1706
- getUrlQuery,
1707
- getUrlQueryAll,
1708
- getUrlQueryNumber,
630
+ getUrlNumber,
631
+ getUrlParam,
632
+ getUrlParams,
1709
633
  getWindowHeight,
1710
634
  getWindowScrollLeft,
1711
635
  getWindowScrollTop,