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

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