@alibarbar/common 1.0.9 → 1.1.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/{chunk-O3O67R4I.js → algorithm.cjs} +1 -3
- package/dist/algorithm.js +130 -44
- package/dist/{chunk-LOAZSPGQ.js → array.cjs} +1 -3
- package/dist/array.js +135 -84
- package/dist/{chunk-Y364QIQH.js → color.cjs} +1 -3
- package/dist/color.js +127 -40
- package/dist/{chunk-DYBSRI7V.js → crypto.cjs} +109 -3
- package/dist/crypto.d.mts +48 -1
- package/dist/crypto.d.ts +48 -1
- package/dist/crypto.js +274 -60
- package/dist/{chunk-BHCRFURU.js → data-structure.cjs} +1 -3
- package/dist/data-structure.js +481 -32
- package/dist/{chunk-I3L42475.js → date.cjs} +1 -3
- package/dist/date.js +125 -72
- package/dist/{chunk-JK2SE3I2.js → dom.cjs} +1 -3
- package/dist/dom.js +84 -56
- package/dist/{chunk-7V5UQXIO.js → file.cjs} +1 -3
- package/dist/file.js +79 -32
- package/dist/{chunk-OX5PLOWB.js → i18n.cjs} +1 -3
- package/dist/i18n.js +78 -40
- package/dist/index.cjs +4543 -0
- package/dist/index.d.mts +6 -162
- package/dist/index.d.ts +6 -162
- package/dist/index.js +3712 -17374
- package/dist/{chunk-4RGXV4SJ.js → network.cjs} +1 -3
- package/dist/network.js +97 -28
- package/dist/{chunk-3FRYJPHG.js → number.cjs} +1 -3
- package/dist/number.js +77 -56
- package/dist/{chunk-27UDDVLZ.js → object.cjs} +1 -3
- package/dist/object.js +237 -80
- package/dist/{chunk-JQZBPAPO.js → performance.cjs} +1 -3
- package/dist/performance.js +145 -40
- package/dist/services.cjs +291 -0
- package/dist/services.d.mts +161 -0
- package/dist/services.d.ts +161 -0
- package/dist/services.js +281 -0
- package/dist/storage.cjs +943 -0
- package/dist/storage.d.mts +46 -1
- package/dist/storage.d.ts +46 -1
- package/dist/storage.js +930 -32
- package/dist/{chunk-D7CS5EKF.js → string.cjs} +1 -3
- package/dist/string.js +91 -68
- package/dist/{chunk-56W6YECK.js → tracking.cjs} +1 -3
- package/dist/tracking.js +359 -52
- package/dist/{chunk-ZDMFMUDR.js → transform.cjs} +1 -3
- package/dist/transform.js +299 -32
- package/dist/{chunk-NJARVI6X.mjs → upload.cjs} +42 -15
- package/dist/upload.d.mts +1 -1
- package/dist/upload.d.ts +1 -1
- package/dist/upload.js +402 -20
- package/dist/{chunk-KGFTD255.js → url.cjs} +1 -3
- package/dist/url.js +91 -44
- package/dist/{chunk-TQN37HIN.js → validation.cjs} +1 -3
- package/dist/validation.js +77 -60
- package/package.json +7 -2
- package/dist/algorithm.js.map +0 -1
- package/dist/algorithm.mjs +0 -4
- package/dist/algorithm.mjs.map +0 -1
- package/dist/array.js.map +0 -1
- package/dist/array.mjs +0 -4
- package/dist/array.mjs.map +0 -1
- package/dist/chunk-27UDDVLZ.js.map +0 -1
- package/dist/chunk-2R2QWFJC.mjs +0 -138
- package/dist/chunk-2R2QWFJC.mjs.map +0 -1
- package/dist/chunk-3FRYJPHG.js.map +0 -1
- package/dist/chunk-4RGXV4SJ.js.map +0 -1
- package/dist/chunk-56W6YECK.js.map +0 -1
- package/dist/chunk-5BGSUGTI.mjs +0 -128
- package/dist/chunk-5BGSUGTI.mjs.map +0 -1
- package/dist/chunk-7E6GELHJ.mjs +0 -302
- package/dist/chunk-7E6GELHJ.mjs.map +0 -1
- package/dist/chunk-7V5UQXIO.js.map +0 -1
- package/dist/chunk-A4SWQXX7.mjs +0 -484
- package/dist/chunk-A4SWQXX7.mjs.map +0 -1
- package/dist/chunk-BHCRFURU.js.map +0 -1
- package/dist/chunk-CDSGEAOK.mjs +0 -80
- package/dist/chunk-CDSGEAOK.mjs.map +0 -1
- package/dist/chunk-D7CS5EKF.js.map +0 -1
- package/dist/chunk-DYBSRI7V.js.map +0 -1
- package/dist/chunk-FEBKPX5A.js +0 -386
- package/dist/chunk-FEBKPX5A.js.map +0 -1
- package/dist/chunk-FJ6ZGZIA.mjs +0 -39
- package/dist/chunk-FJ6ZGZIA.mjs.map +0 -1
- package/dist/chunk-HLDFI7R2.mjs +0 -175
- package/dist/chunk-HLDFI7R2.mjs.map +0 -1
- package/dist/chunk-I3L42475.js.map +0 -1
- package/dist/chunk-JBLX27WD.mjs +0 -240
- package/dist/chunk-JBLX27WD.mjs.map +0 -1
- package/dist/chunk-JHZ7M2MR.mjs +0 -133
- package/dist/chunk-JHZ7M2MR.mjs.map +0 -1
- package/dist/chunk-JK2SE3I2.js.map +0 -1
- package/dist/chunk-JQZBPAPO.js.map +0 -1
- package/dist/chunk-JXYGC2C5.mjs +0 -100
- package/dist/chunk-JXYGC2C5.mjs.map +0 -1
- package/dist/chunk-KGFTD255.js.map +0 -1
- package/dist/chunk-LBHBNPNJ.mjs +0 -148
- package/dist/chunk-LBHBNPNJ.mjs.map +0 -1
- package/dist/chunk-LF4CILQS.mjs +0 -87
- package/dist/chunk-LF4CILQS.mjs.map +0 -1
- package/dist/chunk-LOAZSPGQ.js.map +0 -1
- package/dist/chunk-NJARVI6X.mjs.map +0 -1
- package/dist/chunk-NSSDYX2U.mjs +0 -80
- package/dist/chunk-NSSDYX2U.mjs.map +0 -1
- package/dist/chunk-O3O67R4I.js.map +0 -1
- package/dist/chunk-OIXQ3E6W.mjs +0 -354
- package/dist/chunk-OIXQ3E6W.mjs.map +0 -1
- package/dist/chunk-OX5PLOWB.js.map +0 -1
- package/dist/chunk-PJ7UCTX4.mjs +0 -362
- package/dist/chunk-PJ7UCTX4.mjs.map +0 -1
- package/dist/chunk-PR4QN5HX.js +0 -44
- package/dist/chunk-PR4QN5HX.js.map +0 -1
- package/dist/chunk-QIBE7GVN.mjs +0 -81
- package/dist/chunk-QIBE7GVN.mjs.map +0 -1
- package/dist/chunk-QIOC54LQ.mjs +0 -130
- package/dist/chunk-QIOC54LQ.mjs.map +0 -1
- package/dist/chunk-TQN37HIN.js.map +0 -1
- package/dist/chunk-WZDOPUJW.js +0 -361
- package/dist/chunk-WZDOPUJW.js.map +0 -1
- package/dist/chunk-XJTZDXSR.mjs +0 -94
- package/dist/chunk-XJTZDXSR.mjs.map +0 -1
- package/dist/chunk-Y364QIQH.js.map +0 -1
- package/dist/chunk-YXM6Q4JS.mjs +0 -94
- package/dist/chunk-YXM6Q4JS.mjs.map +0 -1
- package/dist/chunk-ZDMFMUDR.js.map +0 -1
- package/dist/chunk-ZVJ6NQUM.mjs +0 -82
- package/dist/chunk-ZVJ6NQUM.mjs.map +0 -1
- package/dist/color.js.map +0 -1
- package/dist/color.mjs +0 -4
- package/dist/color.mjs.map +0 -1
- package/dist/crypto.js.map +0 -1
- package/dist/crypto.mjs +0 -4
- package/dist/crypto.mjs.map +0 -1
- package/dist/data-structure.js.map +0 -1
- package/dist/data-structure.mjs +0 -4
- package/dist/data-structure.mjs.map +0 -1
- package/dist/date.js.map +0 -1
- package/dist/date.mjs +0 -4
- package/dist/date.mjs.map +0 -1
- package/dist/dom.js.map +0 -1
- package/dist/dom.mjs +0 -4
- package/dist/dom.mjs.map +0 -1
- package/dist/file.js.map +0 -1
- package/dist/file.mjs +0 -4
- package/dist/file.mjs.map +0 -1
- package/dist/i18n.js.map +0 -1
- package/dist/i18n.mjs +0 -4
- package/dist/i18n.mjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/index.mjs +0 -17155
- package/dist/index.mjs.map +0 -1
- package/dist/network.js.map +0 -1
- package/dist/network.mjs +0 -4
- package/dist/network.mjs.map +0 -1
- package/dist/number.js.map +0 -1
- package/dist/number.mjs +0 -4
- package/dist/number.mjs.map +0 -1
- package/dist/object.js.map +0 -1
- package/dist/object.mjs +0 -4
- package/dist/object.mjs.map +0 -1
- package/dist/performance.js.map +0 -1
- package/dist/performance.mjs +0 -4
- package/dist/performance.mjs.map +0 -1
- package/dist/storage.js.map +0 -1
- package/dist/storage.mjs +0 -5
- package/dist/storage.mjs.map +0 -1
- package/dist/string.js.map +0 -1
- package/dist/string.mjs +0 -4
- package/dist/string.mjs.map +0 -1
- package/dist/tracking.js.map +0 -1
- package/dist/tracking.mjs +0 -4
- package/dist/tracking.mjs.map +0 -1
- package/dist/transform.js.map +0 -1
- package/dist/transform.mjs +0 -4
- package/dist/transform.mjs.map +0 -1
- package/dist/upload.js.map +0 -1
- package/dist/upload.mjs +0 -5
- package/dist/upload.mjs.map +0 -1
- package/dist/url.js.map +0 -1
- package/dist/url.mjs +0 -4
- package/dist/url.mjs.map +0 -1
- package/dist/validation.js.map +0 -1
- package/dist/validation.mjs +0 -4
- package/dist/validation.mjs.map +0 -1
- /package/dist/{upload-DchqyDBQ.d.mts → index-DchqyDBQ.d.mts} +0 -0
- /package/dist/{upload-DchqyDBQ.d.ts → index-DchqyDBQ.d.ts} +0 -0
package/dist/chunk-QIOC54LQ.mjs
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
// src/format/color.ts
|
|
2
|
-
function hexToRgb(hex) {
|
|
3
|
-
const cleanHex = hex.replace("#", "");
|
|
4
|
-
if (!/^[0-9A-Fa-f]{6}$/.test(cleanHex)) {
|
|
5
|
-
throw new Error("Invalid hex color format");
|
|
6
|
-
}
|
|
7
|
-
return {
|
|
8
|
-
r: parseInt(cleanHex.substring(0, 2), 16),
|
|
9
|
-
g: parseInt(cleanHex.substring(2, 4), 16),
|
|
10
|
-
b: parseInt(cleanHex.substring(4, 6), 16)
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
function rgbToHex(rgb) {
|
|
14
|
-
let r;
|
|
15
|
-
let g;
|
|
16
|
-
let b;
|
|
17
|
-
if (typeof rgb === "string") {
|
|
18
|
-
const match = rgb.match(/rgb\((\d+),\s*(\d+),\s*(\d+)\)/);
|
|
19
|
-
if (!match) {
|
|
20
|
-
throw new Error("Invalid RGB string format");
|
|
21
|
-
}
|
|
22
|
-
r = parseInt(match[1], 10);
|
|
23
|
-
g = parseInt(match[2], 10);
|
|
24
|
-
b = parseInt(match[3], 10);
|
|
25
|
-
} else {
|
|
26
|
-
r = rgb.r;
|
|
27
|
-
g = rgb.g;
|
|
28
|
-
b = rgb.b;
|
|
29
|
-
}
|
|
30
|
-
r = Math.max(0, Math.min(255, Math.round(r)));
|
|
31
|
-
g = Math.max(0, Math.min(255, Math.round(g)));
|
|
32
|
-
b = Math.max(0, Math.min(255, Math.round(b)));
|
|
33
|
-
return `#${r.toString(16).padStart(2, "0")}${g.toString(16).padStart(2, "0")}${b.toString(16).padStart(2, "0")}`.toUpperCase();
|
|
34
|
-
}
|
|
35
|
-
function rgbToHsl(rgb) {
|
|
36
|
-
const r = rgb.r / 255;
|
|
37
|
-
const g = rgb.g / 255;
|
|
38
|
-
const b = rgb.b / 255;
|
|
39
|
-
const max = Math.max(r, g, b);
|
|
40
|
-
const min = Math.min(r, g, b);
|
|
41
|
-
const delta = max - min;
|
|
42
|
-
let h = 0;
|
|
43
|
-
let s = 0;
|
|
44
|
-
const l = (max + min) / 2;
|
|
45
|
-
if (delta !== 0) {
|
|
46
|
-
s = l > 0.5 ? delta / (2 - max - min) : delta / (max + min);
|
|
47
|
-
if (max === r) {
|
|
48
|
-
h = ((g - b) / delta + (g < b ? 6 : 0)) / 6;
|
|
49
|
-
} else if (max === g) {
|
|
50
|
-
h = ((b - r) / delta + 2) / 6;
|
|
51
|
-
} else {
|
|
52
|
-
h = ((r - g) / delta + 4) / 6;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return {
|
|
56
|
-
h: Math.round(h * 360),
|
|
57
|
-
s: Math.round(s * 100),
|
|
58
|
-
l: Math.round(l * 100)
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
function hslToRgb(hsl) {
|
|
62
|
-
const h = hsl.h / 360;
|
|
63
|
-
const s = hsl.s / 100;
|
|
64
|
-
const l = hsl.l / 100;
|
|
65
|
-
let r;
|
|
66
|
-
let g;
|
|
67
|
-
let b;
|
|
68
|
-
if (s === 0) {
|
|
69
|
-
r = g = b = l;
|
|
70
|
-
} else {
|
|
71
|
-
const hue2rgb = (p2, q2, t) => {
|
|
72
|
-
if (t < 0) t += 1;
|
|
73
|
-
if (t > 1) t -= 1;
|
|
74
|
-
if (t < 1 / 6) return p2 + (q2 - p2) * 6 * t;
|
|
75
|
-
if (t < 1 / 2) return q2;
|
|
76
|
-
if (t < 2 / 3) return p2 + (q2 - p2) * (2 / 3 - t) * 6;
|
|
77
|
-
return p2;
|
|
78
|
-
};
|
|
79
|
-
const q = l < 0.5 ? l * (1 + s) : l + s - l * s;
|
|
80
|
-
const p = 2 * l - q;
|
|
81
|
-
r = hue2rgb(p, q, h + 1 / 3);
|
|
82
|
-
g = hue2rgb(p, q, h);
|
|
83
|
-
b = hue2rgb(p, q, h - 1 / 3);
|
|
84
|
-
}
|
|
85
|
-
return {
|
|
86
|
-
r: Math.round(r * 255),
|
|
87
|
-
g: Math.round(g * 255),
|
|
88
|
-
b: Math.round(b * 255)
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
function lighten(color, amount) {
|
|
92
|
-
const rgb = typeof color === "string" ? hexToRgb(color) : color;
|
|
93
|
-
const hsl = rgbToHsl(rgb);
|
|
94
|
-
hsl.l = Math.min(100, hsl.l + amount);
|
|
95
|
-
return rgbToHex(hslToRgb(hsl));
|
|
96
|
-
}
|
|
97
|
-
function darken(color, amount) {
|
|
98
|
-
const rgb = typeof color === "string" ? hexToRgb(color) : color;
|
|
99
|
-
const hsl = rgbToHsl(rgb);
|
|
100
|
-
hsl.l = Math.max(0, hsl.l - amount);
|
|
101
|
-
return rgbToHex(hslToRgb(hsl));
|
|
102
|
-
}
|
|
103
|
-
function mix(color1, color2, ratio) {
|
|
104
|
-
const rgb1 = hexToRgb(color1);
|
|
105
|
-
const rgb2 = hexToRgb(color2);
|
|
106
|
-
const r = Math.round(rgb1.r * (1 - ratio) + rgb2.r * ratio);
|
|
107
|
-
const g = Math.round(rgb1.g * (1 - ratio) + rgb2.g * ratio);
|
|
108
|
-
const b = Math.round(rgb1.b * (1 - ratio) + rgb2.b * ratio);
|
|
109
|
-
return rgbToHex({ r, g, b });
|
|
110
|
-
}
|
|
111
|
-
function contrast(color1, color2) {
|
|
112
|
-
const rgb1 = hexToRgb(color1);
|
|
113
|
-
const rgb2 = hexToRgb(color2);
|
|
114
|
-
const getLuminance = (rgb) => {
|
|
115
|
-
const normalize = (value) => {
|
|
116
|
-
value = value / 255;
|
|
117
|
-
return value <= 0.03928 ? value / 12.92 : Math.pow((value + 0.055) / 1.055, 2.4);
|
|
118
|
-
};
|
|
119
|
-
return 0.2126 * normalize(rgb.r) + 0.7152 * normalize(rgb.g) + 0.0722 * normalize(rgb.b);
|
|
120
|
-
};
|
|
121
|
-
const lum1 = getLuminance(rgb1);
|
|
122
|
-
const lum2 = getLuminance(rgb2);
|
|
123
|
-
const lighter = Math.max(lum1, lum2);
|
|
124
|
-
const darker = Math.min(lum1, lum2);
|
|
125
|
-
return (lighter + 0.05) / (darker + 0.05);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
export { contrast, darken, hexToRgb, hslToRgb, lighten, mix, rgbToHex, rgbToHsl };
|
|
129
|
-
//# sourceMappingURL=chunk-QIOC54LQ.mjs.map
|
|
130
|
-
//# sourceMappingURL=chunk-QIOC54LQ.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/format/color.ts"],"names":["p","q"],"mappings":";AA2BO,SAAS,SAAS,GAAA,EAAkB;AAEzC,EAAA,MAAM,QAAA,GAAW,GAAA,CAAI,OAAA,CAAQ,GAAA,EAAK,EAAE,CAAA;AAGpC,EAAA,IAAI,CAAC,kBAAA,CAAmB,IAAA,CAAK,QAAQ,CAAA,EAAG;AACtC,IAAA,MAAM,IAAI,MAAM,0BAA0B,CAAA;AAAA,EAC5C;AAEA,EAAA,OAAO;AAAA,IACL,GAAG,QAAA,CAAS,QAAA,CAAS,UAAU,CAAA,EAAG,CAAC,GAAG,EAAE,CAAA;AAAA,IACxC,GAAG,QAAA,CAAS,QAAA,CAAS,UAAU,CAAA,EAAG,CAAC,G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AA,GAAQ,GAAA;AAChB,MAAA,OAAO,KAAA,IAAS,UAAU,KAAA,GAAQ,KAAA,GAAQ,KAAK,GAAA,CAAA,CAAK,KAAA,GAAQ,KAAA,IAAS,KAAA,EAAO,GAAG,CAAA;AAAA,IACjF,CAAA;AAEA,IAAA,OAAO,MAAA,GAAS,SAAA,CAAU,GAAA,CAAI,CAAC,CAAA,GAAI,MAAA,GAAS,SAAA,CAAU,GAAA,CAAI,CAAC,CAAA,GAAI,MAAA,GAAS,SAAA,CAAU,IAAI,CAAC,CAAA;AAAA,EACzF,CAAA;AAEA,EAAA,MAAM,IAAA,GAAO,aAAa,IAAI,CAAA;AAC9B,EAAA,MAAM,IAAA,GAAO,aAAa,IAAI,CAAA;AAE9B,EAAA,MAAM,OAAA,GAAU,IAAA,CAAK,GAAA,CAAI,IAAA,EAAM,IAAI,CAAA;AACnC,EAAA,MAAM,MAAA,GAAS,IAAA,CAAK,GAAA,CAAI,IAAA,EAAM,IAAI,CAAA;AAElC,EAAA,OAAA,CAAQ,OAAA,GAAU,SAAS,MAAA,GAAS,IAAA,CAAA;AACtC","file":"chunk-QIOC54LQ.mjs","sourcesContent":["/**\n * 颜色工具函数\n */\n\n/**\n * RGB颜色类型\n */\nexport interface RGB {\n r: number;\n g: number;\n b: number;\n}\n\n/**\n * HSL颜色类型\n */\nexport interface HSL {\n h: number; // 色相 (0-360)\n s: number; // 饱和度 (0-100)\n l: number; // 亮度 (0-100)\n}\n\n/**\n * 十六进制转RGB\n * @param hex - 十六进制颜色值(如 '#FF0000' 或 'FF0000')\n * @returns RGB对象\n */\nexport function hexToRgb(hex: string): RGB {\n // 移除 # 号\n const cleanHex = hex.replace('#', '');\n\n // 验证格式\n if (!/^[0-9A-Fa-f]{6}$/.test(cleanHex)) {\n throw new Error('Invalid hex color format');\n }\n\n return {\n r: parseInt(cleanHex.substring(0, 2), 16),\n g: parseInt(cleanHex.substring(2, 4), 16),\n b: parseInt(cleanHex.substring(4, 6), 16),\n };\n}\n\n/**\n * RGB转十六进制\n * @param rgb - RGB对象或字符串(如 'rgb(255, 0, 0)')\n * @returns 十六进制颜色值(如 '#FF0000')\n */\nexport function rgbToHex(rgb: RGB | string): string {\n let r: number;\n let g: number;\n let b: number;\n\n if (typeof rgb === 'string') {\n const match = rgb.match(/rgb\\((\\d+),\\s*(\\d+),\\s*(\\d+)\\)/);\n if (!match) {\n throw new Error('Invalid RGB string format');\n }\n r = parseInt(match[1], 10);\n g = parseInt(match[2], 10);\n b = parseInt(match[3], 10);\n } else {\n r = rgb.r;\n g = rgb.g;\n b = rgb.b;\n }\n\n // 确保值在有效范围内\n r = Math.max(0, Math.min(255, Math.round(r)));\n g = Math.max(0, Math.min(255, Math.round(g)));\n b = Math.max(0, Math.min(255, Math.round(b)));\n\n return `#${r.toString(16).padStart(2, '0')}${g.toString(16).padStart(2, '0')}${b.toString(16).padStart(2, '0')}`.toUpperCase();\n}\n\n/**\n * RGB转HSL\n * @param rgb - RGB对象\n * @returns HSL对象\n */\nexport function rgbToHsl(rgb: RGB): HSL {\n const r = rgb.r / 255;\n const g = rgb.g / 255;\n const b = rgb.b / 255;\n\n const max = Math.max(r, g, b);\n const min = Math.min(r, g, b);\n const delta = max - min;\n\n let h = 0;\n let s = 0;\n const l = (max + min) / 2;\n\n if (delta !== 0) {\n s = l > 0.5 ? delta / (2 - max - min) : delta / (max + min);\n\n if (max === r) {\n h = ((g - b) / delta + (g < b ? 6 : 0)) / 6;\n } else if (max === g) {\n h = ((b - r) / delta + 2) / 6;\n } else {\n h = ((r - g) / delta + 4) / 6;\n }\n }\n\n return {\n h: Math.round(h * 360),\n s: Math.round(s * 100),\n l: Math.round(l * 100),\n };\n}\n\n/**\n * HSL转RGB\n * @param hsl - HSL对象\n * @returns RGB对象\n */\nexport function hslToRgb(hsl: HSL): RGB {\n const h = hsl.h / 360;\n const s = hsl.s / 100;\n const l = hsl.l / 100;\n\n let r: number;\n let g: number;\n let b: number;\n\n if (s === 0) {\n r = g = b = l; // 无色彩\n } else {\n const hue2rgb = (p: number, q: number, t: number): number => {\n if (t < 0) t += 1;\n if (t > 1) t -= 1;\n if (t < 1 / 6) return p + (q - p) * 6 * t;\n if (t < 1 / 2) return q;\n if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;\n return p;\n };\n\n const q = l < 0.5 ? l * (1 + s) : l + s - l * s;\n const p = 2 * l - q;\n\n r = hue2rgb(p, q, h + 1 / 3);\n g = hue2rgb(p, q, h);\n b = hue2rgb(p, q, h - 1 / 3);\n }\n\n return {\n r: Math.round(r * 255),\n g: Math.round(g * 255),\n b: Math.round(b * 255),\n };\n}\n\n/**\n * 颜色变亮\n * @param color - 十六进制颜色值或RGB对象\n * @param amount - 变亮程度(0-100)\n * @returns 新的十六进制颜色值\n */\nexport function lighten(color: string | RGB, amount: number): string {\n const rgb = typeof color === 'string' ? hexToRgb(color) : color;\n const hsl = rgbToHsl(rgb);\n\n hsl.l = Math.min(100, hsl.l + amount);\n\n return rgbToHex(hslToRgb(hsl));\n}\n\n/**\n * 颜色变暗\n * @param color - 十六进制颜色值或RGB对象\n * @param amount - 变暗程度(0-100)\n * @returns 新的十六进制颜色值\n */\nexport function darken(color: string | RGB, amount: number): string {\n const rgb = typeof color === 'string' ? hexToRgb(color) : color;\n const hsl = rgbToHsl(rgb);\n\n hsl.l = Math.max(0, hsl.l - amount);\n\n return rgbToHex(hslToRgb(hsl));\n}\n\n/**\n * 颜色混合\n * @param color1 - 第一个颜色(十六进制)\n * @param color2 - 第二个颜色(十六进制)\n * @param ratio - 混合比例(0-1),0表示完全使用color1,1表示完全使用color2\n * @returns 混合后的十六进制颜色值\n */\nexport function mix(color1: string, color2: string, ratio: number): string {\n const rgb1 = hexToRgb(color1);\n const rgb2 = hexToRgb(color2);\n\n const r = Math.round(rgb1.r * (1 - ratio) + rgb2.r * ratio);\n const g = Math.round(rgb1.g * (1 - ratio) + rgb2.g * ratio);\n const b = Math.round(rgb1.b * (1 - ratio) + rgb2.b * ratio);\n\n return rgbToHex({ r, g, b });\n}\n\n/**\n * 计算颜色对比度(WCAG标准)\n * @param color1 - 第一个颜色(十六进制)\n * @param color2 - 第二个颜色(十六进制)\n * @returns 对比度比值(1-21,4.5以上为可接受对比度)\n */\nexport function contrast(color1: string, color2: string): number {\n const rgb1 = hexToRgb(color1);\n const rgb2 = hexToRgb(color2);\n\n // 计算相对亮度\n const getLuminance = (rgb: RGB): number => {\n const normalize = (value: number): number => {\n value = value / 255;\n return value <= 0.03928 ? value / 12.92 : Math.pow((value + 0.055) / 1.055, 2.4);\n };\n\n return 0.2126 * normalize(rgb.r) + 0.7152 * normalize(rgb.g) + 0.0722 * normalize(rgb.b);\n };\n\n const lum1 = getLuminance(rgb1);\n const lum2 = getLuminance(rgb2);\n\n const lighter = Math.max(lum1, lum2);\n const darker = Math.min(lum1, lum2);\n\n return (lighter + 0.05) / (darker + 0.05);\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/core/validation.ts"],"names":[],"mappings":";;;AASO,SAAS,aAAa,KAAA,EAAwB;AACnD,EAAA,MAAM,UAAA,GAAa,4BAAA;AACnB,EAAA,OAAO,UAAA,CAAW,KAAK,KAAK,CAAA;AAC9B;AAOO,SAAS,aAAa,KAAA,EAAwB;AACnD,EAAA,MAAM,UAAA,GAAa,eAAA;AACnB,EAAA,OAAO,UAAA,CAAW,KAAK,KAAK,CAAA;AAC9B;AAOO,SAAS,WAAW,GAAA,EAAsB;AAC/C,EAAA,IAAI;AACF,IAAA,IAAI,IAAI,GAAG,CAAA;AACX,IAAA,OAAO,IAAA;AAAA,EACT,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,KAAA;AAAA,EACT;AACF;AAOO,SAAS,cAAc,MAAA,EAAyB;AACrD,EAAA,MAAM,WAAA,GAAc,4EAAA;AACpB,EAAA,OAAO,WAAA,CAAY,KAAK,MAAM,CAAA;AAChC;AAOO,SAAS,QAAQ,KAAA,EAAyB;AAC/C,EAAA,IAAI,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IAAA,OAAO,KAAA,CAAM,IAAA,EAAK,KAAM,EAAA,IAAM,CAAC,KAAA,CAAM,MAAA,CAAO,KAAK,CAAC,CAAA,IAAK,QAAA,CAAS,MAAA,CAAO,KAAK,CAAC,CAAA;AAAA,EAC/E;AACA,EAAA,OAAO,KAAA;AACT;AAOO,SAAS,UAAU,KAAA,EAAyB;AACjD,EAAA,IAAI,OAAO,KAAA,KAAU,QAAA,EAAU,OAAO,MAAA,CAAO,UAAU,KAAK,CAAA;AAC5D,EAAA,IAAI,OAAO,UAAU,QAAA,EAAU;AAC7B,IAAA,MAAM,GAAA,GAAM,OAAO,KAAK,CAAA;AACxB,IAAA,OAAO,CAAC,KAAA,CAAM,GAAG,CAAA,IAAK,MAAA,CAAO,UAAU,GAAG,CAAA;AAAA,EAC5C;AACA,EAAA,OAAO,KAAA;AACT;AAOO,SAAS,QAAQ,KAAA,EAAyB;AAC/C,EAAA,IAAI,OAAO,KAAA,KAAU,QAAA;AACnB,IAAA,OAAO,CAAC,KAAA,CAAM,KAAK,CAAA,IAAK,QAAA,CAAS,KAAK,CAAA,IAAK,CAAC,MAAA,CAAO,SAAA,CAAU,KAAK,CAAA;AACpE,EAAA,IAAI,OAAO,UAAU,QAAA,EAAU;AAC7B,IAAA,MAAM,GAAA,GAAM,OAAO,KAAK,CAAA;AACxB,IAAA,OAAO,CAAC,KAAA,CAAM,GAAG,CAAA,IAAK,QAAA,CAAS,GAAG,CAAA,IAAK,CAAC,MAAA,CAAO,SAAA,CAAU,GAAG,CAAA;AAAA,EAC9D;AACA,EAAA,OAAO,KAAA;AACT","file":"chunk-TQN37HIN.js","sourcesContent":["/**\n * 验证工具函数\n */\n\n/**\n * 验证邮箱格式\n * @param email - 邮箱地址\n * @returns 是否为有效邮箱\n */\nexport function isValidEmail(email: string): boolean {\n const emailRegex = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/;\n return emailRegex.test(email);\n}\n\n/**\n * 验证手机号格式(中国大陆)\n * @param phone - 手机号\n * @returns 是否为有效手机号\n */\nexport function isValidPhone(phone: string): boolean {\n const phoneRegex = /^1[3-9]\\d{9}$/;\n return phoneRegex.test(phone);\n}\n\n/**\n * 验证URL格式\n * @param url - URL地址\n * @returns 是否为有效URL\n */\nexport function isValidUrl(url: string): boolean {\n try {\n new URL(url);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * 验证身份证号格式(中国大陆18位)\n * @param idCard - 身份证号\n * @returns 是否为有效身份证号\n */\nexport function isValidIdCard(idCard: string): boolean {\n const idCardRegex = /^[1-9]\\d{5}(18|19|20)\\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\\d|3[01])\\d{3}[\\dXx]$/;\n return idCardRegex.test(idCard);\n}\n\n/**\n * 验证是否为空值\n * @param value - 待验证的值\n * @returns 是否为空\n */\nexport function isEmpty(value: unknown): boolean {\n if (value === null || value === undefined) return true;\n if (typeof value === 'string') return value.trim().length === 0;\n if (Array.isArray(value)) return value.length === 0;\n if (typeof value === 'object') return Object.keys(value).length === 0;\n return false;\n}\n\n/**\n * 验证UUID格式\n * @param uuid - UUID字符串\n * @returns 是否为有效UUID\n */\nexport function isValidUUID(uuid: string): boolean {\n const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;\n return uuidRegex.test(uuid);\n}\n\n/**\n * 验证IP地址格式(IPv4)\n * @param ip - IP地址\n * @returns 是否为有效IP地址\n */\nexport function isValidIP(ip: string): boolean {\n const ipRegex =\n /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;\n return ipRegex.test(ip);\n}\n\n/**\n * 验证域名格式\n * @param domain - 域名\n * @returns 是否为有效域名\n */\nexport function isValidDomain(domain: string): boolean {\n const domainRegex = /^([a-z0-9]+(-[a-z0-9]+)*\\.)+[a-z]{2,}$/i;\n return domainRegex.test(domain);\n}\n\n/**\n * 验证十六进制颜色格式\n * @param color - 颜色值\n * @returns 是否为有效十六进制颜色\n */\nexport function isValidHexColor(color: string): boolean {\n const hexColorRegex = /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/;\n return hexColorRegex.test(color);\n}\n\n/**\n * 验证JSON字符串格式\n * @param json - JSON字符串\n * @returns 是否为有效JSON\n */\nexport function isValidJSON(json: string): boolean {\n try {\n JSON.parse(json);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * 验证是否为数字\n * @param value - 待验证的值\n * @returns 是否为数字\n */\nexport function isNumeric(value: unknown): boolean {\n if (typeof value === 'number') return !isNaN(value) && isFinite(value);\n if (typeof value === 'string') {\n return value.trim() !== '' && !isNaN(Number(value)) && isFinite(Number(value));\n }\n return false;\n}\n\n/**\n * 验证是否为整数\n * @param value - 待验证的值\n * @returns 是否为整数\n */\nexport function isInteger(value: unknown): boolean {\n if (typeof value === 'number') return Number.isInteger(value);\n if (typeof value === 'string') {\n const num = Number(value);\n return !isNaN(num) && Number.isInteger(num);\n }\n return false;\n}\n\n/**\n * 验证是否为浮点数\n * @param value - 待验证的值\n * @returns 是否为浮点数\n */\nexport function isFloat(value: unknown): boolean {\n if (typeof value === 'number')\n return !isNaN(value) && isFinite(value) && !Number.isInteger(value);\n if (typeof value === 'string') {\n const num = Number(value);\n return !isNaN(num) && isFinite(num) && !Number.isInteger(num);\n }\n return false;\n}\n"]}
|
package/dist/chunk-WZDOPUJW.js
DELETED
|
@@ -1,361 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var chunkDYBSRI7V_js = require('./chunk-DYBSRI7V.js');
|
|
4
|
-
|
|
5
|
-
// src/browser/storage.ts
|
|
6
|
-
var globalKeyPair = null;
|
|
7
|
-
function setStorageKeyPair(keyPair) {
|
|
8
|
-
globalKeyPair = keyPair;
|
|
9
|
-
}
|
|
10
|
-
function getStorageKeyPair() {
|
|
11
|
-
return globalKeyPair;
|
|
12
|
-
}
|
|
13
|
-
async function encryptValue(value, publicKey) {
|
|
14
|
-
return chunkDYBSRI7V_js.rsaEncrypt(value, publicKey);
|
|
15
|
-
}
|
|
16
|
-
async function decryptValue(encryptedValue, privateKey) {
|
|
17
|
-
try {
|
|
18
|
-
return await chunkDYBSRI7V_js.rsaDecrypt(encryptedValue, privateKey);
|
|
19
|
-
} catch {
|
|
20
|
-
try {
|
|
21
|
-
JSON.parse(encryptedValue);
|
|
22
|
-
return encryptedValue;
|
|
23
|
-
} catch {
|
|
24
|
-
throw new Error("Failed to decrypt storage value");
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
var localStorage = {
|
|
29
|
-
/**
|
|
30
|
-
* 设置值
|
|
31
|
-
* @param key - 键
|
|
32
|
-
* @param value - 值
|
|
33
|
-
* @param options - 选项(过期时间、密钥等)
|
|
34
|
-
* @returns Promise<void>
|
|
35
|
-
*/
|
|
36
|
-
async set(key, value, options = {}) {
|
|
37
|
-
if (typeof window === "undefined" || !window.localStorage) {
|
|
38
|
-
throw new Error("localStorage is not available");
|
|
39
|
-
}
|
|
40
|
-
const { expiry, publicKey } = options;
|
|
41
|
-
const item = {
|
|
42
|
-
value,
|
|
43
|
-
expiry: expiry ? Date.now() + expiry : void 0
|
|
44
|
-
};
|
|
45
|
-
try {
|
|
46
|
-
const jsonStr = JSON.stringify(item);
|
|
47
|
-
const keyToUse = publicKey || globalKeyPair?.publicKey;
|
|
48
|
-
if (keyToUse) {
|
|
49
|
-
const encrypted = await encryptValue(jsonStr, keyToUse);
|
|
50
|
-
window.localStorage.setItem(key, encrypted);
|
|
51
|
-
} else {
|
|
52
|
-
const { base64Encode } = await import('./crypto.js');
|
|
53
|
-
const encoded = base64Encode(jsonStr);
|
|
54
|
-
window.localStorage.setItem(key, encoded);
|
|
55
|
-
}
|
|
56
|
-
} catch (error) {
|
|
57
|
-
console.error("localStorage.set error:", error);
|
|
58
|
-
throw error;
|
|
59
|
-
}
|
|
60
|
-
},
|
|
61
|
-
/**
|
|
62
|
-
* 获取值
|
|
63
|
-
* @param key - 键
|
|
64
|
-
* @param options - 选项(默认值、私钥等)
|
|
65
|
-
* @returns Promise<T | undefined> 值或默认值
|
|
66
|
-
*/
|
|
67
|
-
async get(key, options = {}) {
|
|
68
|
-
if (typeof window === "undefined" || !window.localStorage) {
|
|
69
|
-
return options.defaultValue;
|
|
70
|
-
}
|
|
71
|
-
const { defaultValue, privateKey } = options;
|
|
72
|
-
try {
|
|
73
|
-
const encryptedStr = window.localStorage.getItem(key);
|
|
74
|
-
if (!encryptedStr) return defaultValue;
|
|
75
|
-
let decryptedStr;
|
|
76
|
-
const keyToUse = privateKey || globalKeyPair?.privateKey;
|
|
77
|
-
if (keyToUse) {
|
|
78
|
-
try {
|
|
79
|
-
decryptedStr = await decryptValue(encryptedStr, keyToUse);
|
|
80
|
-
} catch {
|
|
81
|
-
const { base64Decode } = await import('./crypto.js');
|
|
82
|
-
try {
|
|
83
|
-
decryptedStr = base64Decode(encryptedStr);
|
|
84
|
-
} catch {
|
|
85
|
-
return defaultValue;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
} else {
|
|
89
|
-
const { base64Decode } = await import('./crypto.js');
|
|
90
|
-
try {
|
|
91
|
-
decryptedStr = base64Decode(encryptedStr);
|
|
92
|
-
} catch {
|
|
93
|
-
return defaultValue;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
const item = JSON.parse(decryptedStr);
|
|
97
|
-
if (item.expiry && Date.now() > item.expiry) {
|
|
98
|
-
window.localStorage.removeItem(key);
|
|
99
|
-
return defaultValue;
|
|
100
|
-
}
|
|
101
|
-
return item.value;
|
|
102
|
-
} catch {
|
|
103
|
-
return defaultValue;
|
|
104
|
-
}
|
|
105
|
-
},
|
|
106
|
-
/**
|
|
107
|
-
* 移除值
|
|
108
|
-
* @param key - 键
|
|
109
|
-
*/
|
|
110
|
-
remove(key) {
|
|
111
|
-
if (typeof window === "undefined" || !window.localStorage) return;
|
|
112
|
-
try {
|
|
113
|
-
window.localStorage.removeItem(key);
|
|
114
|
-
} catch (error) {
|
|
115
|
-
console.error("localStorage.remove error:", error);
|
|
116
|
-
}
|
|
117
|
-
},
|
|
118
|
-
/**
|
|
119
|
-
* 清空所有值
|
|
120
|
-
*/
|
|
121
|
-
clear() {
|
|
122
|
-
if (typeof window === "undefined" || !window.localStorage) return;
|
|
123
|
-
try {
|
|
124
|
-
window.localStorage.clear();
|
|
125
|
-
} catch (error) {
|
|
126
|
-
console.error("localStorage.clear error:", error);
|
|
127
|
-
}
|
|
128
|
-
},
|
|
129
|
-
/**
|
|
130
|
-
* 获取所有键
|
|
131
|
-
* @returns 键数组
|
|
132
|
-
*/
|
|
133
|
-
keys() {
|
|
134
|
-
if (typeof window === "undefined" || !window.localStorage) return [];
|
|
135
|
-
const keys = [];
|
|
136
|
-
try {
|
|
137
|
-
for (let i = 0; i < window.localStorage.length; i++) {
|
|
138
|
-
const key = window.localStorage.key(i);
|
|
139
|
-
if (key) keys.push(key);
|
|
140
|
-
}
|
|
141
|
-
} catch (error) {
|
|
142
|
-
console.error("localStorage.keys error:", error);
|
|
143
|
-
}
|
|
144
|
-
return keys;
|
|
145
|
-
}
|
|
146
|
-
};
|
|
147
|
-
var sessionStorage = {
|
|
148
|
-
/**
|
|
149
|
-
* 设置值
|
|
150
|
-
* @param key - 键
|
|
151
|
-
* @param value - 值
|
|
152
|
-
* @param options - 选项(公钥等)
|
|
153
|
-
* @returns Promise<void>
|
|
154
|
-
*/
|
|
155
|
-
async set(key, value, options = {}) {
|
|
156
|
-
if (typeof window === "undefined" || !window.sessionStorage) {
|
|
157
|
-
throw new Error("sessionStorage is not available");
|
|
158
|
-
}
|
|
159
|
-
const { publicKey } = options;
|
|
160
|
-
try {
|
|
161
|
-
const jsonStr = JSON.stringify(value);
|
|
162
|
-
const keyToUse = publicKey || globalKeyPair?.publicKey;
|
|
163
|
-
if (keyToUse) {
|
|
164
|
-
const encrypted = await encryptValue(jsonStr, keyToUse);
|
|
165
|
-
window.sessionStorage.setItem(key, encrypted);
|
|
166
|
-
} else {
|
|
167
|
-
const { base64Encode } = await import('./crypto.js');
|
|
168
|
-
const encoded = base64Encode(jsonStr);
|
|
169
|
-
window.sessionStorage.setItem(key, encoded);
|
|
170
|
-
}
|
|
171
|
-
} catch (error) {
|
|
172
|
-
console.error("sessionStorage.set error:", error);
|
|
173
|
-
throw error;
|
|
174
|
-
}
|
|
175
|
-
},
|
|
176
|
-
/**
|
|
177
|
-
* 获取值
|
|
178
|
-
* @param key - 键
|
|
179
|
-
* @param options - 选项(默认值、私钥等)
|
|
180
|
-
* @returns Promise<T | undefined> 值或默认值
|
|
181
|
-
*/
|
|
182
|
-
async get(key, options = {}) {
|
|
183
|
-
if (typeof window === "undefined" || !window.sessionStorage) {
|
|
184
|
-
return options.defaultValue;
|
|
185
|
-
}
|
|
186
|
-
const { defaultValue, privateKey } = options;
|
|
187
|
-
try {
|
|
188
|
-
const encryptedStr = window.sessionStorage.getItem(key);
|
|
189
|
-
if (!encryptedStr) return defaultValue;
|
|
190
|
-
let decryptedStr;
|
|
191
|
-
const keyToUse = privateKey || globalKeyPair?.privateKey;
|
|
192
|
-
if (keyToUse) {
|
|
193
|
-
try {
|
|
194
|
-
decryptedStr = await decryptValue(encryptedStr, keyToUse);
|
|
195
|
-
} catch {
|
|
196
|
-
const { base64Decode } = await import('./crypto.js');
|
|
197
|
-
try {
|
|
198
|
-
decryptedStr = base64Decode(encryptedStr);
|
|
199
|
-
} catch {
|
|
200
|
-
return defaultValue;
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
} else {
|
|
204
|
-
const { base64Decode } = await import('./crypto.js');
|
|
205
|
-
try {
|
|
206
|
-
decryptedStr = base64Decode(encryptedStr);
|
|
207
|
-
} catch {
|
|
208
|
-
return defaultValue;
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
return JSON.parse(decryptedStr);
|
|
212
|
-
} catch {
|
|
213
|
-
return defaultValue;
|
|
214
|
-
}
|
|
215
|
-
},
|
|
216
|
-
/**
|
|
217
|
-
* 移除值
|
|
218
|
-
* @param key - 键
|
|
219
|
-
*/
|
|
220
|
-
remove(key) {
|
|
221
|
-
if (typeof window === "undefined" || !window.sessionStorage) return;
|
|
222
|
-
try {
|
|
223
|
-
window.sessionStorage.removeItem(key);
|
|
224
|
-
} catch (error) {
|
|
225
|
-
console.error("sessionStorage.remove error:", error);
|
|
226
|
-
}
|
|
227
|
-
},
|
|
228
|
-
/**
|
|
229
|
-
* 清空所有值
|
|
230
|
-
*/
|
|
231
|
-
clear() {
|
|
232
|
-
if (typeof window === "undefined" || !window.sessionStorage) return;
|
|
233
|
-
try {
|
|
234
|
-
window.sessionStorage.clear();
|
|
235
|
-
} catch (error) {
|
|
236
|
-
console.error("sessionStorage.clear error:", error);
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
};
|
|
240
|
-
var cookie = {
|
|
241
|
-
/**
|
|
242
|
-
* 设置Cookie
|
|
243
|
-
* @param key - 键
|
|
244
|
-
* @param value - 值
|
|
245
|
-
* @param options - Cookie选项
|
|
246
|
-
*/
|
|
247
|
-
set(key, value, options = {}) {
|
|
248
|
-
if (typeof document === "undefined") {
|
|
249
|
-
throw new Error("document is not available");
|
|
250
|
-
}
|
|
251
|
-
let cookieStr = `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
|
|
252
|
-
if (options.expires) {
|
|
253
|
-
const expiresDate = options.expires instanceof Date ? options.expires : new Date(Date.now() + options.expires * 24 * 60 * 60 * 1e3);
|
|
254
|
-
cookieStr += `; expires=${expiresDate.toUTCString()}`;
|
|
255
|
-
}
|
|
256
|
-
if (options.path) cookieStr += `; path=${options.path}`;
|
|
257
|
-
if (options.domain) cookieStr += `; domain=${options.domain}`;
|
|
258
|
-
if (options.secure) cookieStr += "; secure";
|
|
259
|
-
if (options.sameSite) cookieStr += `; sameSite=${options.sameSite}`;
|
|
260
|
-
document.cookie = cookieStr;
|
|
261
|
-
},
|
|
262
|
-
/**
|
|
263
|
-
* 获取Cookie
|
|
264
|
-
* @param key - 键
|
|
265
|
-
* @returns Cookie值
|
|
266
|
-
*/
|
|
267
|
-
get(key) {
|
|
268
|
-
if (typeof document === "undefined") return void 0;
|
|
269
|
-
const name = encodeURIComponent(key);
|
|
270
|
-
const cookies = document.cookie.split(";");
|
|
271
|
-
for (const cookie2 of cookies) {
|
|
272
|
-
const [cookieKey, cookieValue] = cookie2.trim().split("=");
|
|
273
|
-
if (cookieKey === name) {
|
|
274
|
-
return decodeURIComponent(cookieValue);
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
return void 0;
|
|
278
|
-
},
|
|
279
|
-
/**
|
|
280
|
-
* 移除Cookie
|
|
281
|
-
* @param key - 键
|
|
282
|
-
* @param options - Cookie选项
|
|
283
|
-
*/
|
|
284
|
-
remove(key, options = {}) {
|
|
285
|
-
cookie.set(key, "", {
|
|
286
|
-
...options,
|
|
287
|
-
expires: /* @__PURE__ */ new Date(0)
|
|
288
|
-
});
|
|
289
|
-
},
|
|
290
|
-
/**
|
|
291
|
-
* 获取所有Cookie
|
|
292
|
-
* @returns Cookie对象
|
|
293
|
-
*/
|
|
294
|
-
getAll() {
|
|
295
|
-
if (typeof document === "undefined") return {};
|
|
296
|
-
const cookies = {};
|
|
297
|
-
document.cookie.split(";").forEach((cookieStr) => {
|
|
298
|
-
const [key, value] = cookieStr.trim().split("=");
|
|
299
|
-
if (key && value) {
|
|
300
|
-
cookies[decodeURIComponent(key)] = decodeURIComponent(value);
|
|
301
|
-
}
|
|
302
|
-
});
|
|
303
|
-
return cookies;
|
|
304
|
-
}
|
|
305
|
-
};
|
|
306
|
-
var storage = {
|
|
307
|
-
/**
|
|
308
|
-
* 设置值(优先使用localStorage,失败则使用sessionStorage)
|
|
309
|
-
* @param key - 键
|
|
310
|
-
* @param value - 值
|
|
311
|
-
* @param options - 选项(过期时间、公钥等)
|
|
312
|
-
* @returns Promise<void>
|
|
313
|
-
*/
|
|
314
|
-
async set(key, value, options = {}) {
|
|
315
|
-
try {
|
|
316
|
-
await localStorage.set(key, value, options);
|
|
317
|
-
} catch {
|
|
318
|
-
try {
|
|
319
|
-
await sessionStorage.set(key, value, { publicKey: options.publicKey });
|
|
320
|
-
} catch {
|
|
321
|
-
console.warn("Both localStorage and sessionStorage are not available");
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
},
|
|
325
|
-
/**
|
|
326
|
-
* 获取值
|
|
327
|
-
* @param key - 键
|
|
328
|
-
* @param options - 选项(默认值、私钥等)
|
|
329
|
-
* @returns Promise<T | undefined> 值或默认值
|
|
330
|
-
*/
|
|
331
|
-
async get(key, options = {}) {
|
|
332
|
-
const localValue = await localStorage.get(key, options);
|
|
333
|
-
if (localValue !== void 0) return localValue;
|
|
334
|
-
const sessionValue = await sessionStorage.get(key, options);
|
|
335
|
-
return sessionValue !== void 0 ? sessionValue : options.defaultValue;
|
|
336
|
-
},
|
|
337
|
-
/**
|
|
338
|
-
* 移除值
|
|
339
|
-
* @param key - 键
|
|
340
|
-
*/
|
|
341
|
-
remove(key) {
|
|
342
|
-
localStorage.remove(key);
|
|
343
|
-
sessionStorage.remove(key);
|
|
344
|
-
},
|
|
345
|
-
/**
|
|
346
|
-
* 清空所有值
|
|
347
|
-
*/
|
|
348
|
-
clear() {
|
|
349
|
-
localStorage.clear();
|
|
350
|
-
sessionStorage.clear();
|
|
351
|
-
}
|
|
352
|
-
};
|
|
353
|
-
|
|
354
|
-
exports.cookie = cookie;
|
|
355
|
-
exports.getStorageKeyPair = getStorageKeyPair;
|
|
356
|
-
exports.localStorage = localStorage;
|
|
357
|
-
exports.sessionStorage = sessionStorage;
|
|
358
|
-
exports.setStorageKeyPair = setStorageKeyPair;
|
|
359
|
-
exports.storage = storage;
|
|
360
|
-
//# sourceMappingURL=chunk-WZDOPUJW.js.map
|
|
361
|
-
//# sourceMappingURL=chunk-WZDOPUJW.js.map
|
|
@@ -1 +0,0 @@
|
|
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AAA,CAAI,GAAA,EAAK,KAAA,EAAO,OAAO,CAAA;AAAA,IAC5C,CAAA,CAAA,MAAQ;AACN,MAAA,IAAI;AACF,QAAA,MAAM,cAAA,CAAe,IAAI,GAAA,EAAK,KAAA,EAAO,EAAE,SAAA,EAAW,OAAA,CAAQ,WAAW,CAAA;AAAA,MACvE,CAAA,CAAA,MAAQ;AACN,QAAA,OAAA,CAAQ,KAAK,wDAAwD,CAAA;AAAA,MACvE;AAAA,IACF;AAAA,EACF,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,GAAA,CACJ,GAAA,EACA,OAAA,GAGI,EAAC,EACmB;AACxB,IAAA,MAAM,UAAA,GAAa,MAAM,YAAA,CAAa,GAAA,CAAO,KAAK,OAAO,CAAA;AACzD,IAAA,IAAI,UAAA,KAAe,QAAW,OAAO,UAAA;AAErC,IAAA,MAAM,YAAA,GAAe,MAAM,cAAA,CAAe,GAAA,CAAO,KAAK,OAAO,CAAA;AAC7D,IAAA,OAAO,YAAA,KAAiB,MAAA,GAAY,YAAA,GAAe,OAAA,CAAQ,YAAA;AAAA,EAC7D,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,OAAO,GAAA,EAAmB;AACxB,IAAA,YAAA,CAAa,OAAO,GAAG,CAAA;AACvB,IAAA,cAAA,CAAe,OAAO,GAAG,CAAA;AAAA,EAC3B,CAAA;AAAA;AAAA;AAAA;AAAA,EAKA,KAAA,GAAc;AACZ,IAAA,YAAA,CAAa,KAAA,EAAM;AACnB,IAAA,cAAA,CAAe,KAAA,EAAM;AAAA,EACvB;AACF","file":"chunk-WZDOPUJW.js","sourcesContent":["/**\n * 存储工具函数\n */\n\nimport { rsaEncrypt, rsaDecrypt, type RSAKeyPair } from '../helper/crypto';\n\n/**\n * 存储项配置\n */\ninterface StorageItem<T> {\n value: T;\n expiry?: number; // 过期时间戳\n}\n\n/**\n * 存储配置选项\n */\nexport interface StorageOptions {\n /** RSA公钥(用于加密) */\n publicKey?: CryptoKey;\n /** RSA私钥(用于解密) */\n privateKey?: CryptoKey;\n /** 是否启用加密,默认为 true */\n encrypt?: boolean;\n}\n\n// 全局密钥对(可选,用户也可以传入)\nlet globalKeyPair: RSAKeyPair | null = null;\n\n/**\n * 设置全局RSA密钥对\n * @param keyPair - RSA密钥对\n */\nexport function setStorageKeyPair(keyPair: RSAKeyPair): void {\n globalKeyPair = keyPair;\n}\n\n/**\n * 获取全局密钥对\n * @returns 全局密钥对或null\n */\nexport function getStorageKeyPair(): RSAKeyPair | null {\n return globalKeyPair;\n}\n\n/**\n * 加密存储值\n * @param value - 要加密的值\n * @param publicKey - RSA公钥\n * @returns Promise<string> 加密后的Base64字符串\n */\nasync function encryptValue(value: string, publicKey: CryptoKey): Promise<string> {\n return rsaEncrypt(value, publicKey);\n}\n\n/**\n * 解密存储值\n * @param encryptedValue - 加密后的Base64字符串\n * @param privateKey - RSA私钥\n * @returns Promise<string> 解密后的字符串\n */\nasync function decryptValue(encryptedValue: string, privateKey: CryptoKey): Promise<string> {\n try {\n return await rsaDecrypt(encryptedValue, privateKey);\n } catch {\n // 如果解密失败,可能是旧数据(未加密)或格式错误\n // 尝试直接解析 JSON(向后兼容)\n try {\n JSON.parse(encryptedValue);\n return encryptedValue; // 如果是有效的 JSON,返回原值\n } catch {\n throw new Error('Failed to decrypt storage value');\n }\n }\n}\n\n/**\n * localStorage封装(支持过期时间和RSA加密)\n */\nexport const localStorage = {\n /**\n * 设置值\n * @param key - 键\n * @param value - 值\n * @param options - 选项(过期时间、密钥等)\n * @returns Promise<void>\n */\n async set<T>(\n key: string,\n value: T,\n options: {\n expiry?: number;\n publicKey?: CryptoKey;\n } = {}\n ): Promise<void> {\n if (typeof window === 'undefined' || !window.localStorage) {\n throw new Error('localStorage is not available');\n }\n\n const { expiry, publicKey } = options;\n const item: StorageItem<T> = {\n value,\n expiry: expiry ? Date.now() + expiry : undefined,\n };\n\n try {\n const jsonStr = JSON.stringify(item);\n\n // 如果提供了公钥或全局密钥对存在,使用RSA加密\n const keyToUse = publicKey || globalKeyPair?.publicKey;\n if (keyToUse) {\n const encrypted = await encryptValue(jsonStr, keyToUse);\n window.localStorage.setItem(key, encrypted);\n } else {\n // 如果没有密钥,使用Base64编码(向后兼容)\n const { base64Encode } = await import('../helper/crypto');\n const encoded = base64Encode(jsonStr);\n window.localStorage.setItem(key, encoded);\n }\n } catch (error) {\n console.error('localStorage.set error:', error);\n throw error;\n }\n },\n\n /**\n * 获取值\n * @param key - 键\n * @param options - 选项(默认值、私钥等)\n * @returns Promise<T | undefined> 值或默认值\n */\n async get<T>(\n key: string,\n options: {\n defaultValue?: T;\n privateKey?: CryptoKey;\n } = {}\n ): Promise<T | undefined> {\n if (typeof window === 'undefined' || !window.localStorage) {\n return options.defaultValue;\n }\n\n const { defaultValue, privateKey } = options;\n\n try {\n const encryptedStr = window.localStorage.getItem(key);\n if (!encryptedStr) return defaultValue;\n\n let decryptedStr: string;\n\n // 如果提供了私钥或全局密钥对存在,使用RSA解密\n const keyToUse = privateKey || globalKeyPair?.privateKey;\n if (keyToUse) {\n try {\n decryptedStr = await decryptValue(encryptedStr, keyToUse);\n } catch {\n // RSA解密失败,尝试Base64解码(向后兼容)\n const { base64Decode } = await import('../helper/crypto');\n try {\n decryptedStr = base64Decode(encryptedStr);\n } catch {\n return defaultValue;\n }\n }\n } else {\n // 如果没有密钥,尝试Base64解码\n const { base64Decode } = await import('../helper/crypto');\n try {\n decryptedStr = base64Decode(encryptedStr);\n } catch {\n return defaultValue;\n }\n }\n\n const item: StorageItem<T> = JSON.parse(decryptedStr);\n\n // 检查是否过期\n if (item.expiry && Date.now() > item.expiry) {\n window.localStorage.removeItem(key);\n return defaultValue;\n }\n\n return item.value;\n } catch {\n return defaultValue;\n }\n },\n\n /**\n * 移除值\n * @param key - 键\n */\n remove(key: string): void {\n if (typeof window === 'undefined' || !window.localStorage) return;\n try {\n window.localStorage.removeItem(key);\n } catch (error) {\n console.error('localStorage.remove error:', error);\n }\n },\n\n /**\n * 清空所有值\n */\n clear(): void {\n if (typeof window === 'undefined' || !window.localStorage) return;\n try {\n window.localStorage.clear();\n } catch (error) {\n console.error('localStorage.clear error:', error);\n }\n },\n\n /**\n * 获取所有键\n * @returns 键数组\n */\n keys(): string[] {\n if (typeof window === 'undefined' || !window.localStorage) return [];\n const keys: string[] = [];\n try {\n for (let i = 0; i < window.localStorage.length; i++) {\n const key = window.localStorage.key(i);\n if (key) keys.push(key);\n }\n } catch (error) {\n console.error('localStorage.keys error:', error);\n }\n return keys;\n },\n};\n\n/**\n * sessionStorage封装(支持RSA加密)\n */\nexport const sessionStorage = {\n /**\n * 设置值\n * @param key - 键\n * @param value - 值\n * @param options - 选项(公钥等)\n * @returns Promise<void>\n */\n async set<T>(\n key: string,\n value: T,\n options: {\n publicKey?: CryptoKey;\n } = {}\n ): Promise<void> {\n if (typeof window === 'undefined' || !window.sessionStorage) {\n throw new Error('sessionStorage is not available');\n }\n\n const { publicKey } = options;\n\n try {\n const jsonStr = JSON.stringify(value);\n\n // 如果提供了公钥或全局密钥对存在,使用RSA加密\n const keyToUse = publicKey || globalKeyPair?.publicKey;\n if (keyToUse) {\n const encrypted = await encryptValue(jsonStr, keyToUse);\n window.sessionStorage.setItem(key, encrypted);\n } else {\n // 如果没有密钥,使用Base64编码(向后兼容)\n const { base64Encode } = await import('../helper/crypto');\n const encoded = base64Encode(jsonStr);\n window.sessionStorage.setItem(key, encoded);\n }\n } catch (error) {\n console.error('sessionStorage.set error:', error);\n throw error;\n }\n },\n\n /**\n * 获取值\n * @param key - 键\n * @param options - 选项(默认值、私钥等)\n * @returns Promise<T | undefined> 值或默认值\n */\n async get<T>(\n key: string,\n options: {\n defaultValue?: T;\n privateKey?: CryptoKey;\n } = {}\n ): Promise<T | undefined> {\n if (typeof window === 'undefined' || !window.sessionStorage) {\n return options.defaultValue;\n }\n\n const { defaultValue, privateKey } = options;\n\n try {\n const encryptedStr = window.sessionStorage.getItem(key);\n if (!encryptedStr) return defaultValue;\n\n let decryptedStr: string;\n\n // 如果提供了私钥或全局密钥对存在,使用RSA解密\n const keyToUse = privateKey || globalKeyPair?.privateKey;\n if (keyToUse) {\n try {\n decryptedStr = await decryptValue(encryptedStr, keyToUse);\n } catch {\n // RSA解密失败,尝试Base64解码(向后兼容)\n const { base64Decode } = await import('../helper/crypto');\n try {\n decryptedStr = base64Decode(encryptedStr);\n } catch {\n return defaultValue;\n }\n }\n } else {\n // 如果没有密钥,尝试Base64解码\n const { base64Decode } = await import('../helper/crypto');\n try {\n decryptedStr = base64Decode(encryptedStr);\n } catch {\n return defaultValue;\n }\n }\n\n return JSON.parse(decryptedStr) as T;\n } catch {\n return defaultValue;\n }\n },\n\n /**\n * 移除值\n * @param key - 键\n */\n remove(key: string): void {\n if (typeof window === 'undefined' || !window.sessionStorage) return;\n try {\n window.sessionStorage.removeItem(key);\n } catch (error) {\n console.error('sessionStorage.remove error:', error);\n }\n },\n\n /**\n * 清空所有值\n */\n clear(): void {\n if (typeof window === 'undefined' || !window.sessionStorage) return;\n try {\n window.sessionStorage.clear();\n } catch (error) {\n console.error('sessionStorage.clear error:', error);\n }\n },\n};\n\n/**\n * Cookie操作封装\n */\nexport const cookie = {\n /**\n * 设置Cookie\n * @param key - 键\n * @param value - 值\n * @param options - Cookie选项\n */\n set(\n key: string,\n value: string,\n options: {\n expires?: number | Date; // 过期时间(天数或Date对象)\n path?: string;\n domain?: string;\n secure?: boolean;\n sameSite?: 'strict' | 'lax' | 'none';\n } = {}\n ): void {\n if (typeof document === 'undefined') {\n throw new Error('document is not available');\n }\n\n let cookieStr = `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;\n\n if (options.expires) {\n const expiresDate =\n options.expires instanceof Date\n ? options.expires\n : new Date(Date.now() + options.expires * 24 * 60 * 60 * 1000);\n cookieStr += `; expires=${expiresDate.toUTCString()}`;\n }\n\n if (options.path) cookieStr += `; path=${options.path}`;\n if (options.domain) cookieStr += `; domain=${options.domain}`;\n if (options.secure) cookieStr += '; secure';\n if (options.sameSite) cookieStr += `; sameSite=${options.sameSite}`;\n\n document.cookie = cookieStr;\n },\n\n /**\n * 获取Cookie\n * @param key - 键\n * @returns Cookie值\n */\n get(key: string): string | undefined {\n if (typeof document === 'undefined') return undefined;\n\n const name = encodeURIComponent(key);\n const cookies = document.cookie.split(';');\n\n for (const cookie of cookies) {\n const [cookieKey, cookieValue] = cookie.trim().split('=');\n if (cookieKey === name) {\n return decodeURIComponent(cookieValue);\n }\n }\n\n return undefined;\n },\n\n /**\n * 移除Cookie\n * @param key - 键\n * @param options - Cookie选项\n */\n remove(key: string, options: { path?: string; domain?: string } = {}): void {\n cookie.set(key, '', {\n ...options,\n expires: new Date(0),\n });\n },\n\n /**\n * 获取所有Cookie\n * @returns Cookie对象\n */\n getAll(): Record<string, string> {\n if (typeof document === 'undefined') return {};\n\n const cookies: Record<string, string> = {};\n document.cookie.split(';').forEach(cookieStr => {\n const [key, value] = cookieStr.trim().split('=');\n if (key && value) {\n cookies[decodeURIComponent(key)] = decodeURIComponent(value);\n }\n });\n\n return cookies;\n },\n};\n\n/**\n * 统一存储接口(自动选择存储方式,支持RSA加密)\n */\nexport const storage = {\n /**\n * 设置值(优先使用localStorage,失败则使用sessionStorage)\n * @param key - 键\n * @param value - 值\n * @param options - 选项(过期时间、公钥等)\n * @returns Promise<void>\n */\n async set<T>(\n key: string,\n value: T,\n options: {\n expiry?: number;\n publicKey?: CryptoKey;\n } = {}\n ): Promise<void> {\n try {\n await localStorage.set(key, value, options);\n } catch {\n try {\n await sessionStorage.set(key, value, { publicKey: options.publicKey });\n } catch {\n console.warn('Both localStorage and sessionStorage are not available');\n }\n }\n },\n\n /**\n * 获取值\n * @param key - 键\n * @param options - 选项(默认值、私钥等)\n * @returns Promise<T | undefined> 值或默认值\n */\n async get<T>(\n key: string,\n options: {\n defaultValue?: T;\n privateKey?: CryptoKey;\n } = {}\n ): Promise<T | undefined> {\n const localValue = await localStorage.get<T>(key, options);\n if (localValue !== undefined) return localValue;\n\n const sessionValue = await sessionStorage.get<T>(key, options);\n return sessionValue !== undefined ? sessionValue : options.defaultValue;\n },\n\n /**\n * 移除值\n * @param key - 键\n */\n remove(key: string): void {\n localStorage.remove(key);\n sessionStorage.remove(key);\n },\n\n /**\n * 清空所有值\n */\n clear(): void {\n localStorage.clear();\n sessionStorage.clear();\n },\n};\n"]}
|
package/dist/chunk-XJTZDXSR.mjs
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
// src/core/string.ts
|
|
2
|
-
function capitalize(str) {
|
|
3
|
-
if (!str) return str;
|
|
4
|
-
return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
|
|
5
|
-
}
|
|
6
|
-
function camelCase(str) {
|
|
7
|
-
if (!str) return str;
|
|
8
|
-
const words = str.replace(/[A-Z]/g, (letter) => ` ${letter.toLowerCase()}`).split(/[\s\-_]+/).filter((word) => word.length > 0);
|
|
9
|
-
if (words.length === 0) return "";
|
|
10
|
-
return words[0].toLowerCase() + words.slice(1).map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join("");
|
|
11
|
-
}
|
|
12
|
-
function kebabCase(str) {
|
|
13
|
-
return str.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/[\s_]+/g, "-").toLowerCase();
|
|
14
|
-
}
|
|
15
|
-
function truncate(str, length, suffix = "...") {
|
|
16
|
-
if (str.length <= length) return str;
|
|
17
|
-
return str.slice(0, length - suffix.length) + suffix;
|
|
18
|
-
}
|
|
19
|
-
function snakeCase(str) {
|
|
20
|
-
if (!str) return str;
|
|
21
|
-
return str.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`).replace(/[\s-]+/g, "_").replace(/^_+|_+$/g, "").toLowerCase();
|
|
22
|
-
}
|
|
23
|
-
function pascalCase(str) {
|
|
24
|
-
if (!str) return str;
|
|
25
|
-
const camel = camelCase(str);
|
|
26
|
-
return camel.charAt(0).toUpperCase() + camel.slice(1);
|
|
27
|
-
}
|
|
28
|
-
function mask(str, options = {}) {
|
|
29
|
-
if (!str) return str;
|
|
30
|
-
const { start = 0, end = str.length, maskChar = "*" } = options;
|
|
31
|
-
const startIndex = Math.max(0, start);
|
|
32
|
-
const endIndex = Math.min(str.length, end);
|
|
33
|
-
if (startIndex >= endIndex) return str;
|
|
34
|
-
return str.slice(0, startIndex) + maskChar.repeat(endIndex - startIndex) + str.slice(endIndex);
|
|
35
|
-
}
|
|
36
|
-
function maskPhone(phone) {
|
|
37
|
-
if (!phone || phone.length < 7) return phone;
|
|
38
|
-
return mask(phone, { start: 3, end: phone.length - 4 });
|
|
39
|
-
}
|
|
40
|
-
function maskEmail(email) {
|
|
41
|
-
if (!email || !email.includes("@")) return email;
|
|
42
|
-
const [local, domain] = email.split("@");
|
|
43
|
-
if (local.length <= 2) return email;
|
|
44
|
-
return `${local.slice(0, 2)}***@${domain}`;
|
|
45
|
-
}
|
|
46
|
-
function slugify(str) {
|
|
47
|
-
if (!str) return "";
|
|
48
|
-
return str.toLowerCase().trim().replace(/[^\w\s-]/g, "").replace(/[\s_-]+/g, "-").replace(/^-+|-+$/g, "");
|
|
49
|
-
}
|
|
50
|
-
function removeAccents(str) {
|
|
51
|
-
if (!str) return str;
|
|
52
|
-
return str.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
|
|
53
|
-
}
|
|
54
|
-
function escapeHtml(str) {
|
|
55
|
-
if (!str) return str;
|
|
56
|
-
const map = {
|
|
57
|
-
"&": "&",
|
|
58
|
-
"<": "<",
|
|
59
|
-
">": ">",
|
|
60
|
-
'"': """,
|
|
61
|
-
"'": "'"
|
|
62
|
-
};
|
|
63
|
-
return str.replace(/[&<>"']/g, (char) => map[char]);
|
|
64
|
-
}
|
|
65
|
-
function unescapeHtml(str) {
|
|
66
|
-
if (!str) return str;
|
|
67
|
-
const map = {
|
|
68
|
-
"&": "&",
|
|
69
|
-
"<": "<",
|
|
70
|
-
">": ">",
|
|
71
|
-
""": '"',
|
|
72
|
-
"'": "'"
|
|
73
|
-
};
|
|
74
|
-
return str.replace(/&|<|>|"|'/g, (char) => map[char]);
|
|
75
|
-
}
|
|
76
|
-
function template(template2, data) {
|
|
77
|
-
if (!template2) return template2;
|
|
78
|
-
return template2.replace(/\{\{(\w+)\}\}/g, (match, key) => {
|
|
79
|
-
const value = data[key];
|
|
80
|
-
return value !== void 0 && value !== null ? String(value) : match;
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
function highlight(text, keyword, tag = "mark") {
|
|
84
|
-
if (!text || !keyword) return text;
|
|
85
|
-
const regex = new RegExp(`(${escapeRegex(keyword)})`, "gi");
|
|
86
|
-
return text.replace(regex, `<${tag}>$1</${tag}>`);
|
|
87
|
-
}
|
|
88
|
-
function escapeRegex(str) {
|
|
89
|
-
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export { camelCase, capitalize, escapeHtml, highlight, kebabCase, mask, maskEmail, maskPhone, pascalCase, removeAccents, slugify, snakeCase, template, truncate, unescapeHtml };
|
|
93
|
-
//# sourceMappingURL=chunk-XJTZDXSR.mjs.map
|
|
94
|
-
//# sourceMappingURL=chunk-XJTZDXSR.mjs.map
|