@fluixi/utils 1.0.0-alpha.100
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/LICENSE +21 -0
- package/README.md +68 -0
- package/dist/index.cjs +2858 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -0
- package/dist/index.mjs +2838 -0
- package/dist/lib/array/advanced.cjs +2227 -0
- package/dist/lib/array/advanced.d.ts +1116 -0
- package/dist/lib/array/advanced.d.ts.map +1 -0
- package/dist/lib/array/advanced.js +2429 -0
- package/dist/lib/array/advanced.mjs +2204 -0
- package/dist/lib/array/array.cjs +57 -0
- package/dist/lib/array/array.d.ts +6 -0
- package/dist/lib/array/array.d.ts.map +1 -0
- package/dist/lib/array/array.js +31 -0
- package/dist/lib/array/array.mjs +36 -0
- package/dist/lib/array/index.cjs +2344 -0
- package/dist/lib/array/index.d.ts +4 -0
- package/dist/lib/array/index.d.ts.map +1 -0
- package/dist/lib/array/index.js +3 -0
- package/dist/lib/array/index.mjs +2322 -0
- package/dist/lib/array/utils.cjs +103 -0
- package/dist/lib/array/utils.d.ts +100 -0
- package/dist/lib/array/utils.d.ts.map +1 -0
- package/dist/lib/array/utils.js +165 -0
- package/dist/lib/array/utils.mjs +82 -0
- package/dist/lib/color/color.cjs +2190 -0
- package/dist/lib/color/color.d.ts +366 -0
- package/dist/lib/color/color.d.ts.map +1 -0
- package/dist/lib/color/color.js +722 -0
- package/dist/lib/color/color.mjs +2167 -0
- package/dist/lib/color/constants.cjs +380 -0
- package/dist/lib/color/constants.d.ts +361 -0
- package/dist/lib/color/constants.d.ts.map +1 -0
- package/dist/lib/color/constants.js +358 -0
- package/dist/lib/color/constants.mjs +359 -0
- package/dist/lib/color/conversions.cjs +629 -0
- package/dist/lib/color/conversions.d.ts +166 -0
- package/dist/lib/color/conversions.d.ts.map +1 -0
- package/dist/lib/color/conversions.js +766 -0
- package/dist/lib/color/conversions.mjs +608 -0
- package/dist/lib/color/helpers.cjs +2534 -0
- package/dist/lib/color/helpers.d.ts +75 -0
- package/dist/lib/color/helpers.d.ts.map +1 -0
- package/dist/lib/color/helpers.js +419 -0
- package/dist/lib/color/helpers.mjs +2511 -0
- package/dist/lib/color/index.cjs +2641 -0
- package/dist/lib/color/index.d.ts +12 -0
- package/dist/lib/color/index.d.ts.map +1 -0
- package/dist/lib/color/index.js +15 -0
- package/dist/lib/color/index.mjs +2619 -0
- package/dist/lib/color/types.cjs +18 -0
- package/dist/lib/color/types.d.ts +179 -0
- package/dist/lib/color/types.d.ts.map +1 -0
- package/dist/lib/color/types.js +1 -0
- package/dist/lib/color/types.mjs +0 -0
- package/dist/lib/color/utils.cjs +962 -0
- package/dist/lib/color/utils.d.ts +199 -0
- package/dist/lib/color/utils.d.ts.map +1 -0
- package/dist/lib/color/utils.js +858 -0
- package/dist/lib/color/utils.mjs +939 -0
- package/dist/lib/compare/comparators.cjs +171 -0
- package/dist/lib/compare/comparators.d.ts +65 -0
- package/dist/lib/compare/comparators.d.ts.map +1 -0
- package/dist/lib/compare/comparators.js +210 -0
- package/dist/lib/compare/comparators.mjs +150 -0
- package/dist/lib/compare/index.cjs +172 -0
- package/dist/lib/compare/index.d.ts +2 -0
- package/dist/lib/compare/index.d.ts.map +1 -0
- package/dist/lib/compare/index.js +1 -0
- package/dist/lib/compare/index.mjs +152 -0
- package/dist/lib/cookie/codec.cjs +72 -0
- package/dist/lib/cookie/codec.d.ts +22 -0
- package/dist/lib/cookie/codec.d.ts.map +1 -0
- package/dist/lib/cookie/codec.js +67 -0
- package/dist/lib/cookie/codec.mjs +51 -0
- package/dist/lib/cookie/index.cjs +75 -0
- package/dist/lib/cookie/index.d.ts +2 -0
- package/dist/lib/cookie/index.d.ts.map +1 -0
- package/dist/lib/cookie/index.js +1 -0
- package/dist/lib/cookie/index.mjs +53 -0
- package/dist/lib/crypto/hash.cjs +83 -0
- package/dist/lib/crypto/hash.d.ts +6 -0
- package/dist/lib/crypto/hash.d.ts.map +1 -0
- package/dist/lib/crypto/hash.js +53 -0
- package/dist/lib/crypto/hash.mjs +62 -0
- package/dist/lib/crypto/index.cjs +85 -0
- package/dist/lib/crypto/index.d.ts +2 -0
- package/dist/lib/crypto/index.d.ts.map +1 -0
- package/dist/lib/crypto/index.js +1 -0
- package/dist/lib/crypto/index.mjs +62 -0
- package/dist/lib/dom/events.cjs +40 -0
- package/dist/lib/dom/events.d.ts +159 -0
- package/dist/lib/dom/events.d.ts.map +1 -0
- package/dist/lib/dom/events.js +50 -0
- package/dist/lib/dom/events.mjs +19 -0
- package/dist/lib/dom/index.cjs +78 -0
- package/dist/lib/dom/index.d.ts +3 -0
- package/dist/lib/dom/index.d.ts.map +1 -0
- package/dist/lib/dom/index.js +2 -0
- package/dist/lib/dom/index.mjs +56 -0
- package/dist/lib/dom/utils.cjs +57 -0
- package/dist/lib/dom/utils.d.ts +6 -0
- package/dist/lib/dom/utils.d.ts.map +1 -0
- package/dist/lib/dom/utils.js +37 -0
- package/dist/lib/dom/utils.mjs +36 -0
- package/dist/lib/functions/functions.cjs +366 -0
- package/dist/lib/functions/functions.d.ts +329 -0
- package/dist/lib/functions/functions.d.ts.map +1 -0
- package/dist/lib/functions/functions.js +585 -0
- package/dist/lib/functions/functions.mjs +345 -0
- package/dist/lib/functions/index.cjs +369 -0
- package/dist/lib/functions/index.d.ts +3 -0
- package/dist/lib/functions/index.d.ts.map +1 -0
- package/dist/lib/functions/index.js +1 -0
- package/dist/lib/functions/index.mjs +347 -0
- package/dist/lib/functions/types.cjs +18 -0
- package/dist/lib/functions/types.d.ts +2 -0
- package/dist/lib/functions/types.d.ts.map +1 -0
- package/dist/lib/functions/types.js +1 -0
- package/dist/lib/functions/types.mjs +0 -0
- package/dist/lib/helpers.cjs +78 -0
- package/dist/lib/helpers.d.ts +13 -0
- package/dist/lib/helpers.d.ts.map +1 -0
- package/dist/lib/helpers.js +66 -0
- package/dist/lib/helpers.mjs +59 -0
- package/dist/lib/index.cjs +2857 -0
- package/dist/lib/index.d.ts +6 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/index.js +8 -0
- package/dist/lib/index.mjs +2836 -0
- package/dist/lib/maths/constants.cjs +70 -0
- package/dist/lib/maths/constants.d.ts +84 -0
- package/dist/lib/maths/constants.d.ts.map +1 -0
- package/dist/lib/maths/constants.js +79 -0
- package/dist/lib/maths/constants.mjs +50 -0
- package/dist/lib/maths/fn/advanced.cjs +231 -0
- package/dist/lib/maths/fn/advanced.d.ts +149 -0
- package/dist/lib/maths/fn/advanced.d.ts.map +1 -0
- package/dist/lib/maths/fn/advanced.js +264 -0
- package/dist/lib/maths/fn/advanced.mjs +208 -0
- package/dist/lib/maths/fn/basic.cjs +212 -0
- package/dist/lib/maths/fn/basic.d.ts +182 -0
- package/dist/lib/maths/fn/basic.d.ts.map +1 -0
- package/dist/lib/maths/fn/basic.js +343 -0
- package/dist/lib/maths/fn/basic.mjs +191 -0
- package/dist/lib/maths/fn/complex.cjs +268 -0
- package/dist/lib/maths/fn/complex.d.ts +153 -0
- package/dist/lib/maths/fn/complex.d.ts.map +1 -0
- package/dist/lib/maths/fn/complex.js +383 -0
- package/dist/lib/maths/fn/complex.mjs +247 -0
- package/dist/lib/maths/fn/index.cjs +877 -0
- package/dist/lib/maths/fn/index.d.ts +10 -0
- package/dist/lib/maths/fn/index.d.ts.map +1 -0
- package/dist/lib/maths/fn/index.js +9 -0
- package/dist/lib/maths/fn/index.mjs +855 -0
- package/dist/lib/maths/fn/trigo.cjs +179 -0
- package/dist/lib/maths/fn/trigo.d.ts +147 -0
- package/dist/lib/maths/fn/trigo.d.ts.map +1 -0
- package/dist/lib/maths/fn/trigo.js +227 -0
- package/dist/lib/maths/fn/trigo.mjs +156 -0
- package/dist/lib/maths/fn/vector.cjs +728 -0
- package/dist/lib/maths/fn/vector.d.ts +512 -0
- package/dist/lib/maths/fn/vector.d.ts.map +1 -0
- package/dist/lib/maths/fn/vector.js +1136 -0
- package/dist/lib/maths/fn/vector.mjs +707 -0
- package/dist/lib/maths/formatter.cjs +61 -0
- package/dist/lib/maths/formatter.d.ts +35 -0
- package/dist/lib/maths/formatter.d.ts.map +1 -0
- package/dist/lib/maths/formatter.js +56 -0
- package/dist/lib/maths/formatter.mjs +40 -0
- package/dist/lib/maths/guards.cjs +164 -0
- package/dist/lib/maths/guards.d.ts +166 -0
- package/dist/lib/maths/guards.d.ts.map +1 -0
- package/dist/lib/maths/guards.js +315 -0
- package/dist/lib/maths/guards.mjs +144 -0
- package/dist/lib/maths/index.cjs +1152 -0
- package/dist/lib/maths/index.d.ts +24 -0
- package/dist/lib/maths/index.d.ts.map +1 -0
- package/dist/lib/maths/index.js +29 -0
- package/dist/lib/maths/index.mjs +1130 -0
- package/dist/lib/maths/parser.cjs +75 -0
- package/dist/lib/maths/parser.d.ts +20 -0
- package/dist/lib/maths/parser.d.ts.map +1 -0
- package/dist/lib/maths/parser.js +78 -0
- package/dist/lib/maths/parser.mjs +54 -0
- package/dist/lib/maths/random.cjs +49 -0
- package/dist/lib/maths/random.d.ts +27 -0
- package/dist/lib/maths/random.d.ts.map +1 -0
- package/dist/lib/maths/random.js +49 -0
- package/dist/lib/maths/random.mjs +28 -0
- package/dist/lib/maths/types/advanced.cjs +18 -0
- package/dist/lib/maths/types/advanced.d.ts +357 -0
- package/dist/lib/maths/types/advanced.d.ts.map +1 -0
- package/dist/lib/maths/types/advanced.js +5 -0
- package/dist/lib/maths/types/advanced.mjs +0 -0
- package/dist/lib/maths/types/basic.cjs +18 -0
- package/dist/lib/maths/types/basic.d.ts +95 -0
- package/dist/lib/maths/types/basic.d.ts.map +1 -0
- package/dist/lib/maths/types/basic.js +5 -0
- package/dist/lib/maths/types/basic.mjs +0 -0
- package/dist/lib/maths/types/index.cjs +19 -0
- package/dist/lib/maths/types/index.d.ts +4 -0
- package/dist/lib/maths/types/index.d.ts.map +1 -0
- package/dist/lib/maths/types/index.js +3 -0
- package/dist/lib/maths/types/index.mjs +1 -0
- package/dist/lib/maths/types/negative.cjs +18 -0
- package/dist/lib/maths/types/negative.d.ts +51 -0
- package/dist/lib/maths/types/negative.d.ts.map +1 -0
- package/dist/lib/maths/types/negative.js +5 -0
- package/dist/lib/maths/types/negative.mjs +0 -0
- package/dist/lib/maths/types/operations.cjs +18 -0
- package/dist/lib/maths/types/operations.d.ts +188 -0
- package/dist/lib/maths/types/operations.d.ts.map +1 -0
- package/dist/lib/maths/types/operations.js +6 -0
- package/dist/lib/maths/types/operations.mjs +0 -0
- package/dist/lib/object/clone.cjs +88 -0
- package/dist/lib/object/clone.d.ts +46 -0
- package/dist/lib/object/clone.d.ts.map +1 -0
- package/dist/lib/object/clone.js +104 -0
- package/dist/lib/object/clone.mjs +65 -0
- package/dist/lib/object/diff.cjs +573 -0
- package/dist/lib/object/diff.d.ts +203 -0
- package/dist/lib/object/diff.d.ts.map +1 -0
- package/dist/lib/object/diff.js +805 -0
- package/dist/lib/object/diff.mjs +550 -0
- package/dist/lib/object/getter-setter.cjs +2351 -0
- package/dist/lib/object/getter-setter.d.ts +361 -0
- package/dist/lib/object/getter-setter.d.ts.map +1 -0
- package/dist/lib/object/getter-setter.js +1771 -0
- package/dist/lib/object/getter-setter.mjs +2330 -0
- package/dist/lib/object/index.cjs +3956 -0
- package/dist/lib/object/index.d.ts +13 -0
- package/dist/lib/object/index.d.ts.map +1 -0
- package/dist/lib/object/index.js +12 -0
- package/dist/lib/object/index.mjs +3936 -0
- package/dist/lib/object/merge.cjs +1029 -0
- package/dist/lib/object/merge.d.ts +93 -0
- package/dist/lib/object/merge.d.ts.map +1 -0
- package/dist/lib/object/merge.js +474 -0
- package/dist/lib/object/merge.mjs +1006 -0
- package/dist/lib/object/object.cjs +280 -0
- package/dist/lib/object/object.d.ts +128 -0
- package/dist/lib/object/object.d.ts.map +1 -0
- package/dist/lib/object/object.js +432 -0
- package/dist/lib/object/object.mjs +257 -0
- package/dist/lib/object/omit.cjs +2022 -0
- package/dist/lib/object/omit.d.ts +351 -0
- package/dist/lib/object/omit.d.ts.map +1 -0
- package/dist/lib/object/omit.js +656 -0
- package/dist/lib/object/omit.mjs +1999 -0
- package/dist/lib/object/reconcile.cjs +126 -0
- package/dist/lib/object/reconcile.d.ts +7 -0
- package/dist/lib/object/reconcile.d.ts.map +1 -0
- package/dist/lib/object/reconcile.js +122 -0
- package/dist/lib/object/reconcile.mjs +105 -0
- package/dist/lib/object/selector.cjs +303 -0
- package/dist/lib/object/selector.d.ts +50 -0
- package/dist/lib/object/selector.d.ts.map +1 -0
- package/dist/lib/object/selector.js +371 -0
- package/dist/lib/object/selector.mjs +282 -0
- package/dist/lib/object/sort.cjs +209 -0
- package/dist/lib/object/sort.d.ts +149 -0
- package/dist/lib/object/sort.d.ts.map +1 -0
- package/dist/lib/object/sort.js +298 -0
- package/dist/lib/object/sort.mjs +186 -0
- package/dist/lib/object/transform.cjs +2211 -0
- package/dist/lib/object/transform.d.ts +620 -0
- package/dist/lib/object/transform.d.ts.map +1 -0
- package/dist/lib/object/transform.js +1058 -0
- package/dist/lib/object/transform.mjs +2190 -0
- package/dist/lib/object/types.cjs +18 -0
- package/dist/lib/object/types.d.ts +250 -0
- package/dist/lib/object/types.d.ts.map +1 -0
- package/dist/lib/object/types.js +1 -0
- package/dist/lib/object/types.mjs +0 -0
- package/dist/lib/object/utils.cjs +326 -0
- package/dist/lib/object/utils.d.ts +165 -0
- package/dist/lib/object/utils.d.ts.map +1 -0
- package/dist/lib/object/utils.js +444 -0
- package/dist/lib/object/utils.mjs +305 -0
- package/dist/lib/primitive/boolean/boolean.cjs +407 -0
- package/dist/lib/primitive/boolean/boolean.d.ts +276 -0
- package/dist/lib/primitive/boolean/boolean.d.ts.map +1 -0
- package/dist/lib/primitive/boolean/boolean.js +615 -0
- package/dist/lib/primitive/boolean/boolean.mjs +386 -0
- package/dist/lib/primitive/boolean/index.cjs +382 -0
- package/dist/lib/primitive/boolean/index.d.ts +3 -0
- package/dist/lib/primitive/boolean/index.d.ts.map +1 -0
- package/dist/lib/primitive/boolean/index.js +2 -0
- package/dist/lib/primitive/boolean/index.mjs +359 -0
- package/dist/lib/primitive/boolean/types.cjs +18 -0
- package/dist/lib/primitive/boolean/types.d.ts +14 -0
- package/dist/lib/primitive/boolean/types.d.ts.map +1 -0
- package/dist/lib/primitive/boolean/types.js +1 -0
- package/dist/lib/primitive/boolean/types.mjs +0 -0
- package/dist/lib/primitive/date/date.cjs +1126 -0
- package/dist/lib/primitive/date/date.d.ts +641 -0
- package/dist/lib/primitive/date/date.d.ts.map +1 -0
- package/dist/lib/primitive/date/date.js +1998 -0
- package/dist/lib/primitive/date/date.mjs +1105 -0
- package/dist/lib/primitive/date/index.cjs +1128 -0
- package/dist/lib/primitive/date/index.d.ts +3 -0
- package/dist/lib/primitive/date/index.d.ts.map +1 -0
- package/dist/lib/primitive/date/index.js +2 -0
- package/dist/lib/primitive/date/index.mjs +1105 -0
- package/dist/lib/primitive/date/types.cjs +18 -0
- package/dist/lib/primitive/date/types.d.ts +205 -0
- package/dist/lib/primitive/date/types.d.ts.map +1 -0
- package/dist/lib/primitive/date/types.js +7 -0
- package/dist/lib/primitive/date/types.mjs +0 -0
- package/dist/lib/primitive/index.cjs +2338 -0
- package/dist/lib/primitive/index.d.ts +5 -0
- package/dist/lib/primitive/index.d.ts.map +1 -0
- package/dist/lib/primitive/index.js +4 -0
- package/dist/lib/primitive/index.mjs +2316 -0
- package/dist/lib/primitive/string/index.cjs +875 -0
- package/dist/lib/primitive/string/index.d.ts +3 -0
- package/dist/lib/primitive/string/index.d.ts.map +1 -0
- package/dist/lib/primitive/string/index.js +2 -0
- package/dist/lib/primitive/string/index.mjs +852 -0
- package/dist/lib/primitive/string/parser-2.cjs +543 -0
- package/dist/lib/primitive/string/parser-2.d.ts +17 -0
- package/dist/lib/primitive/string/parser-2.d.ts.map +1 -0
- package/dist/lib/primitive/string/parser-2.js +656 -0
- package/dist/lib/primitive/string/parser-2.mjs +522 -0
- package/dist/lib/primitive/string/parser.cjs +236 -0
- package/dist/lib/primitive/string/parser.d.ts +9 -0
- package/dist/lib/primitive/string/parser.d.ts.map +1 -0
- package/dist/lib/primitive/string/parser.js +775 -0
- package/dist/lib/primitive/string/parser.mjs +215 -0
- package/dist/lib/primitive/string/string.cjs +926 -0
- package/dist/lib/primitive/string/string.d.ts +535 -0
- package/dist/lib/primitive/string/string.d.ts.map +1 -0
- package/dist/lib/primitive/string/string.js +1301 -0
- package/dist/lib/primitive/string/string.mjs +903 -0
- package/dist/lib/primitive/string/types.cjs +18 -0
- package/dist/lib/primitive/string/types.d.ts +318 -0
- package/dist/lib/primitive/string/types.d.ts.map +1 -0
- package/dist/lib/primitive/string/types.js +5 -0
- package/dist/lib/primitive/string/types.mjs +0 -0
- package/dist/lib/primitive/types.cjs +18 -0
- package/dist/lib/primitive/types.d.ts +27 -0
- package/dist/lib/primitive/types.d.ts.map +1 -0
- package/dist/lib/primitive/types.js +1 -0
- package/dist/lib/primitive/types.mjs +0 -0
- package/dist/lib/url/index.cjs +327 -0
- package/dist/lib/url/index.d.ts +3 -0
- package/dist/lib/url/index.d.ts.map +1 -0
- package/dist/lib/url/index.js +2 -0
- package/dist/lib/url/index.mjs +304 -0
- package/dist/lib/url/parser.cjs +325 -0
- package/dist/lib/url/parser.d.ts +216 -0
- package/dist/lib/url/parser.d.ts.map +1 -0
- package/dist/lib/url/parser.js +488 -0
- package/dist/lib/url/parser.mjs +304 -0
- package/dist/lib/url/types.cjs +18 -0
- package/dist/lib/url/types.d.ts +18 -0
- package/dist/lib/url/types.d.ts.map +1 -0
- package/dist/lib/url/types.js +1 -0
- package/dist/lib/url/types.mjs +0 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -0
- package/package.json +127 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/*! @fluixi/utils v1.0.0-alpha.100 | (c) 2026 Ibrahima Touré and Fluixi contributors | MIT */
|
|
2
|
+
|
|
3
|
+
// src/lib/cookie/codec.ts
|
|
4
|
+
var NAME = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;
|
|
5
|
+
function isValidCookieName(name) {
|
|
6
|
+
return NAME.test(name);
|
|
7
|
+
}
|
|
8
|
+
function decode(value) {
|
|
9
|
+
try {
|
|
10
|
+
return decodeURIComponent(value);
|
|
11
|
+
} catch {
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function parseCookies(header) {
|
|
16
|
+
const out = {};
|
|
17
|
+
if (!header) return out;
|
|
18
|
+
for (const part of header.split(";")) {
|
|
19
|
+
const eq = part.indexOf("=");
|
|
20
|
+
if (eq < 0) continue;
|
|
21
|
+
const k = part.slice(0, eq).trim();
|
|
22
|
+
if (!k || k in out) continue;
|
|
23
|
+
let v = part.slice(eq + 1).trim();
|
|
24
|
+
if (v.length > 1 && v[0] === '"' && v[v.length - 1] === '"') v = v.slice(1, -1);
|
|
25
|
+
out[k] = decode(v);
|
|
26
|
+
}
|
|
27
|
+
return out;
|
|
28
|
+
}
|
|
29
|
+
function serializeCookie(name, value, opts = {}) {
|
|
30
|
+
if (!isValidCookieName(name)) throw new TypeError(`Invalid cookie name: ${JSON.stringify(name)}`);
|
|
31
|
+
const o = { path: "/", httpOnly: true, secure: true, sameSite: "lax", ...opts };
|
|
32
|
+
if (o.domain && /[;\s]/.test(o.domain)) throw new TypeError(`Invalid cookie domain: ${o.domain}`);
|
|
33
|
+
if (/[;\s]/.test(o.path)) throw new TypeError(`Invalid cookie path: ${o.path}`);
|
|
34
|
+
const secure = o.secure || o.sameSite === "none";
|
|
35
|
+
let s = `${name}=${encodeURIComponent(value)}`;
|
|
36
|
+
if (o.maxAge != null) s += `; Max-Age=${Math.floor(o.maxAge)}`;
|
|
37
|
+
if (o.expires) s += `; Expires=${o.expires.toUTCString()}`;
|
|
38
|
+
if (o.domain) s += `; Domain=${o.domain}`;
|
|
39
|
+
s += `; Path=${o.path}`;
|
|
40
|
+
if (o.httpOnly) s += "; HttpOnly";
|
|
41
|
+
if (secure) s += "; Secure";
|
|
42
|
+
s += `; SameSite=${o.sameSite[0].toUpperCase()}${o.sameSite.slice(1)}`;
|
|
43
|
+
return s;
|
|
44
|
+
}
|
|
45
|
+
function deleteCookie(name, opts = {}) {
|
|
46
|
+
return serializeCookie(name, "", { ...opts, maxAge: 0, expires: /* @__PURE__ */ new Date(0) });
|
|
47
|
+
}
|
|
48
|
+
export {
|
|
49
|
+
deleteCookie,
|
|
50
|
+
isValidCookieName,
|
|
51
|
+
parseCookies,
|
|
52
|
+
serializeCookie
|
|
53
|
+
};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/lib/crypto/hash.ts
|
|
21
|
+
var hash_exports = {};
|
|
22
|
+
__export(hash_exports, {
|
|
23
|
+
compareWithHash: () => compareWithHash,
|
|
24
|
+
createHash: () => createHash,
|
|
25
|
+
hash: () => hash,
|
|
26
|
+
hashStringPromise: () => hashStringPromise,
|
|
27
|
+
string_hash: () => string_hash
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(hash_exports);
|
|
30
|
+
var createHash = async (value, algorithm = "SHA-1") => {
|
|
31
|
+
if (typeof window === "undefined") return null;
|
|
32
|
+
const { subtle } = window.globalThis.crypto;
|
|
33
|
+
const key = await subtle.generateKey(
|
|
34
|
+
{
|
|
35
|
+
name: "HMAC",
|
|
36
|
+
hash: algorithm,
|
|
37
|
+
length: 256
|
|
38
|
+
},
|
|
39
|
+
true,
|
|
40
|
+
["sign", "verify"]
|
|
41
|
+
);
|
|
42
|
+
const enc = new TextEncoder();
|
|
43
|
+
const message = enc.encode(value);
|
|
44
|
+
const digest = await subtle.sign(
|
|
45
|
+
{
|
|
46
|
+
name: "HMAC"
|
|
47
|
+
},
|
|
48
|
+
key,
|
|
49
|
+
message
|
|
50
|
+
);
|
|
51
|
+
const hex = [...new Uint8Array(digest)].map((x) => x.toString(16).padStart(2, "0")).join("");
|
|
52
|
+
return hex;
|
|
53
|
+
};
|
|
54
|
+
var hash = async (value, algorithm = "SHA-256") => {
|
|
55
|
+
const encoder = new TextEncoder();
|
|
56
|
+
const data = encoder.encode(value);
|
|
57
|
+
const hashBuffer = await crypto.subtle.digest(algorithm, data);
|
|
58
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
59
|
+
const hashHex = hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
60
|
+
return hashHex;
|
|
61
|
+
};
|
|
62
|
+
var compareWithHash = async (value1, value2, algorithm = "SHA-256") => {
|
|
63
|
+
const hash1 = await hash(value1, algorithm);
|
|
64
|
+
const hash2 = await hash(value2, algorithm);
|
|
65
|
+
return hash1 === hash2;
|
|
66
|
+
};
|
|
67
|
+
async function hashStringPromise(value, algorithm = "SHA-256") {
|
|
68
|
+
const encoder = new TextEncoder();
|
|
69
|
+
const data = encoder.encode(value);
|
|
70
|
+
const hashBuffer = await crypto.subtle.digest(algorithm, data);
|
|
71
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
72
|
+
const hashHex = hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
73
|
+
return hashHex;
|
|
74
|
+
}
|
|
75
|
+
var string_hash = (str) => {
|
|
76
|
+
let hash2 = 0;
|
|
77
|
+
for (let i = 0; i < str.length; i++) {
|
|
78
|
+
const char = str.charCodeAt(i);
|
|
79
|
+
hash2 = (hash2 << 5) - hash2 + char;
|
|
80
|
+
hash2 = hash2 & hash2;
|
|
81
|
+
}
|
|
82
|
+
return hash2.toString(16);
|
|
83
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const createHash: (value: any, algorithm?: string) => Promise<string | null>;
|
|
2
|
+
export declare const hash: (value: string, algorithm?: string) => Promise<string>;
|
|
3
|
+
export declare const compareWithHash: (value1: string, value2: string, algorithm?: string) => Promise<boolean>;
|
|
4
|
+
export declare function hashStringPromise(value: string, algorithm?: string): Promise<string>;
|
|
5
|
+
export declare const string_hash: (str: string) => string;
|
|
6
|
+
//# sourceMappingURL=hash.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../../src/lib/crypto/hash.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU,GAAU,OAAO,GAAG,EAAE,YAAW,MAAgB,2BA2BvE,CAAC;AAEF,eAAO,MAAM,IAAI,GAAU,OAAO,MAAM,EAAE,kBAAqB,oBAS9D,CAAC;AAEF,eAAO,MAAM,eAAe,GAC1B,QAAQ,MAAM,EACd,QAAQ,MAAM,EACd,kBAAqB,qBAKtB,CAAC;AAGF,wBAAsB,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,SAAY,mBAS3E;AAED,eAAO,MAAM,WAAW,GAAI,KAAK,MAAM,WAQtC,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export const createHash = async (value, algorithm = 'SHA-1') => {
|
|
2
|
+
if (typeof window === 'undefined')
|
|
3
|
+
return null;
|
|
4
|
+
const { subtle } = window.globalThis.crypto;
|
|
5
|
+
const key = await subtle.generateKey({
|
|
6
|
+
name: 'HMAC',
|
|
7
|
+
hash: algorithm,
|
|
8
|
+
length: 256,
|
|
9
|
+
}, true, ['sign', 'verify']);
|
|
10
|
+
const enc = new TextEncoder();
|
|
11
|
+
const message = enc.encode(value);
|
|
12
|
+
const digest = await subtle.sign({
|
|
13
|
+
name: 'HMAC',
|
|
14
|
+
}, key, message);
|
|
15
|
+
const hex = [...new Uint8Array(digest)]
|
|
16
|
+
.map((x) => x.toString(16).padStart(2, '0'))
|
|
17
|
+
.join('');
|
|
18
|
+
return hex;
|
|
19
|
+
};
|
|
20
|
+
export const hash = async (value, algorithm = 'SHA-256') => {
|
|
21
|
+
const encoder = new TextEncoder();
|
|
22
|
+
const data = encoder.encode(value);
|
|
23
|
+
const hashBuffer = await crypto.subtle.digest(algorithm, data);
|
|
24
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
25
|
+
const hashHex = hashArray
|
|
26
|
+
.map((b) => b.toString(16).padStart(2, '0'))
|
|
27
|
+
.join('');
|
|
28
|
+
return hashHex;
|
|
29
|
+
};
|
|
30
|
+
export const compareWithHash = async (value1, value2, algorithm = 'SHA-256') => {
|
|
31
|
+
const hash1 = await hash(value1, algorithm);
|
|
32
|
+
const hash2 = await hash(value2, algorithm);
|
|
33
|
+
return hash1 === hash2;
|
|
34
|
+
};
|
|
35
|
+
export async function hashStringPromise(value, algorithm = 'SHA-256') {
|
|
36
|
+
const encoder = new TextEncoder();
|
|
37
|
+
const data = encoder.encode(value);
|
|
38
|
+
const hashBuffer = await crypto.subtle.digest(algorithm, data);
|
|
39
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
40
|
+
const hashHex = hashArray
|
|
41
|
+
.map((b) => b.toString(16).padStart(2, '0'))
|
|
42
|
+
.join('');
|
|
43
|
+
return hashHex;
|
|
44
|
+
}
|
|
45
|
+
export const string_hash = (str) => {
|
|
46
|
+
let hash = 0;
|
|
47
|
+
for (let i = 0; i < str.length; i++) {
|
|
48
|
+
const char = str.charCodeAt(i);
|
|
49
|
+
hash = (hash << 5) - hash + char;
|
|
50
|
+
hash = hash & hash; // Convert to 32bit integer
|
|
51
|
+
}
|
|
52
|
+
return hash.toString(16);
|
|
53
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// src/lib/crypto/hash.ts
|
|
2
|
+
var createHash = async (value, algorithm = "SHA-1") => {
|
|
3
|
+
if (typeof window === "undefined") return null;
|
|
4
|
+
const { subtle } = window.globalThis.crypto;
|
|
5
|
+
const key = await subtle.generateKey(
|
|
6
|
+
{
|
|
7
|
+
name: "HMAC",
|
|
8
|
+
hash: algorithm,
|
|
9
|
+
length: 256
|
|
10
|
+
},
|
|
11
|
+
true,
|
|
12
|
+
["sign", "verify"]
|
|
13
|
+
);
|
|
14
|
+
const enc = new TextEncoder();
|
|
15
|
+
const message = enc.encode(value);
|
|
16
|
+
const digest = await subtle.sign(
|
|
17
|
+
{
|
|
18
|
+
name: "HMAC"
|
|
19
|
+
},
|
|
20
|
+
key,
|
|
21
|
+
message
|
|
22
|
+
);
|
|
23
|
+
const hex = [...new Uint8Array(digest)].map((x) => x.toString(16).padStart(2, "0")).join("");
|
|
24
|
+
return hex;
|
|
25
|
+
};
|
|
26
|
+
var hash = async (value, algorithm = "SHA-256") => {
|
|
27
|
+
const encoder = new TextEncoder();
|
|
28
|
+
const data = encoder.encode(value);
|
|
29
|
+
const hashBuffer = await crypto.subtle.digest(algorithm, data);
|
|
30
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
31
|
+
const hashHex = hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
32
|
+
return hashHex;
|
|
33
|
+
};
|
|
34
|
+
var compareWithHash = async (value1, value2, algorithm = "SHA-256") => {
|
|
35
|
+
const hash1 = await hash(value1, algorithm);
|
|
36
|
+
const hash2 = await hash(value2, algorithm);
|
|
37
|
+
return hash1 === hash2;
|
|
38
|
+
};
|
|
39
|
+
async function hashStringPromise(value, algorithm = "SHA-256") {
|
|
40
|
+
const encoder = new TextEncoder();
|
|
41
|
+
const data = encoder.encode(value);
|
|
42
|
+
const hashBuffer = await crypto.subtle.digest(algorithm, data);
|
|
43
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
44
|
+
const hashHex = hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
45
|
+
return hashHex;
|
|
46
|
+
}
|
|
47
|
+
var string_hash = (str) => {
|
|
48
|
+
let hash2 = 0;
|
|
49
|
+
for (let i = 0; i < str.length; i++) {
|
|
50
|
+
const char = str.charCodeAt(i);
|
|
51
|
+
hash2 = (hash2 << 5) - hash2 + char;
|
|
52
|
+
hash2 = hash2 & hash2;
|
|
53
|
+
}
|
|
54
|
+
return hash2.toString(16);
|
|
55
|
+
};
|
|
56
|
+
export {
|
|
57
|
+
compareWithHash,
|
|
58
|
+
createHash,
|
|
59
|
+
hash,
|
|
60
|
+
hashStringPromise,
|
|
61
|
+
string_hash
|
|
62
|
+
};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/lib/crypto/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
compareWithHash: () => compareWithHash,
|
|
24
|
+
createHash: () => createHash,
|
|
25
|
+
hash: () => hash,
|
|
26
|
+
hashStringPromise: () => hashStringPromise,
|
|
27
|
+
string_hash: () => string_hash
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(index_exports);
|
|
30
|
+
|
|
31
|
+
// src/lib/crypto/hash.ts
|
|
32
|
+
var createHash = async (value, algorithm = "SHA-1") => {
|
|
33
|
+
if (typeof window === "undefined") return null;
|
|
34
|
+
const { subtle } = window.globalThis.crypto;
|
|
35
|
+
const key = await subtle.generateKey(
|
|
36
|
+
{
|
|
37
|
+
name: "HMAC",
|
|
38
|
+
hash: algorithm,
|
|
39
|
+
length: 256
|
|
40
|
+
},
|
|
41
|
+
true,
|
|
42
|
+
["sign", "verify"]
|
|
43
|
+
);
|
|
44
|
+
const enc = new TextEncoder();
|
|
45
|
+
const message = enc.encode(value);
|
|
46
|
+
const digest = await subtle.sign(
|
|
47
|
+
{
|
|
48
|
+
name: "HMAC"
|
|
49
|
+
},
|
|
50
|
+
key,
|
|
51
|
+
message
|
|
52
|
+
);
|
|
53
|
+
const hex = [...new Uint8Array(digest)].map((x) => x.toString(16).padStart(2, "0")).join("");
|
|
54
|
+
return hex;
|
|
55
|
+
};
|
|
56
|
+
var hash = async (value, algorithm = "SHA-256") => {
|
|
57
|
+
const encoder = new TextEncoder();
|
|
58
|
+
const data = encoder.encode(value);
|
|
59
|
+
const hashBuffer = await crypto.subtle.digest(algorithm, data);
|
|
60
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
61
|
+
const hashHex = hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
62
|
+
return hashHex;
|
|
63
|
+
};
|
|
64
|
+
var compareWithHash = async (value1, value2, algorithm = "SHA-256") => {
|
|
65
|
+
const hash1 = await hash(value1, algorithm);
|
|
66
|
+
const hash2 = await hash(value2, algorithm);
|
|
67
|
+
return hash1 === hash2;
|
|
68
|
+
};
|
|
69
|
+
async function hashStringPromise(value, algorithm = "SHA-256") {
|
|
70
|
+
const encoder = new TextEncoder();
|
|
71
|
+
const data = encoder.encode(value);
|
|
72
|
+
const hashBuffer = await crypto.subtle.digest(algorithm, data);
|
|
73
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
74
|
+
const hashHex = hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
75
|
+
return hashHex;
|
|
76
|
+
}
|
|
77
|
+
var string_hash = (str) => {
|
|
78
|
+
let hash2 = 0;
|
|
79
|
+
for (let i = 0; i < str.length; i++) {
|
|
80
|
+
const char = str.charCodeAt(i);
|
|
81
|
+
hash2 = (hash2 << 5) - hash2 + char;
|
|
82
|
+
hash2 = hash2 & hash2;
|
|
83
|
+
}
|
|
84
|
+
return hash2.toString(16);
|
|
85
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/crypto/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './hash.js';
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// src/lib/crypto/hash.ts
|
|
2
|
+
var createHash = async (value, algorithm = "SHA-1") => {
|
|
3
|
+
if (typeof window === "undefined") return null;
|
|
4
|
+
const { subtle } = window.globalThis.crypto;
|
|
5
|
+
const key = await subtle.generateKey(
|
|
6
|
+
{
|
|
7
|
+
name: "HMAC",
|
|
8
|
+
hash: algorithm,
|
|
9
|
+
length: 256
|
|
10
|
+
},
|
|
11
|
+
true,
|
|
12
|
+
["sign", "verify"]
|
|
13
|
+
);
|
|
14
|
+
const enc = new TextEncoder();
|
|
15
|
+
const message = enc.encode(value);
|
|
16
|
+
const digest = await subtle.sign(
|
|
17
|
+
{
|
|
18
|
+
name: "HMAC"
|
|
19
|
+
},
|
|
20
|
+
key,
|
|
21
|
+
message
|
|
22
|
+
);
|
|
23
|
+
const hex = [...new Uint8Array(digest)].map((x) => x.toString(16).padStart(2, "0")).join("");
|
|
24
|
+
return hex;
|
|
25
|
+
};
|
|
26
|
+
var hash = async (value, algorithm = "SHA-256") => {
|
|
27
|
+
const encoder = new TextEncoder();
|
|
28
|
+
const data = encoder.encode(value);
|
|
29
|
+
const hashBuffer = await crypto.subtle.digest(algorithm, data);
|
|
30
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
31
|
+
const hashHex = hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
32
|
+
return hashHex;
|
|
33
|
+
};
|
|
34
|
+
var compareWithHash = async (value1, value2, algorithm = "SHA-256") => {
|
|
35
|
+
const hash1 = await hash(value1, algorithm);
|
|
36
|
+
const hash2 = await hash(value2, algorithm);
|
|
37
|
+
return hash1 === hash2;
|
|
38
|
+
};
|
|
39
|
+
async function hashStringPromise(value, algorithm = "SHA-256") {
|
|
40
|
+
const encoder = new TextEncoder();
|
|
41
|
+
const data = encoder.encode(value);
|
|
42
|
+
const hashBuffer = await crypto.subtle.digest(algorithm, data);
|
|
43
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
44
|
+
const hashHex = hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
45
|
+
return hashHex;
|
|
46
|
+
}
|
|
47
|
+
var string_hash = (str) => {
|
|
48
|
+
let hash2 = 0;
|
|
49
|
+
for (let i = 0; i < str.length; i++) {
|
|
50
|
+
const char = str.charCodeAt(i);
|
|
51
|
+
hash2 = (hash2 << 5) - hash2 + char;
|
|
52
|
+
hash2 = hash2 & hash2;
|
|
53
|
+
}
|
|
54
|
+
return hash2.toString(16);
|
|
55
|
+
};
|
|
56
|
+
export {
|
|
57
|
+
compareWithHash,
|
|
58
|
+
createHash,
|
|
59
|
+
hash,
|
|
60
|
+
hashStringPromise,
|
|
61
|
+
string_hash
|
|
62
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/lib/dom/events.ts
|
|
21
|
+
var events_exports = {};
|
|
22
|
+
__export(events_exports, {
|
|
23
|
+
isAddRemoveListenerTarget: () => isAddRemoveListenerTarget,
|
|
24
|
+
isDOMEventTarget: () => isDOMEventTarget,
|
|
25
|
+
isNodeEventEmitter: () => isNodeEventEmitter,
|
|
26
|
+
isOnOffTarget: () => isOnOffTarget
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(events_exports);
|
|
29
|
+
function isDOMEventTarget(target) {
|
|
30
|
+
return target && typeof target.addEventListener === "function";
|
|
31
|
+
}
|
|
32
|
+
function isNodeEventEmitter(target) {
|
|
33
|
+
return target && typeof target.addEventListener === "function" && typeof target.removeEventListener === "function";
|
|
34
|
+
}
|
|
35
|
+
function isOnOffTarget(target) {
|
|
36
|
+
return target && typeof target.on === "function" && typeof target.off === "function";
|
|
37
|
+
}
|
|
38
|
+
function isAddRemoveListenerTarget(target) {
|
|
39
|
+
return target && typeof target.addListener === "function" && typeof target.removeListener === "function";
|
|
40
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A mapping of common DOM event names to their corresponding TypeScript event interfaces.
|
|
3
|
+
* This enables intelligent type inference for standard browser events.
|
|
4
|
+
*
|
|
5
|
+
* @interface DomEventMap
|
|
6
|
+
*
|
|
7
|
+
* @property {MouseEvent} 'click' - Mouse click events
|
|
8
|
+
* @property {MouseEvent} 'dblclick' - Mouse double-click events
|
|
9
|
+
* @property {MouseEvent} 'mousedown' - Mouse button down events
|
|
10
|
+
* @property {MouseEvent} 'mouseup' - Mouse button up events
|
|
11
|
+
* @property {MouseEvent} 'mousemove' - Mouse movement events
|
|
12
|
+
* @property {MouseEvent} 'mouseenter' - Mouse enter events
|
|
13
|
+
* @property {MouseEvent} 'mouseleave' - Mouse leave events
|
|
14
|
+
* @property {KeyboardEvent} 'keydown' - Keyboard key down events
|
|
15
|
+
* @property {KeyboardEvent} 'keyup' - Keyboard key up events
|
|
16
|
+
* @property {KeyboardEvent} 'keypress' - Keyboard key press events (deprecated)
|
|
17
|
+
* @property {Event} 'change' - Form change events
|
|
18
|
+
* @property {InputEvent} 'input' - Form input events
|
|
19
|
+
* @property {Event} 'submit' - Form submit events
|
|
20
|
+
* @property {FocusEvent} 'focus' - Element focus events
|
|
21
|
+
* @property {FocusEvent} 'blur' - Element blur events
|
|
22
|
+
* @property {DragEvent} 'drag' - Drag events
|
|
23
|
+
* @property {DragEvent} 'dragstart' - Drag start events
|
|
24
|
+
* @property {DragEvent} 'dragend' - Drag end events
|
|
25
|
+
* @property {DragEvent} 'dragover' - Drag over events
|
|
26
|
+
* @property {DragEvent} 'drop' - Drop events
|
|
27
|
+
* @property {Event} 'play' - Media play events
|
|
28
|
+
* @property {Event} 'pause' - Media pause events
|
|
29
|
+
* @property {Event} 'ended' - Media ended events
|
|
30
|
+
* @property {Event} 'load' - Resource load events
|
|
31
|
+
* @property {Event} 'unload' - Resource unload events
|
|
32
|
+
* @property {UIEvent} 'resize' - Window resize events
|
|
33
|
+
* @property {Event} 'scroll' - Scroll events
|
|
34
|
+
*/
|
|
35
|
+
export interface DomEventMap {
|
|
36
|
+
click: MouseEvent;
|
|
37
|
+
dblclick: MouseEvent;
|
|
38
|
+
mousedown: MouseEvent;
|
|
39
|
+
mouseup: MouseEvent;
|
|
40
|
+
mousemove: MouseEvent;
|
|
41
|
+
mouseenter: MouseEvent;
|
|
42
|
+
mouseleave: MouseEvent;
|
|
43
|
+
keydown: KeyboardEvent;
|
|
44
|
+
keyup: KeyboardEvent;
|
|
45
|
+
keypress: KeyboardEvent;
|
|
46
|
+
change: Event;
|
|
47
|
+
input: InputEvent;
|
|
48
|
+
submit: Event;
|
|
49
|
+
focus: FocusEvent;
|
|
50
|
+
blur: FocusEvent;
|
|
51
|
+
drag: DragEvent;
|
|
52
|
+
dragstart: DragEvent;
|
|
53
|
+
dragend: DragEvent;
|
|
54
|
+
dragover: DragEvent;
|
|
55
|
+
drop: DragEvent;
|
|
56
|
+
play: Event;
|
|
57
|
+
pause: Event;
|
|
58
|
+
ended: Event;
|
|
59
|
+
load: Event;
|
|
60
|
+
unload: Event;
|
|
61
|
+
resize: UIEvent;
|
|
62
|
+
scroll: Event;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Interface for Node.js EventEmitter compatibility.
|
|
66
|
+
* This allows `fromEvent` to work with Node.js event emitters.
|
|
67
|
+
*
|
|
68
|
+
* @interface NodeEventEmitter
|
|
69
|
+
*
|
|
70
|
+
* @method addEventListener - Adds an event listener (Node.js style)
|
|
71
|
+
* @param {string|symbol} event - The event name
|
|
72
|
+
* @param {Function} listener - The event listener function
|
|
73
|
+
*
|
|
74
|
+
* @method removeEventListener - Removes an event listener (Node.js style)
|
|
75
|
+
* @param {string|symbol} event - The event name
|
|
76
|
+
* @param {Function} listener - The event listener function
|
|
77
|
+
*/
|
|
78
|
+
export interface NodeEventEmitter {
|
|
79
|
+
addEventListener(event: string | symbol, listener: (...args: any[]) => void): void;
|
|
80
|
+
removeEventListener(event: string | symbol, listener: (...args: any[]) => void): void;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Union type representing all supported event target types.
|
|
84
|
+
* `fromEvent` can work with DOM elements, Node.js EventEmitters, jQuery-like objects,
|
|
85
|
+
* and any object with `on`/`off` or `addListener`/`removeListener` methods.
|
|
86
|
+
*
|
|
87
|
+
* @typedef {EventTarget|NodeEventEmitter|{on:Function, off:Function}|{addListener:Function, removeListener:Function}} EventTargetLike
|
|
88
|
+
*/
|
|
89
|
+
export type EventTargetLike = EventTarget | NodeEventEmitter | {
|
|
90
|
+
on(event: string, handler: (...args: any[]) => void): void;
|
|
91
|
+
off(event: string, handler: (...args: any[]) => void): void;
|
|
92
|
+
} | {
|
|
93
|
+
addListener(event: string, handler: (...args: any[]) => void): void;
|
|
94
|
+
removeListener(event: string, handler: (...args: any[]) => void): void;
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* Infers the specific Event type based on the event name and target.
|
|
98
|
+
* This is a conditional type that provides intelligent type inference:
|
|
99
|
+
* 1. First checks against the standard DomEventMap
|
|
100
|
+
* 2. Then checks if the target has its own event type definitions
|
|
101
|
+
* 3. Falls back to the basic Event type
|
|
102
|
+
*
|
|
103
|
+
* @template EventName - The string literal type of the event name (e.g., 'click', 'keydown')
|
|
104
|
+
* @template Target - The type of the event target
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* // Returns MouseEvent
|
|
108
|
+
* type ClickEvent = EventFor<'click', HTMLButtonElement>;
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* // Returns KeyboardEvent
|
|
112
|
+
* type KeydownEvent = EventFor<'keydown', HTMLInputElement>;
|
|
113
|
+
*/
|
|
114
|
+
export type EventFor<EventName extends string, Target extends EventTargetLike = EventTarget> = EventName extends keyof DomEventMap ? DomEventMap[EventName] : Target extends {
|
|
115
|
+
addEventListener(type: infer E, listener: any, options?: any): any;
|
|
116
|
+
} ? E extends string ? EventName extends E ? Event : never : Event : Event;
|
|
117
|
+
/**
|
|
118
|
+
* Type guard to check if an object is a DOM EventTarget.
|
|
119
|
+
*
|
|
120
|
+
* @param {any} target - The object to check
|
|
121
|
+
* @returns {target is EventTarget} True if the object is a DOM EventTarget
|
|
122
|
+
*
|
|
123
|
+
* @private
|
|
124
|
+
*/
|
|
125
|
+
export declare function isDOMEventTarget(target: any): target is EventTarget;
|
|
126
|
+
/**
|
|
127
|
+
* Type guard to check if an object is a Node.js EventEmitter.
|
|
128
|
+
*
|
|
129
|
+
* @param {any} target - The object to check
|
|
130
|
+
* @returns {target is NodeEventEmitter} True if the object is a NodeEventEmitter
|
|
131
|
+
*
|
|
132
|
+
* @private
|
|
133
|
+
*/
|
|
134
|
+
export declare function isNodeEventEmitter(target: any): target is NodeEventEmitter;
|
|
135
|
+
/**
|
|
136
|
+
* Type guard to check if an object has on/off methods (jQuery-style).
|
|
137
|
+
*
|
|
138
|
+
* @param {any} target - The object to check
|
|
139
|
+
* @returns {target is {on: Function, off: Function}} True if the object has on/off methods
|
|
140
|
+
*
|
|
141
|
+
* @private
|
|
142
|
+
*/
|
|
143
|
+
export declare function isOnOffTarget(target: any): target is {
|
|
144
|
+
on: Function;
|
|
145
|
+
off: Function;
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* Type guard to check if an object has addListener/removeListener methods.
|
|
149
|
+
*
|
|
150
|
+
* @param {any} target - The object to check
|
|
151
|
+
* @returns {target is {addListener: Function, removeListener: Function}} True if the object has addListener/removeListener methods
|
|
152
|
+
*
|
|
153
|
+
* @private
|
|
154
|
+
*/
|
|
155
|
+
export declare function isAddRemoveListenerTarget(target: any): target is {
|
|
156
|
+
addListener: Function;
|
|
157
|
+
removeListener: Function;
|
|
158
|
+
};
|
|
159
|
+
//# sourceMappingURL=events.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../../src/lib/dom/events.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type guard to check if an object is a DOM EventTarget.
|
|
3
|
+
*
|
|
4
|
+
* @param {any} target - The object to check
|
|
5
|
+
* @returns {target is EventTarget} True if the object is a DOM EventTarget
|
|
6
|
+
*
|
|
7
|
+
* @private
|
|
8
|
+
*/
|
|
9
|
+
export function isDOMEventTarget(target) {
|
|
10
|
+
return target && typeof target.addEventListener === 'function';
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Type guard to check if an object is a Node.js EventEmitter.
|
|
14
|
+
*
|
|
15
|
+
* @param {any} target - The object to check
|
|
16
|
+
* @returns {target is NodeEventEmitter} True if the object is a NodeEventEmitter
|
|
17
|
+
*
|
|
18
|
+
* @private
|
|
19
|
+
*/
|
|
20
|
+
export function isNodeEventEmitter(target) {
|
|
21
|
+
return (target &&
|
|
22
|
+
typeof target.addEventListener === 'function' &&
|
|
23
|
+
typeof target.removeEventListener === 'function');
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Type guard to check if an object has on/off methods (jQuery-style).
|
|
27
|
+
*
|
|
28
|
+
* @param {any} target - The object to check
|
|
29
|
+
* @returns {target is {on: Function, off: Function}} True if the object has on/off methods
|
|
30
|
+
*
|
|
31
|
+
* @private
|
|
32
|
+
*/
|
|
33
|
+
export function isOnOffTarget(target) {
|
|
34
|
+
return (target &&
|
|
35
|
+
typeof target.on === 'function' &&
|
|
36
|
+
typeof target.off === 'function');
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Type guard to check if an object has addListener/removeListener methods.
|
|
40
|
+
*
|
|
41
|
+
* @param {any} target - The object to check
|
|
42
|
+
* @returns {target is {addListener: Function, removeListener: Function}} True if the object has addListener/removeListener methods
|
|
43
|
+
*
|
|
44
|
+
* @private
|
|
45
|
+
*/
|
|
46
|
+
export function isAddRemoveListenerTarget(target) {
|
|
47
|
+
return (target &&
|
|
48
|
+
typeof target.addListener === 'function' &&
|
|
49
|
+
typeof target.removeListener === 'function');
|
|
50
|
+
}
|