speexjs-core 0.7.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/CHANGELOG.md +117 -0
- package/CONTRIBUTING.md +55 -0
- package/PUBLISH.md +45 -0
- package/README.md +174 -0
- package/ROADMAP.md +72 -0
- package/SECURITY.md +35 -0
- package/SUMMARY.md +321 -0
- package/dist/async/index.d.ts +232 -0
- package/dist/async/index.js +366 -0
- package/dist/async/index.js.map +1 -0
- package/dist/collection/index.d.ts +230 -0
- package/dist/collection/index.js +375 -0
- package/dist/collection/index.js.map +1 -0
- package/dist/color/index.d.ts +128 -0
- package/dist/color/index.js +167 -0
- package/dist/color/index.js.map +1 -0
- package/dist/core/index.d.ts +119 -0
- package/dist/core/index.js +324 -0
- package/dist/core/index.js.map +1 -0
- package/dist/crypto/index.d.ts +84 -0
- package/dist/crypto/index.js +144 -0
- package/dist/crypto/index.js.map +1 -0
- package/dist/date/index.d.ts +588 -0
- package/dist/date/index.js +737 -0
- package/dist/date/index.js.map +1 -0
- package/dist/dep-exray/analyzer/index.d.ts +7 -0
- package/dist/dep-exray/analyzer/index.js +68 -0
- package/dist/dep-exray/analyzer/index.js.map +1 -0
- package/dist/dep-exray/cli.d.ts +1 -0
- package/dist/dep-exray/cli.js +441 -0
- package/dist/dep-exray/cli.js.map +1 -0
- package/dist/dep-exray/index.d.ts +5 -0
- package/dist/dep-exray/index.js +454 -0
- package/dist/dep-exray/index.js.map +1 -0
- package/dist/dep-exray/known-mappings.d.ts +17 -0
- package/dist/dep-exray/known-mappings.js +122 -0
- package/dist/dep-exray/known-mappings.js.map +1 -0
- package/dist/dep-exray/reporter/index.d.ts +5 -0
- package/dist/dep-exray/reporter/index.js +89 -0
- package/dist/dep-exray/reporter/index.js.map +1 -0
- package/dist/dep-exray/scanner/index.d.ts +5 -0
- package/dist/dep-exray/scanner/index.js +299 -0
- package/dist/dep-exray/scanner/index.js.map +1 -0
- package/dist/dep-exray/types.d.ts +38 -0
- package/dist/dep-exray/types.js +1 -0
- package/dist/dep-exray/types.js.map +1 -0
- package/dist/error/index.d.ts +148 -0
- package/dist/error/index.js +115 -0
- package/dist/error/index.js.map +1 -0
- package/dist/index-BgG21uJC.d.ts +166 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +4378 -0
- package/dist/index.js.map +1 -0
- package/dist/io/index.d.ts +39 -0
- package/dist/io/index.js +111 -0
- package/dist/io/index.js.map +1 -0
- package/dist/logger/index.d.ts +1 -0
- package/dist/logger/index.js +214 -0
- package/dist/logger/index.js.map +1 -0
- package/dist/logger/transports.d.ts +1 -0
- package/dist/logger/transports.js +122 -0
- package/dist/logger/transports.js.map +1 -0
- package/dist/math/index.d.ts +362 -0
- package/dist/math/index.js +372 -0
- package/dist/math/index.js.map +1 -0
- package/dist/path/index.d.ts +81 -0
- package/dist/path/index.js +134 -0
- package/dist/path/index.js.map +1 -0
- package/dist/string/index.d.ts +234 -0
- package/dist/string/index.js +411 -0
- package/dist/string/index.js.map +1 -0
- package/dist/type/index.d.ts +85 -0
- package/dist/type/index.js +107 -0
- package/dist/type/index.js.map +1 -0
- package/dist/validation/index.d.ts +203 -0
- package/dist/validation/index.js +402 -0
- package/dist/validation/index.js.map +1 -0
- package/package.json +172 -0
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
// src/color/index.ts
|
|
2
|
+
function hexToRgb(hex) {
|
|
3
|
+
let h = hex.replace("#", "");
|
|
4
|
+
if (h.length === 3) h = h[0] + h[0] + h[1] + h[1] + h[2] + h[2];
|
|
5
|
+
if (h.length !== 6) return null;
|
|
6
|
+
const num = Number.parseInt(h, 16);
|
|
7
|
+
if (isNaN(num)) return null;
|
|
8
|
+
return {
|
|
9
|
+
r: num >> 16 & 255,
|
|
10
|
+
g: num >> 8 & 255,
|
|
11
|
+
b: num & 255
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
function rgbToHex(r, g, b) {
|
|
15
|
+
const toHex = (n) => Math.max(0, Math.min(255, Math.round(n))).toString(16).padStart(2, "0");
|
|
16
|
+
return "#" + toHex(r) + toHex(g) + toHex(b);
|
|
17
|
+
}
|
|
18
|
+
function lighten(hex, percent) {
|
|
19
|
+
const rgb = hexToRgb(hex);
|
|
20
|
+
if (!rgb) return hex;
|
|
21
|
+
const factor = percent / 100;
|
|
22
|
+
return rgbToHex(
|
|
23
|
+
rgb.r + (255 - rgb.r) * factor,
|
|
24
|
+
rgb.g + (255 - rgb.g) * factor,
|
|
25
|
+
rgb.b + (255 - rgb.b) * factor
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
function darken(hex, percent) {
|
|
29
|
+
const rgb = hexToRgb(hex);
|
|
30
|
+
if (!rgb) return hex;
|
|
31
|
+
const factor = percent / 100;
|
|
32
|
+
return rgbToHex(
|
|
33
|
+
rgb.r * (1 - factor),
|
|
34
|
+
rgb.g * (1 - factor),
|
|
35
|
+
rgb.b * (1 - factor)
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
function contrastRatio(hex1, hex2) {
|
|
39
|
+
const lum1 = relativeLuminance(hex1);
|
|
40
|
+
const lum2 = relativeLuminance(hex2);
|
|
41
|
+
const lighter = Math.max(lum1, lum2);
|
|
42
|
+
const darker = Math.min(lum1, lum2);
|
|
43
|
+
return Number(((lighter + 0.05) / (darker + 0.05)).toFixed(2));
|
|
44
|
+
}
|
|
45
|
+
function relativeLuminance(hex) {
|
|
46
|
+
const rgb = hexToRgb(hex);
|
|
47
|
+
if (!rgb) return 0;
|
|
48
|
+
const vals = [rgb.r / 255, rgb.g / 255, rgb.b / 255].map((c) => {
|
|
49
|
+
return c <= 0.03928 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4);
|
|
50
|
+
});
|
|
51
|
+
return 0.2126 * vals[0] + 0.7152 * vals[1] + 0.0722 * vals[2];
|
|
52
|
+
}
|
|
53
|
+
function meetsWCAG(hex1, hex2, level) {
|
|
54
|
+
const ratio = contrastRatio(hex1, hex2);
|
|
55
|
+
const threshold = level === "AAA" ? 7 : 4.5;
|
|
56
|
+
return ratio >= threshold;
|
|
57
|
+
}
|
|
58
|
+
function isValidHex(value) {
|
|
59
|
+
return /^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/.test(value);
|
|
60
|
+
}
|
|
61
|
+
function hexToHsl(hex) {
|
|
62
|
+
const rgb = hexToRgb(hex);
|
|
63
|
+
if (!rgb) return null;
|
|
64
|
+
const r = rgb.r / 255;
|
|
65
|
+
const g = rgb.g / 255;
|
|
66
|
+
const b = rgb.b / 255;
|
|
67
|
+
const max = Math.max(r, g, b);
|
|
68
|
+
const min = Math.min(r, g, b);
|
|
69
|
+
const l = (max + min) / 2;
|
|
70
|
+
if (max === min) return { h: 0, s: 0, l: Math.round(l * 100) };
|
|
71
|
+
const d = max - min;
|
|
72
|
+
const s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
|
|
73
|
+
let h = 0;
|
|
74
|
+
switch (max) {
|
|
75
|
+
case r:
|
|
76
|
+
h = ((g - b) / d + (g < b ? 6 : 0)) / 6;
|
|
77
|
+
break;
|
|
78
|
+
case g:
|
|
79
|
+
h = ((b - r) / d + 2) / 6;
|
|
80
|
+
break;
|
|
81
|
+
case b:
|
|
82
|
+
h = ((r - g) / d + 4) / 6;
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
h: Math.round(h * 360),
|
|
87
|
+
s: Math.round(s * 100),
|
|
88
|
+
l: Math.round(l * 100)
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function hslToHex(h, s, l) {
|
|
92
|
+
const hue = h / 360;
|
|
93
|
+
const sat = s / 100;
|
|
94
|
+
const lig = l / 100;
|
|
95
|
+
if (sat === 0) {
|
|
96
|
+
const val = Math.round(lig * 255);
|
|
97
|
+
return rgbToHex(val, val, val);
|
|
98
|
+
}
|
|
99
|
+
const hue2rgb = (p2, q2, t) => {
|
|
100
|
+
let tt = t;
|
|
101
|
+
if (tt < 0) tt += 1;
|
|
102
|
+
if (tt > 1) tt -= 1;
|
|
103
|
+
if (tt < 1 / 6) return p2 + (q2 - p2) * 6 * tt;
|
|
104
|
+
if (tt < 1 / 2) return q2;
|
|
105
|
+
if (tt < 2 / 3) return p2 + (q2 - p2) * (2 / 3 - tt) * 6;
|
|
106
|
+
return p2;
|
|
107
|
+
};
|
|
108
|
+
const q = lig < 0.5 ? lig * (1 + sat) : lig + sat - lig * sat;
|
|
109
|
+
const p = 2 * lig - q;
|
|
110
|
+
return rgbToHex(
|
|
111
|
+
Math.round(hue2rgb(p, q, hue + 1 / 3) * 255),
|
|
112
|
+
Math.round(hue2rgb(p, q, hue) * 255),
|
|
113
|
+
Math.round(hue2rgb(p, q, hue - 1 / 3) * 255)
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
function mix(color1, color2, weight = 0.5) {
|
|
117
|
+
const rgb1 = hexToRgb(color1);
|
|
118
|
+
const rgb2 = hexToRgb(color2);
|
|
119
|
+
if (!rgb1 || !rgb2) return color1;
|
|
120
|
+
const w = Math.max(0, Math.min(1, weight));
|
|
121
|
+
const lerp = (a, b) => Math.floor(a + (b - a) * w);
|
|
122
|
+
return rgbToHex(lerp(rgb1.r, rgb2.r), lerp(rgb1.g, rgb2.g), lerp(rgb1.b, rgb2.b));
|
|
123
|
+
}
|
|
124
|
+
function randomColor() {
|
|
125
|
+
const r = Math.floor(Math.random() * 256);
|
|
126
|
+
const g = Math.floor(Math.random() * 256);
|
|
127
|
+
const b = Math.floor(Math.random() * 256);
|
|
128
|
+
return rgbToHex(r, g, b);
|
|
129
|
+
}
|
|
130
|
+
function isLight(hex) {
|
|
131
|
+
const rgb = hexToRgb(hex);
|
|
132
|
+
if (!rgb) return false;
|
|
133
|
+
return (0.299 * rgb.r + 0.587 * rgb.g + 0.114 * rgb.b) / 255 > 0.5;
|
|
134
|
+
}
|
|
135
|
+
function isDark(hex) {
|
|
136
|
+
return !isLight(hex);
|
|
137
|
+
}
|
|
138
|
+
function complementary(hex) {
|
|
139
|
+
const hsl = hexToHsl(hex);
|
|
140
|
+
if (!hsl) return hex;
|
|
141
|
+
return hslToHex((hsl.h + 180) % 360, hsl.s, hsl.l);
|
|
142
|
+
}
|
|
143
|
+
function alpha(hex, opacity) {
|
|
144
|
+
const rgb = hexToRgb(hex);
|
|
145
|
+
if (!rgb) return hex;
|
|
146
|
+
const a = Math.max(0, Math.min(1, opacity));
|
|
147
|
+
const alphaHex = Math.round(a * 255).toString(16).padStart(2, "0");
|
|
148
|
+
return rgbToHex(rgb.r, rgb.g, rgb.b) + alphaHex;
|
|
149
|
+
}
|
|
150
|
+
export {
|
|
151
|
+
alpha,
|
|
152
|
+
complementary,
|
|
153
|
+
contrastRatio,
|
|
154
|
+
darken,
|
|
155
|
+
hexToHsl,
|
|
156
|
+
hexToRgb,
|
|
157
|
+
hslToHex,
|
|
158
|
+
isDark,
|
|
159
|
+
isLight,
|
|
160
|
+
isValidHex,
|
|
161
|
+
lighten,
|
|
162
|
+
meetsWCAG,
|
|
163
|
+
mix,
|
|
164
|
+
randomColor,
|
|
165
|
+
rgbToHex
|
|
166
|
+
};
|
|
167
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/color/index.ts"],"sourcesContent":["/**\n * Converts a hex color string to RGB values.\n *\n * @example hexToRgb('#ff0000') // { r: 255, g: 0, b: 0 }\n * @example hexToRgb('#f00') // { r: 255, g: 0, b: 0 }\n * @example hexToRgb('#FF8800') // { r: 255, g: 136, b: 0 }\n */\nexport function hexToRgb(hex: string): { r: number; g: number; b: number } | null {\n let h = hex.replace('#', '')\n if (h.length === 3) h = h[0]! + h[0] + h[1]! + h[1] + h[2]! + h[2]\n if (h.length !== 6) return null\n const num = Number.parseInt(h, 16)\n if (isNaN(num)) return null\n return {\n r: (num >> 16) & 255,\n g: (num >> 8) & 255,\n b: num & 255,\n }\n}\n\n/**\n * Converts RGB values to a hex color string.\n *\n * @example rgbToHex(255, 0, 0) // \"#ff0000\"\n * @example rgbToHex(255, 136, 0) // \"#ff8800\"\n */\nexport function rgbToHex(r: number, g: number, b: number): string {\n const toHex = (n: number) => Math.max(0, Math.min(255, Math.round(n))).toString(16).padStart(2, '0')\n return '#' + toHex(r) + toHex(g) + toHex(b)\n}\n\n/**\n * Lightens a hex color by a given percentage (0-100).\n *\n * @example lighten('#ff0000', 20) // \"#ff3333\"\n * @example lighten('#0000ff', 50) // \"#7f7fff\"\n */\nexport function lighten(hex: string, percent: number): string {\n const rgb = hexToRgb(hex)\n if (!rgb) return hex\n const factor = percent / 100\n return rgbToHex(\n rgb.r + (255 - rgb.r) * factor,\n rgb.g + (255 - rgb.g) * factor,\n rgb.b + (255 - rgb.b) * factor,\n )\n}\n\n/**\n * Darkens a hex color by a given percentage (0-100).\n *\n * @example darken('#ff0000', 20) // \"#cc0000\"\n * @example darken('#00ff00', 50) // \"#008000\"\n */\nexport function darken(hex: string, percent: number): string {\n const rgb = hexToRgb(hex)\n if (!rgb) return hex\n const factor = percent / 100\n return rgbToHex(\n rgb.r * (1 - factor),\n rgb.g * (1 - factor),\n rgb.b * (1 - factor),\n )\n}\n\n/**\n * Checks the WCAG contrast ratio between two hex colors.\n * Returns the ratio as a number (1-21). WCAG AA requires 4.5:1 for normal text.\n *\n * @example contrastRatio('#000000', '#ffffff') // 21\n * @example contrastRatio('#ff0000', '#ffffff') // 3.99\n */\nexport function contrastRatio(hex1: string, hex2: string): number {\n const lum1 = relativeLuminance(hex1)\n const lum2 = relativeLuminance(hex2)\n const lighter = Math.max(lum1, lum2)\n const darker = Math.min(lum1, lum2)\n return Number(((lighter + 0.05) / (darker + 0.05)).toFixed(2))\n}\n\nfunction relativeLuminance(hex: string): number {\n const rgb = hexToRgb(hex)\n if (!rgb) return 0\n const vals = [rgb.r / 255, rgb.g / 255, rgb.b / 255].map((c) => {\n return c <= 0.03928 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4)\n })\n return 0.2126 * vals[0]! + 0.7152 * vals[1]! + 0.0722 * vals[2]!\n}\n\n/**\n * Checks if a hex color meets WCAG AA contrast ratio (4.5:1) against another color.\n *\n * @example meetsWCAG('#000000', '#ffffff') // true (black on white)\n * @example meetsWCAG('#999999', '#ffffff') // false (gray on white)\n */\nexport function meetsWCAG(hex1: string, hex2: string, level?: 'AA' | 'AAA'): boolean {\n const ratio = contrastRatio(hex1, hex2)\n const threshold = level === 'AAA' ? 7 : 4.5\n return ratio >= threshold\n}\n\n/**\n * Checks if a string is a valid hex color.\n * Supports 3-digit (#rgb), 6-digit (#rrggbb), with or without leading `#`.\n *\n * @example isValidHex('#ff0000') // true\n * @example isValidHex('#f00') // true\n * @example isValidHex('ff0000') // true\n * @example isValidHex('#xyz') // false\n */\nexport function isValidHex(value: string): boolean {\n return /^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/.test(value)\n}\n\n/**\n * Converts a hex color to an HSL object.\n * Returns `null` for invalid input.\n *\n * @example hexToHsl('#ff0000') // { h: 0, s: 100, l: 50 }\n * @example hexToHsl('#00ff00') // { h: 120, s: 100, l: 50 }\n * @example hexToHsl('#0000ff') // { h: 240, s: 100, l: 50 }\n */\nexport function hexToHsl(hex: string): { h: number; s: number; l: number } | null {\n const rgb = hexToRgb(hex)\n if (!rgb) return null\n const r = rgb.r / 255\n const g = rgb.g / 255\n const b = rgb.b / 255\n const max = Math.max(r, g, b)\n const min = Math.min(r, g, b)\n const l = (max + min) / 2\n if (max === min) return { h: 0, s: 0, l: Math.round(l * 100) }\n const d = max - min\n const s = l > 0.5 ? d / (2 - max - min) : d / (max + min)\n let h = 0\n switch (max) {\n case r: h = ((g - b) / d + (g < b ? 6 : 0)) / 6; break\n case g: h = ((b - r) / d + 2) / 6; break\n case b: h = ((r - g) / d + 4) / 6; break\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 * Converts HSL values to a hex color string.\n *\n * @example hslToHex(0, 100, 50) // '#ff0000'\n * @example hslToHex(120, 100, 50) // '#00ff00'\n * @example hslToHex(240, 100, 50) // '#0000ff'\n */\nexport function hslToHex(h: number, s: number, l: number): string {\n const hue = h / 360\n const sat = s / 100\n const lig = l / 100\n if (sat === 0) {\n const val = Math.round(lig * 255)\n return rgbToHex(val, val, val)\n }\n const hue2rgb = (p: number, q: number, t: number): number => {\n let tt = t\n if (tt < 0) tt += 1\n if (tt > 1) tt -= 1\n if (tt < 1 / 6) return p + (q - p) * 6 * tt\n if (tt < 1 / 2) return q\n if (tt < 2 / 3) return p + (q - p) * (2 / 3 - tt) * 6\n return p\n }\n const q = lig < 0.5 ? lig * (1 + sat) : lig + sat - lig * sat\n const p = 2 * lig - q\n return rgbToHex(\n Math.round(hue2rgb(p, q, hue + 1 / 3) * 255),\n Math.round(hue2rgb(p, q, hue) * 255),\n Math.round(hue2rgb(p, q, hue - 1 / 3) * 255),\n )\n}\n\n/**\n * Blends two hex colors together with a weight factor.\n * Weight 0 = fully color1, weight 1 = fully color2. Default 0.5.\n *\n * @example mix('#ff0000', '#0000ff') // '#7f007f'\n * @example mix('#ff0000', '#0000ff', 0) // '#ff0000'\n * @example mix('#ff0000', '#0000ff', 1) // '#0000ff'\n */\nexport function mix(color1: string, color2: string, weight: number = 0.5): string {\n const rgb1 = hexToRgb(color1)\n const rgb2 = hexToRgb(color2)\n if (!rgb1 || !rgb2) return color1\n const w = Math.max(0, Math.min(1, weight))\n const lerp = (a: number, b: number) => Math.floor(a + (b - a) * w)\n return rgbToHex(lerp(rgb1.r, rgb2.r), lerp(rgb1.g, rgb2.g), lerp(rgb1.b, rgb2.b))\n}\n\n/**\n * Generates a random hex color.\n *\n * @example randomColor() // '#a3f07b'\n */\nexport function randomColor(): string {\n const r = Math.floor(Math.random() * 256)\n const g = Math.floor(Math.random() * 256)\n const b = Math.floor(Math.random() * 256)\n return rgbToHex(r, g, b)\n}\n\n/**\n * Checks if a hex color is perceived as light (useful for text contrast decisions).\n *\n * @example isLight('#ffffff') // true\n * @example isLight('#000000') // false\n * @example isLight('#ff0000') // false\n */\nexport function isLight(hex: string): boolean {\n const rgb = hexToRgb(hex)\n if (!rgb) return false\n return (0.299 * rgb.r + 0.587 * rgb.g + 0.114 * rgb.b) / 255 > 0.5\n}\n\n/**\n * Checks if a hex color is perceived as dark.\n *\n * @example isDark('#000000') // true\n * @example isDark('#ffffff') // false\n */\nexport function isDark(hex: string): boolean {\n return !isLight(hex)\n}\n\n/**\n * Returns the complementary color (180° hue rotation).\n *\n * @example complementary('#ff0000') // '#00ffff'\n * @example complementary('#00ff00') // '#ff00ff'\n * @example complementary('#0000ff') // '#ffff00'\n */\nexport function complementary(hex: string): string {\n const hsl = hexToHsl(hex)\n if (!hsl) return hex\n return hslToHex((hsl.h + 180) % 360, hsl.s, hsl.l)\n}\n\n/**\n * Sets opacity on a hex color, returning an 8-digit hex (#rrggbbaa).\n * Opacity is clamped to 0-1.\n *\n * @example alpha('#ff0000', 0.5) // '#ff000080'\n * @example alpha('#00ff00', 1) // '#00ff00ff'\n * @example alpha('#0000ff', 0) // '#0000ff00'\n */\nexport function alpha(hex: string, opacity: number): string {\n const rgb = hexToRgb(hex)\n if (!rgb) return hex\n const a = Math.max(0, Math.min(1, opacity))\n const alphaHex = Math.round(a * 255).toString(16).padStart(2, '0')\n return rgbToHex(rgb.r, rgb.g, rgb.b) + alphaHex\n}\n"],"mappings":";AAOO,SAAS,SAAS,KAAyD;AAChF,MAAI,IAAI,IAAI,QAAQ,KAAK,EAAE;AAC3B,MAAI,EAAE,WAAW,EAAG,KAAI,EAAE,CAAC,IAAK,EAAE,CAAC,IAAI,EAAE,CAAC,IAAK,EAAE,CAAC,IAAI,EAAE,CAAC,IAAK,EAAE,CAAC;AACjE,MAAI,EAAE,WAAW,EAAG,QAAO;AAC3B,QAAM,MAAM,OAAO,SAAS,GAAG,EAAE;AACjC,MAAI,MAAM,GAAG,EAAG,QAAO;AACvB,SAAO;AAAA,IACL,GAAI,OAAO,KAAM;AAA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extends (...args: unknown[]) => unknown> {
|
|
7
|
+
(...args: Parameters<T>): void;
|
|
8
|
+
cancel(): void;
|
|
9
|
+
flush(): void;
|
|
10
|
+
}
|
|
11
|
+
interface MemoizedFunction<T extends (...args: unknown[]) => unknown> {
|
|
12
|
+
(...args: Parameters<T>): ReturnType<T>;
|
|
13
|
+
cache: Map<string, ReturnType<T>>;
|
|
14
|
+
}
|
|
15
|
+
interface RetryOptions {
|
|
16
|
+
attempts?: number;
|
|
17
|
+
baseDelay?: number;
|
|
18
|
+
maxDelay?: number;
|
|
19
|
+
shouldRetry?: (error: unknown) => boolean;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Deep clone a value, supporting objects, arrays, Date, RegExp, Map, Set,
|
|
23
|
+
* and cyclic references.
|
|
24
|
+
*
|
|
25
|
+
* @param value - The value to clone.
|
|
26
|
+
* @returns A deep copy of the input value.
|
|
27
|
+
*/
|
|
28
|
+
declare function deepClone<T>(value: T): T;
|
|
29
|
+
/**
|
|
30
|
+
* Deep merge multiple objects. Arrays are overwritten, not concatenated.
|
|
31
|
+
* `null` and `undefined` source objects are skipped.
|
|
32
|
+
*
|
|
33
|
+
* @param objects - The objects to merge.
|
|
34
|
+
* @returns A new object with merged properties.
|
|
35
|
+
*/
|
|
36
|
+
declare function deepMerge<T extends Record<string, unknown>>(...objects: Partial<T>[]): T;
|
|
37
|
+
/**
|
|
38
|
+
* Creates a debounced function that delays invoking `fn` until after `wait`
|
|
39
|
+
* milliseconds have elapsed since the last invocation. Supports leading,
|
|
40
|
+
* trailing, and maxWait options. The returned function also has `.cancel()`
|
|
41
|
+
* and `.flush()` methods.
|
|
42
|
+
*
|
|
43
|
+
* @param fn - The function to debounce.
|
|
44
|
+
* @param wait - The number of milliseconds to delay.
|
|
45
|
+
* @param options - Optional configuration.
|
|
46
|
+
* @returns A debounced function with `.cancel()` and `.flush()`.
|
|
47
|
+
*/
|
|
48
|
+
declare function debounce<T extends (...args: unknown[]) => unknown>(fn: T, wait: number, options?: DebounceOptions): DebouncedFunction<T>;
|
|
49
|
+
/**
|
|
50
|
+
* Creates a throttled function that only invokes `fn` at most once per
|
|
51
|
+
* `wait` milliseconds.
|
|
52
|
+
*
|
|
53
|
+
* @param fn - The function to throttle.
|
|
54
|
+
* @param wait - The number of milliseconds to throttle invocations to.
|
|
55
|
+
* @returns A throttled function.
|
|
56
|
+
*/
|
|
57
|
+
declare function throttle<T extends (...args: unknown[]) => unknown>(fn: T, wait: number): (...args: Parameters<T>) => void;
|
|
58
|
+
/**
|
|
59
|
+
* Creates a memoized version of `fn`. Uses a `Map` cache keyed by the
|
|
60
|
+
* first argument by default, or by a custom `resolver` function.
|
|
61
|
+
*
|
|
62
|
+
* @param fn - The function to memoize.
|
|
63
|
+
* @param resolver - Optional function to determine the cache key.
|
|
64
|
+
* @returns The memoized function with a `.cache` property.
|
|
65
|
+
*/
|
|
66
|
+
declare function memoize<T extends (...args: unknown[]) => unknown>(fn: T, resolver?: (...args: Parameters<T>) => string): MemoizedFunction<T>;
|
|
67
|
+
/**
|
|
68
|
+
* Retries an async function with exponential backoff and jitter.
|
|
69
|
+
*
|
|
70
|
+
* @param fn - The async function to retry.
|
|
71
|
+
* @param options - Retry configuration.
|
|
72
|
+
* @returns A promise that resolves with the function result.
|
|
73
|
+
*/
|
|
74
|
+
declare function retry<T>(fn: () => Promise<T>, options?: RetryOptions): Promise<T>;
|
|
75
|
+
/**
|
|
76
|
+
* A no-operation function that returns `undefined`.
|
|
77
|
+
*/
|
|
78
|
+
declare function noop(): void;
|
|
79
|
+
/**
|
|
80
|
+
* Returns the given value unchanged.
|
|
81
|
+
*
|
|
82
|
+
* @param value - The value to return.
|
|
83
|
+
* @returns The same value.
|
|
84
|
+
*/
|
|
85
|
+
declare function identity<T>(value: T): T;
|
|
86
|
+
/**
|
|
87
|
+
* Creates a function that invokes `fn` only once. Subsequent calls return
|
|
88
|
+
* the result of the first invocation.
|
|
89
|
+
*
|
|
90
|
+
* @param fn - The function to wrap.
|
|
91
|
+
* @returns A function that runs only once.
|
|
92
|
+
*/
|
|
93
|
+
declare function once<T extends (...args: unknown[]) => unknown>(fn: T): (...args: Parameters<T>) => ReturnType<T>;
|
|
94
|
+
/**
|
|
95
|
+
* Deep equality check between two values. Supports primitives, objects,
|
|
96
|
+
* arrays, Date, RegExp, Map, Set, and nested structures. Circular
|
|
97
|
+
* references are handled.
|
|
98
|
+
*
|
|
99
|
+
* @example deepEqual({ a: 1, b: { c: 2 } }, { a: 1, b: { c: 2 } }) // true
|
|
100
|
+
* @example deepEqual({ a: 1 }, { a: 2 }) // false
|
|
101
|
+
*/
|
|
102
|
+
declare function deepEqual(a: unknown, b: unknown): boolean;
|
|
103
|
+
/**
|
|
104
|
+
* Performs left-to-right function composition.
|
|
105
|
+
*
|
|
106
|
+
* @example const fn = pipe((x: number) => x + 1, (x: number) => x * 2)
|
|
107
|
+
* fn(3) // 8
|
|
108
|
+
*/
|
|
109
|
+
declare function pipe<T>(initial: T, ...fns: Array<(arg: T) => T>): T;
|
|
110
|
+
declare function pipe<T, R>(initial: T, ...fns: Array<(arg: unknown) => unknown>): R;
|
|
111
|
+
/**
|
|
112
|
+
* Performs right-to-left function composition.
|
|
113
|
+
*
|
|
114
|
+
* @example const fn = compose((x: number) => x * 2, (x: number) => x + 1)
|
|
115
|
+
* fn(3) // 8 — same as (3+1)*2
|
|
116
|
+
*/
|
|
117
|
+
declare function compose<T>(...fns: Array<(arg: T) => T>): (initial: T) => T;
|
|
118
|
+
|
|
119
|
+
export { type DebounceOptions, type DebouncedFunction, type MemoizedFunction, type RetryOptions, compose, debounce, deepClone, deepEqual, deepMerge, identity, memoize, noop, once, pipe, retry, throttle };
|
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
// src/core/index.ts
|
|
2
|
+
function isPlainObject(value) {
|
|
3
|
+
if (value === null || typeof value !== "object") return false;
|
|
4
|
+
const proto = Object.getPrototypeOf(value);
|
|
5
|
+
return proto === Object.prototype || proto === null;
|
|
6
|
+
}
|
|
7
|
+
function getType(value) {
|
|
8
|
+
return Object.prototype.toString.call(value);
|
|
9
|
+
}
|
|
10
|
+
function clone(value, seen) {
|
|
11
|
+
if (value === null || typeof value !== "object") return value;
|
|
12
|
+
if (seen.has(value)) return seen.get(value);
|
|
13
|
+
const tag = getType(value);
|
|
14
|
+
if (tag === "[object Date]") {
|
|
15
|
+
const cloned = new Date(value.getTime());
|
|
16
|
+
seen.set(value, cloned);
|
|
17
|
+
return cloned;
|
|
18
|
+
}
|
|
19
|
+
if (tag === "[object RegExp]") {
|
|
20
|
+
const regExp = value;
|
|
21
|
+
const cloned = new RegExp(regExp.source, regExp.flags);
|
|
22
|
+
cloned.lastIndex = regExp.lastIndex;
|
|
23
|
+
seen.set(value, cloned);
|
|
24
|
+
return cloned;
|
|
25
|
+
}
|
|
26
|
+
if (tag === "[object Map]") {
|
|
27
|
+
const cloned = /* @__PURE__ */ new Map();
|
|
28
|
+
seen.set(value, cloned);
|
|
29
|
+
value.forEach((v, k) => {
|
|
30
|
+
cloned.set(clone(k, seen), clone(v, seen));
|
|
31
|
+
});
|
|
32
|
+
return cloned;
|
|
33
|
+
}
|
|
34
|
+
if (tag === "[object Set]") {
|
|
35
|
+
const cloned = /* @__PURE__ */ new Set();
|
|
36
|
+
seen.set(value, cloned);
|
|
37
|
+
value.forEach((v) => {
|
|
38
|
+
cloned.add(clone(v, seen));
|
|
39
|
+
});
|
|
40
|
+
return cloned;
|
|
41
|
+
}
|
|
42
|
+
if (Array.isArray(value)) {
|
|
43
|
+
const cloned = [];
|
|
44
|
+
seen.set(value, cloned);
|
|
45
|
+
for (let i = 0; i < value.length; i++) {
|
|
46
|
+
cloned[i] = clone(value[i], seen);
|
|
47
|
+
}
|
|
48
|
+
return cloned;
|
|
49
|
+
}
|
|
50
|
+
if (tag === "[object Object]") {
|
|
51
|
+
const cloned = {};
|
|
52
|
+
seen.set(value, cloned);
|
|
53
|
+
const keys = Object.keys(value);
|
|
54
|
+
for (let i = 0; i < keys.length; i++) {
|
|
55
|
+
const key = keys[i];
|
|
56
|
+
cloned[key] = clone(value[key], seen);
|
|
57
|
+
}
|
|
58
|
+
return cloned;
|
|
59
|
+
}
|
|
60
|
+
return value;
|
|
61
|
+
}
|
|
62
|
+
function deepClone(value) {
|
|
63
|
+
const seen = /* @__PURE__ */ new WeakMap();
|
|
64
|
+
return clone(value, seen);
|
|
65
|
+
}
|
|
66
|
+
function deepMerge(...objects) {
|
|
67
|
+
const result = {};
|
|
68
|
+
for (let i = 0; i < objects.length; i++) {
|
|
69
|
+
const obj = objects[i];
|
|
70
|
+
if (obj === null || obj === void 0) continue;
|
|
71
|
+
const keys = Object.keys(obj);
|
|
72
|
+
for (let j = 0; j < keys.length; j++) {
|
|
73
|
+
const key = keys[j];
|
|
74
|
+
if (key === "__proto__" || key === "constructor" || key === "prototype") continue;
|
|
75
|
+
const val = obj[key];
|
|
76
|
+
const existing = result[key];
|
|
77
|
+
if (val !== void 0 && isPlainObject(val) && isPlainObject(existing)) {
|
|
78
|
+
result[key] = deepMerge(
|
|
79
|
+
existing,
|
|
80
|
+
val
|
|
81
|
+
);
|
|
82
|
+
} else if (val !== void 0) {
|
|
83
|
+
result[key] = val;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return result;
|
|
88
|
+
}
|
|
89
|
+
function debounce(fn, wait, options) {
|
|
90
|
+
const { leading = false, trailing = true, maxWait } = options ?? {};
|
|
91
|
+
let timer = null;
|
|
92
|
+
let maxTimer = null;
|
|
93
|
+
let lastArgs = null;
|
|
94
|
+
let lastCallTime = null;
|
|
95
|
+
let lastInvokeTime = 0;
|
|
96
|
+
function invoke(time) {
|
|
97
|
+
lastInvokeTime = time;
|
|
98
|
+
if (lastArgs) {
|
|
99
|
+
fn(...lastArgs);
|
|
100
|
+
lastArgs = null;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
function startTimer(waitTime) {
|
|
104
|
+
if (timer) clearTimeout(timer);
|
|
105
|
+
timer = setTimeout(() => {
|
|
106
|
+
const now = Date.now();
|
|
107
|
+
if (lastArgs && trailing) {
|
|
108
|
+
invoke(now);
|
|
109
|
+
}
|
|
110
|
+
timer = null;
|
|
111
|
+
lastCallTime = null;
|
|
112
|
+
}, waitTime);
|
|
113
|
+
}
|
|
114
|
+
function startMaxTimer() {
|
|
115
|
+
if (maxWait === void 0 || maxTimer) return;
|
|
116
|
+
maxTimer = setTimeout(() => {
|
|
117
|
+
if (lastArgs) {
|
|
118
|
+
invoke(Date.now());
|
|
119
|
+
if (timer) {
|
|
120
|
+
clearTimeout(timer);
|
|
121
|
+
timer = null;
|
|
122
|
+
}
|
|
123
|
+
lastCallTime = null;
|
|
124
|
+
}
|
|
125
|
+
}, maxWait);
|
|
126
|
+
}
|
|
127
|
+
function clearAllTimers() {
|
|
128
|
+
if (timer) {
|
|
129
|
+
clearTimeout(timer);
|
|
130
|
+
timer = null;
|
|
131
|
+
}
|
|
132
|
+
if (maxTimer) {
|
|
133
|
+
clearTimeout(maxTimer);
|
|
134
|
+
maxTimer = null;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
function shouldInvoke(time) {
|
|
138
|
+
if (lastCallTime === null) return true;
|
|
139
|
+
const timeSinceLastCall = time - lastCallTime;
|
|
140
|
+
const timeSinceLastInvoke = time - lastInvokeTime;
|
|
141
|
+
return timeSinceLastCall >= wait || maxWait !== void 0 && timeSinceLastInvoke >= maxWait;
|
|
142
|
+
}
|
|
143
|
+
const debounced = function(...args) {
|
|
144
|
+
const time = Date.now();
|
|
145
|
+
const isInvoking = shouldInvoke(time);
|
|
146
|
+
lastArgs = args;
|
|
147
|
+
lastCallTime = time;
|
|
148
|
+
if (isInvoking && !timer && leading) {
|
|
149
|
+
invoke(time);
|
|
150
|
+
}
|
|
151
|
+
if (!timer) {
|
|
152
|
+
startTimer(wait);
|
|
153
|
+
if (maxWait !== void 0) {
|
|
154
|
+
startMaxTimer();
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
debounced.cancel = () => {
|
|
159
|
+
clearAllTimers();
|
|
160
|
+
lastArgs = null;
|
|
161
|
+
lastCallTime = null;
|
|
162
|
+
lastInvokeTime = 0;
|
|
163
|
+
};
|
|
164
|
+
debounced.flush = () => {
|
|
165
|
+
if (timer && lastArgs) {
|
|
166
|
+
invoke(Date.now());
|
|
167
|
+
clearAllTimers();
|
|
168
|
+
lastCallTime = null;
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
return debounced;
|
|
172
|
+
}
|
|
173
|
+
function throttle(fn, wait) {
|
|
174
|
+
let lastTime = 0;
|
|
175
|
+
let timer = null;
|
|
176
|
+
let lastArgs = null;
|
|
177
|
+
const throttled = function(...args) {
|
|
178
|
+
const now = Date.now();
|
|
179
|
+
const remaining = wait - (now - lastTime);
|
|
180
|
+
if (remaining <= 0) {
|
|
181
|
+
if (timer) {
|
|
182
|
+
clearTimeout(timer);
|
|
183
|
+
timer = null;
|
|
184
|
+
}
|
|
185
|
+
lastTime = now;
|
|
186
|
+
lastArgs = null;
|
|
187
|
+
fn.apply(this, args);
|
|
188
|
+
} else {
|
|
189
|
+
lastArgs = args;
|
|
190
|
+
if (!timer) {
|
|
191
|
+
timer = setTimeout(() => {
|
|
192
|
+
lastTime = Date.now();
|
|
193
|
+
timer = null;
|
|
194
|
+
if (lastArgs) {
|
|
195
|
+
fn.apply(this, lastArgs);
|
|
196
|
+
lastArgs = null;
|
|
197
|
+
}
|
|
198
|
+
}, remaining);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
return throttled;
|
|
203
|
+
}
|
|
204
|
+
function memoize(fn, resolver) {
|
|
205
|
+
const cache = /* @__PURE__ */ new Map();
|
|
206
|
+
const memoized = function(...args) {
|
|
207
|
+
const key = resolver ? resolver(...args) : String(args[0]);
|
|
208
|
+
if (cache.has(key)) {
|
|
209
|
+
return cache.get(key);
|
|
210
|
+
}
|
|
211
|
+
const result = fn.apply(this, args);
|
|
212
|
+
cache.set(key, result);
|
|
213
|
+
return result;
|
|
214
|
+
};
|
|
215
|
+
memoized.cache = cache;
|
|
216
|
+
return memoized;
|
|
217
|
+
}
|
|
218
|
+
function retry(fn, options) {
|
|
219
|
+
const {
|
|
220
|
+
attempts = 3,
|
|
221
|
+
baseDelay = 1e3,
|
|
222
|
+
maxDelay = 3e4,
|
|
223
|
+
shouldRetry = () => true
|
|
224
|
+
} = options ?? {};
|
|
225
|
+
let attempt = 0;
|
|
226
|
+
const execute = () => {
|
|
227
|
+
attempt++;
|
|
228
|
+
return fn().catch((error) => {
|
|
229
|
+
if (attempt >= attempts || !shouldRetry(error)) {
|
|
230
|
+
throw error;
|
|
231
|
+
}
|
|
232
|
+
const delay = Math.min(
|
|
233
|
+
baseDelay * Math.pow(2, attempt - 1) + Math.random() * baseDelay,
|
|
234
|
+
maxDelay
|
|
235
|
+
);
|
|
236
|
+
return new Promise((resolve) => {
|
|
237
|
+
setTimeout(() => {
|
|
238
|
+
resolve(execute());
|
|
239
|
+
}, delay);
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
};
|
|
243
|
+
return execute();
|
|
244
|
+
}
|
|
245
|
+
function noop() {
|
|
246
|
+
return void 0;
|
|
247
|
+
}
|
|
248
|
+
function identity(value) {
|
|
249
|
+
return value;
|
|
250
|
+
}
|
|
251
|
+
function once(fn) {
|
|
252
|
+
let called = false;
|
|
253
|
+
let result;
|
|
254
|
+
return function(...args) {
|
|
255
|
+
if (!called) {
|
|
256
|
+
called = true;
|
|
257
|
+
result = fn.apply(this, args);
|
|
258
|
+
}
|
|
259
|
+
return result;
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
function deepEqual(a, b) {
|
|
263
|
+
if (Object.is(a, b)) return true;
|
|
264
|
+
if (a === null || b === null || typeof a !== typeof b) return false;
|
|
265
|
+
if (typeof a !== "object") return false;
|
|
266
|
+
const aObj = a;
|
|
267
|
+
const bObj = b;
|
|
268
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
269
|
+
if (a.length !== b.length) return false;
|
|
270
|
+
for (let i = 0; i < a.length; i++) {
|
|
271
|
+
if (!deepEqual(a[i], b[i])) return false;
|
|
272
|
+
}
|
|
273
|
+
return true;
|
|
274
|
+
}
|
|
275
|
+
if (a instanceof Date && b instanceof Date) {
|
|
276
|
+
return a.getTime() === b.getTime();
|
|
277
|
+
}
|
|
278
|
+
if (a instanceof RegExp && b instanceof RegExp) {
|
|
279
|
+
return a.source === b.source && a.flags === b.flags;
|
|
280
|
+
}
|
|
281
|
+
if (a instanceof Map && b instanceof Map) {
|
|
282
|
+
if (a.size !== b.size) return false;
|
|
283
|
+
for (const [k, v] of a) {
|
|
284
|
+
if (!b.has(k) || !deepEqual(v, b.get(k))) return false;
|
|
285
|
+
}
|
|
286
|
+
return true;
|
|
287
|
+
}
|
|
288
|
+
if (a instanceof Set && b instanceof Set) {
|
|
289
|
+
if (a.size !== b.size) return false;
|
|
290
|
+
for (const v of a) {
|
|
291
|
+
if (!b.has(v)) return false;
|
|
292
|
+
}
|
|
293
|
+
return true;
|
|
294
|
+
}
|
|
295
|
+
const keysA = Object.keys(aObj);
|
|
296
|
+
const keysB = Object.keys(bObj);
|
|
297
|
+
if (keysA.length !== keysB.length) return false;
|
|
298
|
+
for (const key of keysA) {
|
|
299
|
+
if (!Object.prototype.hasOwnProperty.call(bObj, key)) return false;
|
|
300
|
+
if (!deepEqual(aObj[key], bObj[key])) return false;
|
|
301
|
+
}
|
|
302
|
+
return true;
|
|
303
|
+
}
|
|
304
|
+
function pipe(initial, ...fns) {
|
|
305
|
+
return fns.reduce((acc, fn) => fn(acc), initial);
|
|
306
|
+
}
|
|
307
|
+
function compose(...fns) {
|
|
308
|
+
return (initial) => fns.reduceRight((acc, fn) => fn(acc), initial);
|
|
309
|
+
}
|
|
310
|
+
export {
|
|
311
|
+
compose,
|
|
312
|
+
debounce,
|
|
313
|
+
deepClone,
|
|
314
|
+
deepEqual,
|
|
315
|
+
deepMerge,
|
|
316
|
+
identity,
|
|
317
|
+
memoize,
|
|
318
|
+
noop,
|
|
319
|
+
once,
|
|
320
|
+
pipe,
|
|
321
|
+
retry,
|
|
322
|
+
throttle
|
|
323
|
+
};
|
|
324
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/core/index.ts"],"sourcesContent":["export interface DebounceOptions {\r\n leading?: boolean\r\n trailing?: boolean\r\n maxWait?: number\r\n}\r\n\r\nexport interface DebouncedFunction<T extends (...args: unknown[]) => unknown> {\r\n (...args: Parameters<T>): void\r\n cancel(): void\r\n flush(): void\r\n}\r\n\r\nexport interface MemoizedFunction<T extends (...args: unknown[]) => unknown> {\r\n (...args: Parameters<T>): ReturnType<T>\r\n cache: Map<string, ReturnType<T>>\r\n}\r\n\r\nexport interface RetryOptions {\r\n attempts?: number\r\n baseDelay?: number\r\n maxDelay?: number\r\n shouldRetry?: (error: unknown) => boolean\r\n}\r\n\r\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\r\n if (value === null || typeof value !== 'object') return false\r\n const proto = Object.getPrototypeOf(value)\r\n return proto === Object.prototype || proto === null\r\n}\r\n\r\nfunction getType(value: unknown): string {\r\n return Object.prototype.toString.call(value)\r\n}\r\n\r\nfunction clone<T>(value: T, seen: WeakMap<object, unknown>): T {\r\n if (value === null || typeof value !== 'object') return value\r\n\r\n if (seen.has(value as object)) return seen.get(value as object) as T\r\n\r\n const tag = getType(value)\r\n\r\n if (tag === '[object Date]') {\r\n const cloned = new Date((value as unknown as Date).getTime())\r\n seen.set(value as object, cloned)\r\n return cloned as unknown as T\r\n }\r\n\r\n if (tag === '[object RegExp]') {\r\n const regExp = value as unknown as RegExp\r\n const cloned = new RegExp(regExp.source, regExp.flags)\r\n cloned.lastIndex = regExp.lastIndex\r\n seen.set(value as object, cloned)\r\n return cloned as unknown as T\r\n }\r\n\r\n if (tag === '[object Map]') {\r\n const cloned = new Map<unknown, unknown>()\r\n seen.set(value as object, cloned)\r\n ;(value as unknown as Map<unknown, unknown>).forEach((v, k) => {\r\n cloned.set(clone(k, seen), clone(v, seen))\r\n })\r\n return cloned as unknown as T\r\n }\r\n\r\n if (tag === '[object Set]') {\r\n const cloned = new Set<unknown>()\r\n seen.set(value as object, cloned)\r\n ;(value as unknown as Set<unknown>).forEach(v => {\r\n cloned.add(clone(v, seen))\r\n })\r\n return cloned as unknown as T\r\n }\r\n\r\n if (Array.isArray(value)) {\r\n const cloned: unknown[] = []\r\n seen.set(value as object, cloned)\r\n for (let i = 0; i < value.length; i++) {\r\n cloned[i] = clone(value[i], seen)\r\n }\r\n return cloned as unknown as T\r\n }\r\n\r\n if (tag === '[object Object]') {\r\n const cloned: Record<string, unknown> = {}\r\n seen.set(value as object, cloned)\r\n const keys = Object.keys(value as Record<string, unknown>)\r\n for (let i = 0; i < keys.length; i++) {\r\n const key = keys[i]!\r\n cloned[key] = clone((value as Record<string, unknown>)[key], seen)\r\n }\r\n return cloned as unknown as T\r\n }\r\n\r\n return value\r\n}\r\n\r\n/**\r\n * Deep clone a value, supporting objects, arrays, Date, RegExp, Map, Set,\r\n * and cyclic references.\r\n *\r\n * @param value - The value to clone.\r\n * @returns A deep copy of the input value.\r\n */\r\nexport function deepClone<T>(value: T): T {\r\n const seen = new WeakMap<object, unknown>()\r\n return clone(value, seen)\r\n}\r\n\r\n/**\r\n * Deep merge multiple objects. Arrays are overwritten, not concatenated.\r\n * `null` and `undefined` source objects are skipped.\r\n *\r\n * @param objects - The objects to merge.\r\n * @returns A new object with merged properties.\r\n */\r\nexport function deepMerge<T extends Record<string, unknown>>(...objects: Partial<T>[]): T {\r\n const result = {} as T\r\n\r\n for (let i = 0; i < objects.length; i++) {\r\n const obj = objects[i]\r\n if (obj === null || obj === undefined) continue\r\n\r\n const keys = Object.keys(obj) as (keyof T)[]\r\n for (let j = 0; j < keys.length; j++) {\r\n const key = keys[j]!\r\n if (key === '__proto__' || key === 'constructor' || key === 'prototype') continue\r\n const val = obj[key]\r\n const existing = result[key]\r\n\r\n if (val !== undefined && isPlainObject(val) && isPlainObject(existing)) {\r\n result[key] = deepMerge(\r\n existing as Record<string, unknown>,\r\n val as Record<string, unknown>\r\n ) as T[keyof T]\r\n } else if (val !== undefined) {\r\n result[key] = val as T[keyof T]\r\n }\r\n }\r\n }\r\n\r\n return result\r\n}\r\n\r\n/**\r\n * Creates a debounced function that delays invoking `fn` until after `wait`\r\n * milliseconds have elapsed since the last invocation. Supports leading,\r\n * trailing, and maxWait options. The returned function also has `.cancel()`\r\n * and `.flush()` methods.\r\n *\r\n * @param fn - The function to debounce.\r\n * @param wait - The number of milliseconds to delay.\r\n * @param options - Optional configuration.\r\n * @returns A debounced function with `.cancel()` and `.flush()`.\r\n */\r\nexport function debounce<T extends (...args: unknown[]) => unknown>(\r\n fn: T,\r\n wait: number,\r\n options?: DebounceOptions\r\n): DebouncedFunction<T> {\r\n const { leading = false, trailing = true, maxWait } = options ?? {}\r\n\r\n let timer: ReturnType<typeof setTimeout> | null = null\r\n let maxTimer: ReturnType<typeof setTimeout> | null = null\r\n let lastArgs: Parameters<T> | null = null\r\n let lastCallTime: number | null = null\r\n let lastInvokeTime = 0\r\n\r\n function invoke(time: number): void {\r\n lastInvokeTime = time\r\n if (lastArgs) {\r\n fn(...lastArgs)\r\n lastArgs = null\r\n }\r\n }\r\n\r\n function startTimer(waitTime: number): void {\r\n if (timer) clearTimeout(timer)\r\n timer = setTimeout(() => {\r\n const now = Date.now()\r\n if (lastArgs && trailing) {\r\n invoke(now)\r\n }\r\n timer = null\r\n lastCallTime = null\r\n }, waitTime)\r\n }\r\n\r\n function startMaxTimer(): void {\r\n if (maxWait === undefined || maxTimer) return\r\n maxTimer = setTimeout(() => {\r\n if (lastArgs) {\r\n invoke(Date.now())\r\n if (timer) {\r\n clearTimeout(timer)\r\n timer = null\r\n }\r\n lastCallTime = null\r\n }\r\n }, maxWait)\r\n }\r\n\r\n function clearAllTimers(): void {\r\n if (timer) {\r\n clearTimeout(timer)\r\n timer = null\r\n }\r\n if (maxTimer) {\r\n clearTimeout(maxTimer)\r\n maxTimer = null\r\n }\r\n }\r\n\r\n function shouldInvoke(time: number): boolean {\r\n if (lastCallTime === null) return true\r\n const timeSinceLastCall = time - lastCallTime\r\n const timeSinceLastInvoke = time - lastInvokeTime\r\n return (\r\n timeSinceLastCall >= wait ||\r\n (maxWait !== undefined && timeSinceLastInvoke >= maxWait)\r\n )\r\n }\r\n\r\n const debounced = function (this: unknown, ...args: Parameters<T>): void {\r\n const time = Date.now()\r\n const isInvoking = shouldInvoke(time)\r\n\r\n lastArgs = args\r\n lastCallTime = time\r\n\r\n if (isInvoking && !timer && leading) {\r\n invoke(time)\r\n }\r\n\r\n if (!timer) {\r\n startTimer(wait)\r\n if (maxWait !== undefined) {\r\n startMaxTimer()\r\n }\r\n }\r\n } as DebouncedFunction<T>\r\n\r\n debounced.cancel = (): void => {\r\n clearAllTimers()\r\n lastArgs = null\r\n lastCallTime = null\r\n lastInvokeTime = 0\r\n }\r\n\r\n debounced.flush = (): void => {\r\n if (timer && lastArgs) {\r\n invoke(Date.now())\r\n clearAllTimers()\r\n lastCallTime = null\r\n }\r\n }\r\n\r\n return debounced\r\n}\r\n\r\n/**\r\n * Creates a throttled function that only invokes `fn` at most once per\r\n * `wait` milliseconds.\r\n *\r\n * @param fn - The function to throttle.\r\n * @param wait - The number of milliseconds to throttle invocations to.\r\n * @returns A throttled function.\r\n */\r\nexport function throttle<T extends (...args: unknown[]) => unknown>(\r\n fn: T,\r\n wait: number\r\n): (...args: Parameters<T>) => void {\r\n let lastTime = 0\r\n let timer: ReturnType<typeof setTimeout> | null = null\r\n let lastArgs: Parameters<T> | null = null\r\n\r\n const throttled = function (this: unknown, ...args: Parameters<T>): void {\r\n const now = Date.now()\r\n const remaining = wait - (now - lastTime)\r\n\r\n if (remaining <= 0) {\r\n if (timer) {\r\n clearTimeout(timer)\r\n timer = null\r\n }\r\n lastTime = now\r\n lastArgs = null\r\n fn.apply(this, args)\r\n } else {\r\n lastArgs = args\r\n if (!timer) {\r\n timer = setTimeout(() => {\r\n lastTime = Date.now()\r\n timer = null\r\n if (lastArgs) {\r\n fn.apply(this, lastArgs)\r\n lastArgs = null\r\n }\r\n }, remaining)\r\n }\r\n }\r\n }\r\n\r\n return throttled\r\n}\r\n\r\n/**\r\n * Creates a memoized version of `fn`. Uses a `Map` cache keyed by the\r\n * first argument by default, or by a custom `resolver` function.\r\n *\r\n * @param fn - The function to memoize.\r\n * @param resolver - Optional function to determine the cache key.\r\n * @returns The memoized function with a `.cache` property.\r\n */\r\nexport function memoize<T extends (...args: unknown[]) => unknown>(\r\n fn: T,\r\n resolver?: (...args: Parameters<T>) => string\r\n): MemoizedFunction<T> {\r\n const cache = new Map<string, ReturnType<T>>()\r\n\r\n const memoized = function (this: unknown, ...args: Parameters<T>): ReturnType<T> {\r\n const key = resolver ? resolver(...args) : String(args[0])\r\n if (cache.has(key)) {\r\n return cache.get(key) as ReturnType<T>\r\n }\r\n const result = fn.apply(this, args) as ReturnType<T>\r\n cache.set(key, result)\r\n return result\r\n }\r\n\r\n memoized.cache = cache\r\n\r\n return memoized as MemoizedFunction<T>\r\n}\r\n\r\n/**\r\n * Retries an async function with exponential backoff and jitter.\r\n *\r\n * @param fn - The async function to retry.\r\n * @param options - Retry configuration.\r\n * @returns A promise that resolves with the function result.\r\n */\r\nexport function retry<T>(\r\n fn: () => Promise<T>,\r\n options?: RetryOptions\r\n): Promise<T> {\r\n const {\r\n attempts = 3,\r\n baseDelay = 1000,\r\n maxDelay = 30000,\r\n shouldRetry = () => true,\r\n } = options ?? {}\r\n\r\n let attempt = 0\r\n\r\n const execute = (): Promise<T> => {\r\n attempt++\r\n return fn().catch((error: unknown) => {\r\n if (attempt >= attempts || !shouldRetry(error)) {\r\n throw error\r\n }\r\n\r\n const delay = Math.min(\r\n baseDelay * Math.pow(2, attempt - 1) + Math.random() * baseDelay,\r\n maxDelay\r\n )\r\n\r\n return new Promise<T>(resolve => {\r\n setTimeout(() => {\r\n resolve(execute())\r\n }, delay)\r\n })\r\n })\r\n }\r\n\r\n return execute()\r\n}\r\n\r\n/**\r\n * A no-operation function that returns `undefined`.\r\n */\r\nexport function noop(): void {\r\n return undefined\r\n}\r\n\r\n/**\r\n * Returns the given value unchanged.\r\n *\r\n * @param value - The value to return.\r\n * @returns The same value.\r\n */\r\nexport function identity<T>(value: T): T {\r\n return value\r\n}\r\n\r\n/**\r\n * Creates a function that invokes `fn` only once. Subsequent calls return\r\n * the result of the first invocation.\r\n *\r\n * @param fn - The function to wrap.\r\n * @returns A function that runs only once.\r\n */\r\nexport function once<T extends (...args: unknown[]) => unknown>(\r\n fn: T\r\n): (...args: Parameters<T>) => ReturnType<T> {\r\n let called = false\r\n let result: ReturnType<T>\r\n\r\n return function (this: unknown, ...args: Parameters<T>): ReturnType<T> {\r\n if (!called) {\r\n called = true\r\n result = fn.apply(this, args) as ReturnType<T>\r\n }\r\n return result\r\n }\r\n}\r\n\r\n/**\r\n * Deep equality check between two values. Supports primitives, objects,\r\n * arrays, Date, RegExp, Map, Set, and nested structures. Circular\r\n * references are handled.\r\n *\r\n * @example deepEqual({ a: 1, b: { c: 2 } }, { a: 1, b: { c: 2 } }) // true\r\n * @example deepEqual({ a: 1 }, { a: 2 }) // false\r\n */\r\nexport function deepEqual(a: unknown, b: unknown): boolean {\r\n if (Object.is(a, b)) return true\r\n if (a === null || b === null || typeof a !== typeof b) return false\r\n if (typeof a !== 'object') return false\r\n\r\n const aObj = a as Record<string, unknown>\r\n const bObj = b as Record<string, unknown>\r\n\r\n if (Array.isArray(a) && Array.isArray(b)) {\r\n if (a.length !== b.length) return false\r\n for (let i = 0; i < a.length; i++) {\r\n if (!deepEqual(a[i], b[i])) return false\r\n }\r\n return true\r\n }\r\n\r\n if (a instanceof Date && b instanceof Date) {\r\n return a.getTime() === b.getTime()\r\n }\r\n\r\n if (a instanceof RegExp && b instanceof RegExp) {\r\n return a.source === b.source && a.flags === b.flags\r\n }\r\n\r\n if (a instanceof Map && b instanceof Map) {\r\n if (a.size !== b.size) return false\r\n for (const [k, v] of a) {\r\n if (!b.has(k) || !deepEqual(v, b.get(k))) return false\r\n }\r\n return true\r\n }\r\n\r\n if (a instanceof Set && b instanceof Set) {\r\n if (a.size !== b.size) return false\r\n for (const v of a) {\r\n if (!b.has(v)) return false\r\n }\r\n return true\r\n }\r\n\r\n const keysA = Object.keys(aObj)\r\n const keysB = Object.keys(bObj)\r\n if (keysA.length !== keysB.length) return false\r\n\r\n for (const key of keysA) {\r\n if (!Object.prototype.hasOwnProperty.call(bObj, key)) return false\r\n if (!deepEqual(aObj[key], bObj[key])) return false\r\n }\r\n return true\r\n}\r\n\r\n/**\r\n * Performs left-to-right function composition.\r\n *\r\n * @example const fn = pipe((x: number) => x + 1, (x: number) => x * 2)\r\n * fn(3) // 8\r\n */\r\nexport function pipe<T>(initial: T, ...fns: Array<(arg: T) => T>): T\r\nexport function pipe<T, R>(initial: T, ...fns: Array<(arg: unknown) => unknown>): R\r\nexport function pipe(initial: unknown, ...fns: Array<(arg: unknown) => unknown>): unknown {\r\n return fns.reduce((acc, fn) => fn(acc), initial)\r\n}\r\n\r\n/**\r\n * Performs right-to-left function composition.\r\n *\r\n * @example const fn = compose((x: number) => x * 2, (x: number) => x + 1)\r\n * fn(3) // 8 — same as (3+1)*2\r\n */\r\nexport function compose<T>(...fns: Array<(arg: T) => T>): (initial: T) => T\r\nexport function compose(...fns: Array<(arg: unknown) => unknown>): (initial: unknown) => unknown {\r\n return (initial: unknown) => fns.reduceRight((acc, fn) => fn(acc), initial)\r\n}\r\n"],"mappings":";AAwBA,SAAS,cAAc,OAAkD;AACvE,MAAI,UAAU,QAAQ,OAAO,UAAU,SAAU,QAAO;AACxD,QAAM,QAAQ,OAAO,eAAe,KAAK;AACzC,SAAO,UAAU,OAAO,aAAa,UAAU;AACjD;AAEA,SAAS,QAAQ,OAAwB;AACvC,SAAO,OAAO,UAAU,SAAS,KAA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