@kikiutils/shared 15.0.1 → 15.0.3
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/README.md +46 -119
- package/dist/crypto-hash.d.ts +145 -0
- package/dist/crypto-hash.d.ts.map +1 -1
- package/dist/crypto-hash.js +137 -7
- package/dist/crypto-hash.js.map +1 -1
- package/dist/datetime.d.ts +0 -2
- package/dist/datetime.d.ts.map +1 -1
- package/dist/datetime.js +0 -2
- package/dist/datetime.js.map +1 -1
- package/dist/enum.js.map +1 -1
- package/dist/env.d.ts +2 -0
- package/dist/env.d.ts.map +1 -1
- package/dist/env.js +2 -0
- package/dist/env.js.map +1 -1
- package/dist/event-awaiter.js +1 -1
- package/dist/event-awaiter.js.map +1 -1
- package/dist/hash.d.ts +48 -5
- package/dist/hash.d.ts.map +1 -1
- package/dist/hash.js +49 -6
- package/dist/hash.js.map +1 -1
- package/dist/math.js +1 -1
- package/dist/math.js.map +1 -1
- package/dist/object.d.ts +4 -0
- package/dist/object.d.ts.map +1 -1
- package/dist/object.js +4 -0
- package/dist/object.js.map +1 -1
- package/dist/pino.js.map +1 -1
- package/dist/random.js +2 -0
- package/dist/random.js.map +1 -1
- package/dist/storages/lru/keyed-store.d.ts +22 -0
- package/dist/storages/lru/keyed-store.d.ts.map +1 -1
- package/dist/storages/lru/keyed-store.js +30 -0
- package/dist/storages/lru/keyed-store.js.map +1 -1
- package/dist/storages/redis/keyed-store.d.ts +25 -0
- package/dist/storages/redis/keyed-store.d.ts.map +1 -1
- package/dist/storages/redis/keyed-store.js +25 -0
- package/dist/storages/redis/keyed-store.js.map +1 -1
- package/dist/storages/redis/msgpack.d.ts +20 -0
- package/dist/storages/redis/msgpack.d.ts.map +1 -1
- package/dist/storages/redis/msgpack.js +20 -0
- package/dist/storages/redis/msgpack.js.map +1 -1
- package/dist/storages/redis/types.d.ts +42 -0
- package/dist/storages/redis/types.d.ts.map +1 -1
- package/dist/time.d.ts +17 -0
- package/dist/time.d.ts.map +1 -1
- package/dist/time.js +17 -0
- package/dist/time.js.map +1 -1
- package/dist/url.d.ts +3 -0
- package/dist/url.d.ts.map +1 -1
- package/dist/url.js +8 -2
- package/dist/url.js.map +1 -1
- package/dist/vue.d.ts +6 -0
- package/dist/vue.d.ts.map +1 -1
- package/dist/vue.js +6 -0
- package/dist/vue.js.map +1 -1
- package/dist/web.js.map +1 -1
- package/package.json +11 -11
- package/src/crypto-hash.ts +143 -14
- package/src/datetime.ts +0 -2
- package/src/env.ts +2 -0
- package/src/event-awaiter.ts +1 -1
- package/src/hash.ts +56 -14
- package/src/math.ts +2 -1
- package/src/object.ts +4 -0
- package/src/random.ts +3 -0
- package/src/storages/lru/keyed-store.ts +22 -0
- package/src/storages/redis/keyed-store.ts +25 -0
- package/src/storages/redis/msgpack.ts +20 -0
- package/src/storages/redis/types.ts +52 -0
- package/src/time.ts +17 -0
- package/src/url.ts +13 -2
- package/src/vue.ts +6 -0
|
@@ -1,20 +1,62 @@
|
|
|
1
1
|
import { Nullable } from "../../types/index.js";
|
|
2
2
|
|
|
3
3
|
//#region src/storages/redis/types.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Low-level Redis-like adapter interface for raw buffer operations.
|
|
6
|
+
*/
|
|
4
7
|
interface RedisLikeAdapter {
|
|
8
|
+
/**
|
|
9
|
+
* Deletes a key and returns the number of keys deleted.
|
|
10
|
+
*/
|
|
5
11
|
delete: (key: string) => Promise<number>;
|
|
12
|
+
/**
|
|
13
|
+
* Gets the raw buffer value for a key.
|
|
14
|
+
*/
|
|
6
15
|
getBuffer: (key: string) => Promise<Nullable<Uint8Array>>;
|
|
16
|
+
/**
|
|
17
|
+
* Checks if a key exists.
|
|
18
|
+
*/
|
|
7
19
|
has: (key: string) => Promise<boolean>;
|
|
20
|
+
/**
|
|
21
|
+
* Sets a raw buffer value for a key.
|
|
22
|
+
*/
|
|
8
23
|
setBuffer: (key: string, value: Uint8Array) => Promise<'OK' | void>;
|
|
24
|
+
/**
|
|
25
|
+
* Sets a raw buffer value for a key with a TTL.
|
|
26
|
+
*/
|
|
9
27
|
setBufferEx: (key: string, ttlSeconds: number, value: Uint8Array) => Promise<'OK' | void>;
|
|
28
|
+
/**
|
|
29
|
+
* Gets the TTL of a key in seconds.
|
|
30
|
+
*/
|
|
10
31
|
ttl: (key: string) => Promise<number>;
|
|
11
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* High-level Redis-like storage interface with typed get/set operations.
|
|
35
|
+
*/
|
|
12
36
|
interface RedisLikeStorage {
|
|
37
|
+
/**
|
|
38
|
+
* Gets a deserialized value by key.
|
|
39
|
+
*/
|
|
13
40
|
getItem: <T = unknown>(key: string) => Promise<Nullable<T>>;
|
|
41
|
+
/**
|
|
42
|
+
* Gets the TTL of a key in seconds.
|
|
43
|
+
*/
|
|
14
44
|
getItemTtl: (key: string) => Promise<number>;
|
|
45
|
+
/**
|
|
46
|
+
* Checks if a key exists.
|
|
47
|
+
*/
|
|
15
48
|
hasItem: (key: string) => Promise<boolean>;
|
|
49
|
+
/**
|
|
50
|
+
* Removes a key.
|
|
51
|
+
*/
|
|
16
52
|
removeItem: (key: string) => Promise<boolean>;
|
|
53
|
+
/**
|
|
54
|
+
* Sets a value for a key.
|
|
55
|
+
*/
|
|
17
56
|
setItem: (key: string, value: any) => Promise<boolean>;
|
|
57
|
+
/**
|
|
58
|
+
* Sets a value for a key with a TTL.
|
|
59
|
+
*/
|
|
18
60
|
setItemWithTtl: (key: string, ttlSeconds: number, value: any) => Promise<boolean>;
|
|
19
61
|
}
|
|
20
62
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","names":[],"sources":["../../../src/storages/redis/types.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.d.ts","names":[],"sources":["../../../src/storages/redis/types.ts"],"mappings":";;;;;AAKA;UAAiB,gBAAA;;;;EAIb,MAAA,GAAS,GAAA,aAAgB,OAAA;EAKG;;;EAA5B,SAAA,GAAY,GAAA,aAAgB,OAAA,CAAQ,QAAA,CAAS,UAAA;EAeS;;;EAVtD,GAAA,GAAM,GAAA,aAAgB,OAAA;EAeO;;;EAV7B,SAAA,GAAY,GAAA,UAAa,KAAA,EAAO,UAAA,KAAe,OAAA;EAV/C;;;EAeA,WAAA,GAAc,GAAA,UAAa,UAAA,UAAoB,KAAA,EAAO,UAAA,KAAe,OAAA;EAfxB;;;EAoB7C,GAAA,GAAM,GAAA,aAAgB,OAAA;AAAA;;;;UAMT,gBAAA;EAXb;;;EAeA,OAAA,gBAAuB,GAAA,aAAgB,OAAA,CAAQ,QAAA,CAAS,CAAA;EAfT;;;EAoB/C,UAAA,GAAa,GAAA,aAAgB,OAAA;EAfP;;;EAoBtB,OAAA,GAAU,GAAA,aAAgB,OAAA;EAdG;;;EAmB7B,UAAA,GAAa,GAAA,aAAgB,OAAA;EAfU;;;EAoBvC,OAAA,GAAU,GAAA,UAAa,KAAA,UAAe,OAAA;EAAA;;;EAKtC,cAAA,GAAiB,GAAA,UAAa,UAAA,UAAoB,KAAA,UAAe,OAAA;AAAA"}
|
package/dist/time.d.ts
CHANGED
|
@@ -1,4 +1,21 @@
|
|
|
1
1
|
//#region src/time.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a delay that can be aborted via AbortSignal.
|
|
4
|
+
*
|
|
5
|
+
* @param {number} ms - Delay duration in milliseconds
|
|
6
|
+
* @param {AbortSignal} [signal] - Optional AbortSignal to cancel the delay
|
|
7
|
+
*
|
|
8
|
+
* @returns {Promise<undefined>} A promise that resolves after ms or resolves immediately on abort
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { abortableDelay } from '@kikiutils/shared/time';
|
|
13
|
+
*
|
|
14
|
+
* const controller = new AbortController();
|
|
15
|
+
* setTimeout(() => controller.abort(), 1000);
|
|
16
|
+
* await abortableDelay(5000, controller.signal); // resolves after ~1s when aborted
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
2
19
|
declare function abortableDelay(ms: number, signal?: AbortSignal): Promise<unknown>;
|
|
3
20
|
//#endregion
|
|
4
21
|
export { abortableDelay };
|
package/dist/time.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"time.d.ts","names":[],"sources":["../src/time.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"time.d.ts","names":[],"sources":["../src/time.ts"],"mappings":";;AAiBA;;;;;;;;;;;;;;;;iBAAgB,cAAA,CAAe,EAAA,UAAY,MAAA,GAAS,WAAA,GAAW,OAAA"}
|
package/dist/time.js
CHANGED
|
@@ -1,4 +1,21 @@
|
|
|
1
1
|
//#region src/time.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a delay that can be aborted via AbortSignal.
|
|
4
|
+
*
|
|
5
|
+
* @param {number} ms - Delay duration in milliseconds
|
|
6
|
+
* @param {AbortSignal} [signal] - Optional AbortSignal to cancel the delay
|
|
7
|
+
*
|
|
8
|
+
* @returns {Promise<undefined>} A promise that resolves after ms or resolves immediately on abort
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { abortableDelay } from '@kikiutils/shared/time';
|
|
13
|
+
*
|
|
14
|
+
* const controller = new AbortController();
|
|
15
|
+
* setTimeout(() => controller.abort(), 1000);
|
|
16
|
+
* await abortableDelay(5000, controller.signal); // resolves after ~1s when aborted
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
2
19
|
function abortableDelay(ms, signal) {
|
|
3
20
|
return new Promise((resolve) => {
|
|
4
21
|
const timeout = setTimeout(resolve, ms);
|
package/dist/time.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"time.js","names":[],"sources":["../src/time.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"time.js","names":[],"sources":["../src/time.ts"],"sourcesContent":["/**\n * Creates a delay that can be aborted via AbortSignal.\n *\n * @param {number} ms - Delay duration in milliseconds\n * @param {AbortSignal} [signal] - Optional AbortSignal to cancel the delay\n *\n * @returns {Promise<undefined>} A promise that resolves after ms or resolves immediately on abort\n *\n * @example\n * ```typescript\n * import { abortableDelay } from '@kikiutils/shared/time';\n *\n * const controller = new AbortController();\n * setTimeout(() => controller.abort(), 1000);\n * await abortableDelay(5000, controller.signal); // resolves after ~1s when aborted\n * ```\n */\nexport function abortableDelay(ms: number, signal?: AbortSignal) {\n return new Promise((resolve) => {\n const timeout = setTimeout(resolve, ms);\n if (signal) {\n signal.addEventListener(\n 'abort',\n () => {\n clearTimeout(timeout);\n resolve(undefined);\n },\n );\n }\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAiBA,SAAgB,eAAe,IAAY,QAAsB;AAC7D,QAAO,IAAI,SAAS,YAAY;EAC5B,MAAM,UAAU,WAAW,SAAS,GAAG;AACvC,MAAI,OACA,QAAO,iBACH,eACM;AACF,gBAAa,QAAQ;AACrB,WAAQ,KAAA,EAAU;IAEzB;GAEP"}
|
package/dist/url.d.ts
CHANGED
|
@@ -6,8 +6,11 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @param {string} url - The target URL to modify
|
|
8
8
|
* @param {string} redirectPath - The path to use as the redirect destination
|
|
9
|
+
* (must be an absolute path starting with '/')
|
|
9
10
|
*
|
|
10
11
|
* @returns {string} A new URL string with the `redirect` query parameter
|
|
12
|
+
*
|
|
13
|
+
* @throws {Error} If redirectPath is not a valid relative path (must start with '/')
|
|
11
14
|
*/
|
|
12
15
|
declare function appendRedirectParamToUrl(url: string, redirectPath: string): string;
|
|
13
16
|
//#endregion
|
package/dist/url.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"url.d.ts","names":[],"sources":["../src/url.ts"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"url.d.ts","names":[],"sources":["../src/url.ts"],"mappings":";;AAaA;;;;;;;;;;;;iBAAgB,wBAAA,CAAyB,GAAA,UAAa,YAAA"}
|
package/dist/url.js
CHANGED
|
@@ -6,14 +6,20 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @param {string} url - The target URL to modify
|
|
8
8
|
* @param {string} redirectPath - The path to use as the redirect destination
|
|
9
|
+
* (must be an absolute path starting with '/')
|
|
9
10
|
*
|
|
10
11
|
* @returns {string} A new URL string with the `redirect` query parameter
|
|
12
|
+
*
|
|
13
|
+
* @throws {Error} If redirectPath is not a valid relative path (must start with '/')
|
|
11
14
|
*/
|
|
12
15
|
function appendRedirectParamToUrl(url, redirectPath) {
|
|
13
|
-
|
|
16
|
+
if (!redirectPath.startsWith("/")) throw new Error(`Invalid redirect path: "${redirectPath}". Redirect paths must be absolute paths starting with '/'.`);
|
|
17
|
+
const [baseAndHash, rawQuery = ""] = url.split("?");
|
|
18
|
+
const [base, hash] = (baseAndHash || "").split("#");
|
|
14
19
|
const searchParams = new URLSearchParams(rawQuery);
|
|
15
20
|
searchParams.set("redirect", redirectPath);
|
|
16
|
-
|
|
21
|
+
const queryString = searchParams.toString();
|
|
22
|
+
return hash ? `${base}?${queryString}#${hash}` : `${base}?${queryString}`;
|
|
17
23
|
}
|
|
18
24
|
//#endregion
|
|
19
25
|
export { appendRedirectParamToUrl };
|
package/dist/url.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"url.js","names":[],"sources":["../src/url.ts"],"sourcesContent":["/**\n * Appends or updates the `redirect` query parameter on a given URL.\n *\n * Typically used to preserve the user's current path for post-login navigation.\n *\n * @param {string} url - The target URL to modify\n * @param {string} redirectPath - The path to use as the redirect destination\n *\n * @returns {string} A new URL string with the `redirect` query parameter\n */\nexport function appendRedirectParamToUrl(url: string, redirectPath: string) {\n const [
|
|
1
|
+
{"version":3,"file":"url.js","names":[],"sources":["../src/url.ts"],"sourcesContent":["/**\n * Appends or updates the `redirect` query parameter on a given URL.\n *\n * Typically used to preserve the user's current path for post-login navigation.\n *\n * @param {string} url - The target URL to modify\n * @param {string} redirectPath - The path to use as the redirect destination\n * (must be an absolute path starting with '/')\n *\n * @returns {string} A new URL string with the `redirect` query parameter\n *\n * @throws {Error} If redirectPath is not a valid relative path (must start with '/')\n */\nexport function appendRedirectParamToUrl(url: string, redirectPath: string) {\n if (!redirectPath.startsWith('/')) {\n throw new Error(\n `Invalid redirect path: \"${redirectPath}\". Redirect paths must be absolute paths starting with '/'.`,\n );\n }\n\n const [baseAndHash, rawQuery = ''] = url.split('?');\n const [base, hash] = (baseAndHash || '').split('#');\n const searchParams = new URLSearchParams(rawQuery);\n searchParams.set('redirect', redirectPath);\n const queryString = searchParams.toString();\n return hash ? `${base}?${queryString}#${hash}` : `${base}?${queryString}`;\n}\n"],"mappings":";;;;;;;;;;;;;;AAaA,SAAgB,yBAAyB,KAAa,cAAsB;AACxE,KAAI,CAAC,aAAa,WAAW,IAAI,CAC7B,OAAM,IAAI,MACN,2BAA2B,aAAa,6DAC3C;CAGL,MAAM,CAAC,aAAa,WAAW,MAAM,IAAI,MAAM,IAAI;CACnD,MAAM,CAAC,MAAM,SAAS,eAAe,IAAI,MAAM,IAAI;CACnD,MAAM,eAAe,IAAI,gBAAgB,SAAS;AAClD,cAAa,IAAI,YAAY,aAAa;CAC1C,MAAM,cAAc,aAAa,UAAU;AAC3C,QAAO,OAAO,GAAG,KAAK,GAAG,YAAY,GAAG,SAAS,GAAG,KAAK,GAAG"}
|
package/dist/vue.d.ts
CHANGED
|
@@ -26,6 +26,12 @@ declare function clearTimeoutRef(timeoutRef: Ref<Nullable<ReturnType<typeof setT
|
|
|
26
26
|
* A Vue composition function that remembers and restores scroll position
|
|
27
27
|
* of a scrollable container across route changes and keep-alive activation.
|
|
28
28
|
*
|
|
29
|
+
* Designed for use with `<KeepAlive>` components. Scroll state is saved on
|
|
30
|
+
* route leave and restored when the component is activated again.
|
|
31
|
+
*
|
|
32
|
+
* Note: Without `<KeepAlive>`, the component state is destroyed on unmount,
|
|
33
|
+
* so scroll position will not be preserved.
|
|
34
|
+
*
|
|
29
35
|
* @template T - The type of the scrollable element (defaults to HTMLElement)
|
|
30
36
|
*
|
|
31
37
|
* @param {Ref<Nullable<T>>} containerRef - A ref to the scrollable HTML element
|
package/dist/vue.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vue.d.ts","names":[],"sources":["../src/vue.ts"],"mappings":";;;;;;AAiBA;;;;;iBAAgB,wCAAA,CAAyC,GAAA;;;;;;iBASzC,gBAAA,CAAiB,WAAA,EAAa,GAAA,CAAI,QAAA,CAAS,UAAA,QAAkB,WAAA;;;;;;iBAU7D,eAAA,CAAgB,UAAA,EAAY,GAAA,CAAI,QAAA,CAAS,UAAA,QAAkB,UAAA;;;;AAA3E
|
|
1
|
+
{"version":3,"file":"vue.d.ts","names":[],"sources":["../src/vue.ts"],"mappings":";;;;;;AAiBA;;;;;iBAAgB,wCAAA,CAAyC,GAAA;;;;;;iBASzC,gBAAA,CAAiB,WAAA,EAAa,GAAA,CAAI,QAAA,CAAS,UAAA,QAAkB,WAAA;;;;;;iBAU7D,eAAA,CAAgB,UAAA,EAAY,GAAA,CAAI,QAAA,CAAS,UAAA,QAAkB,UAAA;;;;AAA3E;;;;;;;;;;;iBAmBgB,iBAAA,WAA4B,OAAA,GAAU,WAAA,CAAA,CAAa,YAAA,EAAc,GAAA,CAAI,QAAA,CAAS,CAAA"}
|
package/dist/vue.js
CHANGED
|
@@ -34,6 +34,12 @@ function clearTimeoutRef(timeoutRef) {
|
|
|
34
34
|
* A Vue composition function that remembers and restores scroll position
|
|
35
35
|
* of a scrollable container across route changes and keep-alive activation.
|
|
36
36
|
*
|
|
37
|
+
* Designed for use with `<KeepAlive>` components. Scroll state is saved on
|
|
38
|
+
* route leave and restored when the component is activated again.
|
|
39
|
+
*
|
|
40
|
+
* Note: Without `<KeepAlive>`, the component state is destroyed on unmount,
|
|
41
|
+
* so scroll position will not be preserved.
|
|
42
|
+
*
|
|
37
43
|
* @template T - The type of the scrollable element (defaults to HTMLElement)
|
|
38
44
|
*
|
|
39
45
|
* @param {Ref<Nullable<T>>} containerRef - A ref to the scrollable HTML element
|
package/dist/vue.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vue.js","names":[],"sources":["../src/vue.ts"],"sourcesContent":["import { onActivated } from 'vue';\nimport type { Ref } from 'vue';\nimport {\n onBeforeRouteLeave,\n useRoute,\n} from 'vue-router';\n\nimport type { Nullable } from './types';\nimport { appendRedirectParamToUrl } from './url';\n\n/**\n * Appends the current Vue Router route's fullPath as the `redirect` query parameter to the given URL.\n *\n * @param {string} url - The base URL to modify\n *\n * @returns {string} A new URL with the current route fullPath as the `redirect` parameter\n */\nexport function appendRedirectParamFromCurrentRouteToUrl(url: string) {\n return appendRedirectParamToUrl(url, useRoute().fullPath);\n}\n\n/**\n * Clears an interval referenced by a Vue ref and sets it to null.\n *\n * @param {Ref<Nullable<ReturnType<typeof setInterval>>>} intervalRef - A Vue ref holding a NodeJS.Timeout or null\n */\nexport function clearIntervalRef(intervalRef: Ref<Nullable<ReturnType<typeof setInterval>>>) {\n if (intervalRef.value) clearInterval(intervalRef.value);\n intervalRef.value = null;\n}\n\n/**\n * Clears a timeout referenced by a Vue ref and sets it to null.\n *\n * @param {Ref<Nullable<ReturnType<typeof setTimeout>>>} timeoutRef - A Vue ref holding a NodeJS.Timeout or null\n */\nexport function clearTimeoutRef(timeoutRef: Ref<Nullable<ReturnType<typeof setTimeout>>>) {\n if (timeoutRef.value) clearTimeout(timeoutRef.value);\n timeoutRef.value = null;\n}\n\n/**\n * A Vue composition function that remembers and restores scroll position\n * of a scrollable container across route changes and keep-alive activation.\n *\n * @template T - The type of the scrollable element (defaults to HTMLElement)\n *\n * @param {Ref<Nullable<T>>} containerRef - A ref to the scrollable HTML element\n */\nexport function usePreserveScroll<T extends Element = HTMLElement>(containerRef: Ref<Nullable<T>>) {\n let scrollLeft = 0;\n let scrollTop = 0;\n onActivated(() => {\n if (!containerRef.value) return;\n containerRef.value.scrollLeft = scrollLeft;\n containerRef.value.scrollTop = scrollTop;\n });\n\n onBeforeRouteLeave(() => {\n scrollLeft = containerRef.value?.scrollLeft || 0;\n scrollTop = containerRef.value?.scrollTop || 0;\n });\n}\n"],"mappings":";;;;;;;;;;;AAiBA,SAAgB,yCAAyC,KAAa;AAClE,QAAO,yBAAyB,KAAK,UAAU,CAAC,SAAS;;;;;;;AAQ7D,SAAgB,iBAAiB,aAA4D;AACzF,KAAI,YAAY,MAAO,eAAc,YAAY,MAAM;AACvD,aAAY,QAAQ;;;;;;;AAQxB,SAAgB,gBAAgB,YAA0D;AACtF,KAAI,WAAW,MAAO,cAAa,WAAW,MAAM;AACpD,YAAW,QAAQ
|
|
1
|
+
{"version":3,"file":"vue.js","names":[],"sources":["../src/vue.ts"],"sourcesContent":["import { onActivated } from 'vue';\nimport type { Ref } from 'vue';\nimport {\n onBeforeRouteLeave,\n useRoute,\n} from 'vue-router';\n\nimport type { Nullable } from './types';\nimport { appendRedirectParamToUrl } from './url';\n\n/**\n * Appends the current Vue Router route's fullPath as the `redirect` query parameter to the given URL.\n *\n * @param {string} url - The base URL to modify\n *\n * @returns {string} A new URL with the current route fullPath as the `redirect` parameter\n */\nexport function appendRedirectParamFromCurrentRouteToUrl(url: string) {\n return appendRedirectParamToUrl(url, useRoute().fullPath);\n}\n\n/**\n * Clears an interval referenced by a Vue ref and sets it to null.\n *\n * @param {Ref<Nullable<ReturnType<typeof setInterval>>>} intervalRef - A Vue ref holding a NodeJS.Timeout or null\n */\nexport function clearIntervalRef(intervalRef: Ref<Nullable<ReturnType<typeof setInterval>>>) {\n if (intervalRef.value) clearInterval(intervalRef.value);\n intervalRef.value = null;\n}\n\n/**\n * Clears a timeout referenced by a Vue ref and sets it to null.\n *\n * @param {Ref<Nullable<ReturnType<typeof setTimeout>>>} timeoutRef - A Vue ref holding a NodeJS.Timeout or null\n */\nexport function clearTimeoutRef(timeoutRef: Ref<Nullable<ReturnType<typeof setTimeout>>>) {\n if (timeoutRef.value) clearTimeout(timeoutRef.value);\n timeoutRef.value = null;\n}\n\n/**\n * A Vue composition function that remembers and restores scroll position\n * of a scrollable container across route changes and keep-alive activation.\n *\n * Designed for use with `<KeepAlive>` components. Scroll state is saved on\n * route leave and restored when the component is activated again.\n *\n * Note: Without `<KeepAlive>`, the component state is destroyed on unmount,\n * so scroll position will not be preserved.\n *\n * @template T - The type of the scrollable element (defaults to HTMLElement)\n *\n * @param {Ref<Nullable<T>>} containerRef - A ref to the scrollable HTML element\n */\nexport function usePreserveScroll<T extends Element = HTMLElement>(containerRef: Ref<Nullable<T>>) {\n let scrollLeft = 0;\n let scrollTop = 0;\n onActivated(() => {\n if (!containerRef.value) return;\n containerRef.value.scrollLeft = scrollLeft;\n containerRef.value.scrollTop = scrollTop;\n });\n\n onBeforeRouteLeave(() => {\n scrollLeft = containerRef.value?.scrollLeft || 0;\n scrollTop = containerRef.value?.scrollTop || 0;\n });\n}\n"],"mappings":";;;;;;;;;;;AAiBA,SAAgB,yCAAyC,KAAa;AAClE,QAAO,yBAAyB,KAAK,UAAU,CAAC,SAAS;;;;;;;AAQ7D,SAAgB,iBAAiB,aAA4D;AACzF,KAAI,YAAY,MAAO,eAAc,YAAY,MAAM;AACvD,aAAY,QAAQ;;;;;;;AAQxB,SAAgB,gBAAgB,YAA0D;AACtF,KAAI,WAAW,MAAO,cAAa,WAAW,MAAM;AACpD,YAAW,QAAQ;;;;;;;;;;;;;;;;AAiBvB,SAAgB,kBAAmD,cAAgC;CAC/F,IAAI,aAAa;CACjB,IAAI,YAAY;AAChB,mBAAkB;AACd,MAAI,CAAC,aAAa,MAAO;AACzB,eAAa,MAAM,aAAa;AAChC,eAAa,MAAM,YAAY;GACjC;AAEF,0BAAyB;AACrB,eAAa,aAAa,OAAO,cAAc;AAC/C,cAAY,aAAa,OAAO,aAAa;GAC/C"}
|
package/dist/web.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web.js","names":[],"sources":["../src/web.ts"],"sourcesContent":["import { appendRedirectParamToUrl } from './url';\n\n/**\n * Appends the current browser URL (including path, query, and hash) as the `redirect` query parameter to the given URL.\n *\n * @param {string} url - The base URL to modify\n *\n * @returns {string} A new URL with the current location as the `redirect` parameter\n */\nexport function appendRedirectParamFromCurrentLocationToUrl(url: string) {\n const currentPath = `${window.location.pathname}${window.location.search}${window.location.hash}`;\n return appendRedirectParamToUrl(url, currentPath);\n}\n\n/**\n * Navigates to the given URL, appending the current browser location\n * (path, query, and hash) as the `redirect` query parameter.\n *\n * Useful for redirecting to login or other gateways while preserving\n * the current location for post-auth navigation.\n *\n * @param {string} url - The destination URL to navigate to\n * @param {number} [delayMs] - Optional delay in milliseconds before navigation\n */\nexport function assignUrlWithRedirectParamFromCurrentLocation(url: string, delayMs?: number) {\n if (delayMs === undefined) window.location.assign(appendRedirectParamFromCurrentLocationToUrl(url));\n else return setTimeout(() => window.location.assign(appendRedirectParamFromCurrentLocationToUrl(url)), delayMs);\n}\n"],"mappings":";;;;;;;;;AASA,SAAgB,4CAA4C,KAAa;AAErE,QAAO,yBAAyB,
|
|
1
|
+
{"version":3,"file":"web.js","names":[],"sources":["../src/web.ts"],"sourcesContent":["import { appendRedirectParamToUrl } from './url';\n\n/**\n * Appends the current browser URL (including path, query, and hash) as the `redirect` query parameter to the given URL.\n *\n * @param {string} url - The base URL to modify\n *\n * @returns {string} A new URL with the current location as the `redirect` parameter\n */\nexport function appendRedirectParamFromCurrentLocationToUrl(url: string) {\n const currentPath = `${window.location.pathname}${window.location.search}${window.location.hash}`;\n return appendRedirectParamToUrl(url, currentPath);\n}\n\n/**\n * Navigates to the given URL, appending the current browser location\n * (path, query, and hash) as the `redirect` query parameter.\n *\n * Useful for redirecting to login or other gateways while preserving\n * the current location for post-auth navigation.\n *\n * @param {string} url - The destination URL to navigate to\n * @param {number} [delayMs] - Optional delay in milliseconds before navigation\n */\nexport function assignUrlWithRedirectParamFromCurrentLocation(url: string, delayMs?: number) {\n if (delayMs === undefined) window.location.assign(appendRedirectParamFromCurrentLocationToUrl(url));\n else return setTimeout(() => window.location.assign(appendRedirectParamFromCurrentLocationToUrl(url)), delayMs);\n}\n"],"mappings":";;;;;;;;;AASA,SAAgB,4CAA4C,KAAa;AAErE,QAAO,yBAAyB,KAAK,GADd,OAAO,SAAS,WAAW,OAAO,SAAS,SAAS,OAAO,SAAS,OAC1C;;;;;;;;;;;;AAarD,SAAgB,8CAA8C,KAAa,SAAkB;AACzF,KAAI,YAAY,KAAA,EAAW,QAAO,SAAS,OAAO,4CAA4C,IAAI,CAAC;KAC9F,QAAO,iBAAiB,OAAO,SAAS,OAAO,4CAA4C,IAAI,CAAC,EAAE,QAAQ"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kikiutils/shared",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "15.0.
|
|
4
|
+
"version": "15.0.3",
|
|
5
5
|
"description": "A lightweight and modular utility library for modern JavaScript and TypeScript — includes secure hashing, flexible logging, datetime tools, Vue/web helpers, storage abstraction, and more.",
|
|
6
6
|
"author": "kiki-kanri",
|
|
7
7
|
"license": "MIT",
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
"element-plus": "^2.13.7",
|
|
78
78
|
"lru-cache": "^11.3.5",
|
|
79
79
|
"millify": "^6.1.0",
|
|
80
|
-
"msgpackr": "^
|
|
80
|
+
"msgpackr": "^2.0.1",
|
|
81
81
|
"node-ssh": "^13.2.1",
|
|
82
82
|
"pino": "^10.3.1",
|
|
83
83
|
"pino-pretty": "^13.1.3",
|
|
@@ -136,12 +136,12 @@
|
|
|
136
136
|
},
|
|
137
137
|
"devDependencies": {
|
|
138
138
|
"@antfu/eslint-config": "^8.2.0",
|
|
139
|
-
"@kikiutils/eslint-config": "^9.
|
|
139
|
+
"@kikiutils/eslint-config": "^9.1.2",
|
|
140
140
|
"@kikiutils/tsconfigs": "^6.0.0",
|
|
141
141
|
"@noble/hashes": "^2.2.0",
|
|
142
142
|
"@types/node": "^25.6.0",
|
|
143
143
|
"@types/ssh2": "^1.15.5",
|
|
144
|
-
"@vitest/coverage-v8": "^4.1.
|
|
144
|
+
"@vitest/coverage-v8": "^4.1.5",
|
|
145
145
|
"async-validator": "^4.2.5",
|
|
146
146
|
"bson": "^7.2.0",
|
|
147
147
|
"changelogen": "^0.6.2",
|
|
@@ -150,21 +150,21 @@
|
|
|
150
150
|
"date-fns": "^4.1.0",
|
|
151
151
|
"decimal.js": "^10.6.0",
|
|
152
152
|
"element-plus": "^2.13.7",
|
|
153
|
-
"jsdom": "^29.
|
|
154
|
-
"knip": "^6.
|
|
153
|
+
"jsdom": "^29.1.1",
|
|
154
|
+
"knip": "^6.11.0",
|
|
155
155
|
"lru-cache": "^11.3.5",
|
|
156
156
|
"millify": "^6.1.0",
|
|
157
|
-
"msgpackr": "^
|
|
157
|
+
"msgpackr": "^2.0.1",
|
|
158
158
|
"node-ssh": "^13.2.1",
|
|
159
159
|
"pino": "^10.3.1",
|
|
160
160
|
"pino-pretty": "^13.1.3",
|
|
161
161
|
"publint": "^0.3.18",
|
|
162
|
-
"tsdown": "^0.21.
|
|
162
|
+
"tsdown": "^0.21.10",
|
|
163
163
|
"typescript": "^6.0.3",
|
|
164
164
|
"unplugin-unused": "^0.5.7",
|
|
165
|
-
"vitest": "^4.1.
|
|
166
|
-
"vue": "^3.5.
|
|
167
|
-
"vue-router": "^5.0.
|
|
165
|
+
"vitest": "^4.1.5",
|
|
166
|
+
"vue": "^3.5.33",
|
|
167
|
+
"vue-router": "^5.0.6"
|
|
168
168
|
},
|
|
169
169
|
"pnpm": {
|
|
170
170
|
"onlyBuiltDependencies": [
|
package/src/crypto-hash.ts
CHANGED
|
@@ -1,61 +1,190 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import type {
|
|
3
|
+
BinaryLike,
|
|
4
|
+
BinaryToTextEncoding,
|
|
5
|
+
} from 'node:crypto';
|
|
6
|
+
|
|
1
7
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
8
|
+
* Computes the MD5 hash of the given data.
|
|
9
|
+
*
|
|
10
|
+
* @param {BinaryLike} data - The input data to hash
|
|
11
|
+
* @param {BinaryToTextEncoding} [outputEncoding] - The output encoding (default: `'hex'`)
|
|
5
12
|
*
|
|
6
|
-
*
|
|
7
|
-
* Can only be used in Node.js/Deno/Bun runtimes.
|
|
13
|
+
* @returns {string | Buffer} The hash digest in the specified encoding
|
|
8
14
|
*
|
|
9
15
|
* @example
|
|
10
16
|
* ```typescript
|
|
11
|
-
* import {
|
|
17
|
+
* import { cryptoMd5 } from '@kikiutils/shared/crypto-hash';
|
|
12
18
|
*
|
|
13
|
-
* console.log(
|
|
19
|
+
* console.log(cryptoMd5('test')); // 33ed9a05a10b21f0...
|
|
14
20
|
* ```
|
|
15
21
|
*/
|
|
16
|
-
|
|
17
|
-
import { createHash } from 'node:crypto';
|
|
18
|
-
import type {
|
|
19
|
-
BinaryLike,
|
|
20
|
-
BinaryToTextEncoding,
|
|
21
|
-
} from 'node:crypto';
|
|
22
|
-
|
|
23
22
|
export function cryptoMd5(data: BinaryLike, outputEncoding: BinaryToTextEncoding = 'hex') {
|
|
24
23
|
return createHash('md5').update(data).digest(outputEncoding);
|
|
25
24
|
}
|
|
26
25
|
|
|
26
|
+
/**
|
|
27
|
+
* Computes the MD5 hash of the given data and returns the raw buffer.
|
|
28
|
+
*
|
|
29
|
+
* @param {BinaryLike} data - The input data to hash
|
|
30
|
+
*
|
|
31
|
+
* @returns {Buffer} The raw hash digest as a Buffer
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* import { cryptoMd5ToBuffer } from '@kikiutils/shared/crypto-hash';
|
|
36
|
+
*
|
|
37
|
+
* console.log(cryptoMd5ToBuffer('test')); // <Buffer 33 ed 9a ...>
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
27
40
|
export function cryptoMd5ToBuffer(data: BinaryLike) {
|
|
28
41
|
return createHash('md5').update(data).digest();
|
|
29
42
|
}
|
|
30
43
|
|
|
44
|
+
/**
|
|
45
|
+
* Computes the SHA-3 hash of the given data using the 224-bit digest.
|
|
46
|
+
*
|
|
47
|
+
* @param {BinaryLike} data - The input data to hash
|
|
48
|
+
* @param {BinaryToTextEncoding} [outputEncoding] - The output encoding (default: `'hex'`)
|
|
49
|
+
*
|
|
50
|
+
* @returns {string | Buffer} The hash digest in the specified encoding
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* import { cryptoSha3224 } from '@kikiutils/shared/crypto-hash';
|
|
55
|
+
*
|
|
56
|
+
* console.log(cryptoSha3224('test')); // 0qW8FoqDcFmkpuqR9J3uT8YX...
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
31
59
|
export function cryptoSha3224(data: BinaryLike, outputEncoding: BinaryToTextEncoding = 'hex') {
|
|
32
60
|
return createHash('sha3-224').update(data).digest(outputEncoding);
|
|
33
61
|
}
|
|
34
62
|
|
|
63
|
+
/**
|
|
64
|
+
* Computes the SHA-3 hash of the given data using the 224-bit digest and returns the raw buffer.
|
|
65
|
+
*
|
|
66
|
+
* @param {BinaryLike} data - The input data to hash
|
|
67
|
+
*
|
|
68
|
+
* @returns {Buffer} The raw hash digest as a Buffer
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```typescript
|
|
72
|
+
* import { cryptoSha3224ToBuffer } from '@kikiutils/shared/crypto-hash';
|
|
73
|
+
*
|
|
74
|
+
* console.log(cryptoSha3224ToBuffer('test')); // <Buffer 0q W8 Fo ...>
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
35
77
|
export function cryptoSha3224ToBuffer(data: BinaryLike) {
|
|
36
78
|
return createHash('sha3-224').update(data).digest();
|
|
37
79
|
}
|
|
38
80
|
|
|
81
|
+
/**
|
|
82
|
+
* Computes the SHA-3 hash of the given data using the 256-bit digest.
|
|
83
|
+
*
|
|
84
|
+
* @param {BinaryLike} data - The input data to hash
|
|
85
|
+
* @param {BinaryToTextEncoding} [outputEncoding] - The output encoding (default: `'hex'`)
|
|
86
|
+
*
|
|
87
|
+
* @returns {string | Buffer} The hash digest in the specified encoding
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```typescript
|
|
91
|
+
* import { cryptoSha3256 } from '@kikiutils/shared/crypto-hash';
|
|
92
|
+
*
|
|
93
|
+
* console.log(cryptoSha3256('test')); // 36f028580bb02cc8272a9a020f4200e346e276ae664e45ee80745574e2f5ab80
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
39
96
|
export function cryptoSha3256(data: BinaryLike, outputEncoding: BinaryToTextEncoding = 'hex') {
|
|
40
97
|
return createHash('sha3-256').update(data).digest(outputEncoding);
|
|
41
98
|
}
|
|
42
99
|
|
|
100
|
+
/**
|
|
101
|
+
* Computes the SHA-3 hash of the given data using the 256-bit digest and returns the raw buffer.
|
|
102
|
+
*
|
|
103
|
+
* @param {BinaryLike} data - The input data to hash
|
|
104
|
+
*
|
|
105
|
+
* @returns {Buffer} The raw hash digest as a Buffer
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```typescript
|
|
109
|
+
* import { cryptoSha3256ToBuffer } from '@kikiutils/shared/crypto-hash';
|
|
110
|
+
*
|
|
111
|
+
* console.log(cryptoSha3256ToBuffer('test')); // <Buffer 36 f0 28 ...>
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
43
114
|
export function cryptoSha3256ToBuffer(data: BinaryLike) {
|
|
44
115
|
return createHash('sha3-256').update(data).digest();
|
|
45
116
|
}
|
|
46
117
|
|
|
118
|
+
/**
|
|
119
|
+
* Computes the SHA-3 hash of the given data using the 384-bit digest.
|
|
120
|
+
*
|
|
121
|
+
* @param {BinaryLike} data - The input data to hash
|
|
122
|
+
* @param {BinaryToTextEncoding} [outputEncoding] - The output encoding (default: `'hex'`)
|
|
123
|
+
*
|
|
124
|
+
* @returns {string | Buffer} The hash digest in the specified encoding
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```typescript
|
|
128
|
+
* import { cryptoSha3384 } from '@kikiutils/shared/crypto-hash';
|
|
129
|
+
*
|
|
130
|
+
* console.log(cryptoSha3384('test')); // 1Q2wQAYaZ4o8vWX5bEB2n3Y...
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
47
133
|
export function cryptoSha3384(data: BinaryLike, outputEncoding: BinaryToTextEncoding = 'hex') {
|
|
48
134
|
return createHash('sha3-384').update(data).digest(outputEncoding);
|
|
49
135
|
}
|
|
50
136
|
|
|
137
|
+
/**
|
|
138
|
+
* Computes the SHA-3 hash of the given data using the 384-bit digest and returns the raw buffer.
|
|
139
|
+
*
|
|
140
|
+
* @param {BinaryLike} data - The input data to hash
|
|
141
|
+
*
|
|
142
|
+
* @returns {Buffer} The raw hash digest as a Buffer
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```typescript
|
|
146
|
+
* import { cryptoSha3384ToBuffer } from '@kikiutils/shared/crypto-hash';
|
|
147
|
+
*
|
|
148
|
+
* console.log(cryptoSha3384ToBuffer('test')); // <Buffer 1Q 2w QZ ...>
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
51
151
|
export function cryptoSha3384ToBuffer(data: BinaryLike) {
|
|
52
152
|
return createHash('sha3-384').update(data).digest();
|
|
53
153
|
}
|
|
54
154
|
|
|
155
|
+
/**
|
|
156
|
+
* Computes the SHA-3 hash of the given data using the 512-bit digest.
|
|
157
|
+
*
|
|
158
|
+
* @param {BinaryLike} data - The input data to hash
|
|
159
|
+
* @param {BinaryToTextEncoding} [outputEncoding] - The output encoding (default: `'hex'`)
|
|
160
|
+
*
|
|
161
|
+
* @returns {string | Buffer} The hash digest in the specified encoding
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```typescript
|
|
165
|
+
* import { cryptoSha3512 } from '@kikiutils/shared/crypto-hash';
|
|
166
|
+
*
|
|
167
|
+
* console.log(cryptoSha3512('test')); // b_NQJ8FJBY9dIjm1q7...
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
55
170
|
export function cryptoSha3512(data: BinaryLike, outputEncoding: BinaryToTextEncoding = 'hex') {
|
|
56
171
|
return createHash('sha3-512').update(data).digest(outputEncoding);
|
|
57
172
|
}
|
|
58
173
|
|
|
174
|
+
/**
|
|
175
|
+
* Computes the SHA-3 hash of the given data using the 512-bit digest and returns the raw buffer.
|
|
176
|
+
*
|
|
177
|
+
* @param {BinaryLike} data - The input data to hash
|
|
178
|
+
*
|
|
179
|
+
* @returns {Buffer} The raw hash digest as a Buffer
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```typescript
|
|
183
|
+
* import { cryptoSha3512ToBuffer } from '@kikiutils/shared/crypto-hash';
|
|
184
|
+
*
|
|
185
|
+
* console.log(cryptoSha3512ToBuffer('test')); // <Buffer b_ NQ ...>
|
|
186
|
+
* ```
|
|
187
|
+
*/
|
|
59
188
|
export function cryptoSha3512ToBuffer(data: BinaryLike) {
|
|
60
189
|
return createHash('sha3-512').update(data).digest();
|
|
61
190
|
}
|
package/src/datetime.ts
CHANGED
|
@@ -42,8 +42,6 @@ export type DateRangeType = 'lastMonth' | 'lastWeek' | 'thisMonth' | 'thisWeek'
|
|
|
42
42
|
* // Format a date string
|
|
43
43
|
* console.log(formatDate('2024-07-10T00:00:00Z', 'yyyy-MM-dd')); // 2024-07-10
|
|
44
44
|
* ```
|
|
45
|
-
*
|
|
46
|
-
* @see https://date-fns.org/docs/format
|
|
47
45
|
*/
|
|
48
46
|
export function formatDate(date: DateArg<Date> & {}, format: string = 'yyyy-MM-dd HH:mm:ss', options?: FormatOptions) {
|
|
49
47
|
return dateFnsFormat(date, format, options);
|
package/src/env.ts
CHANGED
|
@@ -35,6 +35,8 @@ export class EnvironmentNotFoundError extends Error {
|
|
|
35
35
|
*
|
|
36
36
|
* @example
|
|
37
37
|
* ```typescript
|
|
38
|
+
* import { checkAndGetEnvValue } from '@kikiutils/shared/env';
|
|
39
|
+
*
|
|
38
40
|
* process.env.API_KEY = '';
|
|
39
41
|
* checkAndGetEnvValue('API_KEY'); // ✅ Returns '' (still considered "defined")
|
|
40
42
|
*
|
package/src/event-awaiter.ts
CHANGED
package/src/hash.ts
CHANGED
|
@@ -1,17 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file provides a set of functions for creating SHA-3 hash digests
|
|
3
|
-
* using different bit lengths (224, 256, 384, 512).
|
|
4
|
-
* These functions use the [@noble/hashes](https://github.com/paulmillr/noble-hashes) library to generate the hashes.
|
|
5
|
-
* Can be used in the browser, mainly for Nuxt/Vue and other frameworks compiled and executed in the browser.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```typescript
|
|
9
|
-
* import { sha3256 } from '@kikiutils/shared/hash';
|
|
10
|
-
*
|
|
11
|
-
* console.log(sha3256('test')); // 36f028580bb02cc8272a9a020f4200e346e276ae664e45ee80745574e2f5ab80
|
|
12
|
-
* ```
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
1
|
import {
|
|
16
2
|
sha3_224,
|
|
17
3
|
sha3_256,
|
|
@@ -23,18 +9,74 @@ import {
|
|
|
23
9
|
utf8ToBytes,
|
|
24
10
|
} from '@noble/hashes/utils.js';
|
|
25
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Computes the SHA-3 hash of the given data using the 224-bit digest.
|
|
14
|
+
*
|
|
15
|
+
* @param {string | Uint8Array} data - The input data to hash
|
|
16
|
+
*
|
|
17
|
+
* @returns {string} The hexadecimal hash digest
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* import { sha3224 } from '@kikiutils/shared/hash';
|
|
22
|
+
*
|
|
23
|
+
* console.log(sha3224('test')); // 0qW8FoqDcFmkpuqR9J3uT8YXVb3pWnLYgA4JqyprhqZ5H...
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
26
|
export function sha3224(data: string | Uint8Array) {
|
|
27
27
|
return bytesToHex(sha3_224(typeof data === 'string' ? utf8ToBytes(data) : data));
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
/**
|
|
31
|
+
* Computes the SHA-3 hash of the given data using the 256-bit digest.
|
|
32
|
+
*
|
|
33
|
+
* @param {string | Uint8Array} data - The input data to hash
|
|
34
|
+
*
|
|
35
|
+
* @returns {string} The hexadecimal hash digest
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* import { sha3256 } from '@kikiutils/shared/hash';
|
|
40
|
+
*
|
|
41
|
+
* console.log(sha3256('test')); // 36f028580bb02cc8272a9a020f4200e346e276ae664e45ee80745574e2f5ab80
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
30
44
|
export function sha3256(data: string | Uint8Array) {
|
|
31
45
|
return bytesToHex(sha3_256(typeof data === 'string' ? utf8ToBytes(data) : data));
|
|
32
46
|
}
|
|
33
47
|
|
|
48
|
+
/**
|
|
49
|
+
* Computes the SHA-3 hash of the given data using the 384-bit digest.
|
|
50
|
+
*
|
|
51
|
+
* @param {string | Uint8Array} data - The input data to hash
|
|
52
|
+
*
|
|
53
|
+
* @returns {string} The hexadecimal hash digest
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* import { sha3384 } from '@kikiutils/shared/hash';
|
|
58
|
+
*
|
|
59
|
+
* console.log(sha3384('test')); // 1Q2wQAYaZ4o8vWX5bEB2n3Y...
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
34
62
|
export function sha3384(data: string | Uint8Array) {
|
|
35
63
|
return bytesToHex(sha3_384(typeof data === 'string' ? utf8ToBytes(data) : data));
|
|
36
64
|
}
|
|
37
65
|
|
|
66
|
+
/**
|
|
67
|
+
* Computes the SHA-3 hash of the given data using the 512-bit digest.
|
|
68
|
+
*
|
|
69
|
+
* @param {string | Uint8Array} data - The input data to hash
|
|
70
|
+
*
|
|
71
|
+
* @returns {string} The hexadecimal hash digest
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* import { sha3512 } from '@kikiutils/shared/hash';
|
|
76
|
+
*
|
|
77
|
+
* console.log(sha3512('test')); // b_NQJ8FJBY9dIjm1q7...
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
38
80
|
export function sha3512(data: string | Uint8Array) {
|
|
39
81
|
return bytesToHex(sha3_512(typeof data === 'string' ? utf8ToBytes(data) : data));
|
|
40
82
|
}
|
package/src/math.ts
CHANGED
|
@@ -51,7 +51,8 @@ export function toPercentageString(
|
|
|
51
51
|
const molecularDecimal = new Decimal(molecular.toString());
|
|
52
52
|
const denominatorDecimal = new Decimal(denominator.toString());
|
|
53
53
|
const calculationResult = molecularDecimal.div(denominatorDecimal);
|
|
54
|
-
|
|
54
|
+
|
|
55
|
+
const result = calculationResult.isNaN() || !calculationResult.isFinite()
|
|
55
56
|
? '0.00'
|
|
56
57
|
: calculationResult.times(100).toFixed(options?.decimalPlaces ?? 2);
|
|
57
58
|
|