@kikiutils/shared 15.1.1 → 17.0.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/README.md +1 -1
- package/dist/buffer.d.ts +0 -1
- package/dist/buffer.d.ts.map +1 -1
- package/dist/classes/path.d.ts +0 -1
- package/dist/classes/path.d.ts.map +1 -1
- package/dist/classes/path.js.map +1 -1
- package/dist/classes/precision-number.d.ts +0 -1
- package/dist/classes/precision-number.d.ts.map +1 -1
- package/dist/classes/precision-number.js.map +1 -1
- package/dist/classes/ssh-client.d.ts +4 -7
- package/dist/classes/ssh-client.d.ts.map +1 -1
- package/dist/classes/ssh-client.js.map +1 -1
- package/dist/clipboard.d.ts.map +1 -1
- package/dist/consola.d.ts +2 -4
- package/dist/consola.d.ts.map +1 -1
- package/dist/crypto-hash.d.ts +11 -12
- package/dist/crypto-hash.d.ts.map +1 -1
- package/dist/crypto-hash.js +19 -15
- package/dist/crypto-hash.js.map +1 -1
- package/dist/datetime.d.ts +0 -1
- package/dist/datetime.d.ts.map +1 -1
- package/dist/element-plus.d.ts +0 -1
- package/dist/element-plus.d.ts.map +1 -1
- package/dist/enum.d.ts.map +1 -1
- package/dist/enum.js.map +1 -1
- package/dist/env.d.ts.map +1 -1
- package/dist/event-awaiter.d.ts.map +1 -1
- package/dist/general.d.ts.map +1 -1
- package/dist/hash.d.ts.map +1 -1
- package/dist/math.d.ts +0 -1
- package/dist/math.d.ts.map +1 -1
- package/dist/math.js.map +1 -1
- package/dist/number.d.ts +0 -1
- package/dist/number.d.ts.map +1 -1
- package/dist/object.d.ts.map +1 -1
- package/dist/object.js.map +1 -1
- package/dist/pino.d.ts +2 -4
- package/dist/pino.d.ts.map +1 -1
- package/dist/pino.js +10 -5
- package/dist/pino.js.map +1 -1
- package/dist/random.d.ts.map +1 -1
- package/dist/storages/lru/keyed-store.d.ts +0 -1
- package/dist/storages/lru/keyed-store.d.ts.map +1 -1
- package/dist/storages/redis/keyed-store.d.ts +2 -3
- package/dist/storages/redis/keyed-store.d.ts.map +1 -1
- package/dist/storages/redis/msgpack.d.ts +0 -1
- package/dist/storages/redis/msgpack.d.ts.map +1 -1
- package/dist/storages/redis/types.d.ts +2 -4
- package/dist/storages/redis/types.d.ts.map +1 -1
- package/dist/string.d.ts.map +1 -1
- package/dist/string.js +7 -10
- package/dist/string.js.map +1 -1
- package/dist/time.d.ts +29 -7
- package/dist/time.d.ts.map +1 -1
- package/dist/time.js +55 -11
- package/dist/time.js.map +1 -1
- package/dist/types/filtered-key-path.d.ts +1 -2
- package/dist/types/filtered-key-path.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -6
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/vue.d.ts +1 -3
- package/dist/types/vue.d.ts.map +1 -1
- package/dist/url.d.ts.map +1 -1
- package/dist/url.js.map +1 -1
- package/dist/vue.d.ts +6 -8
- package/dist/vue.d.ts.map +1 -1
- package/dist/vue.js +3 -3
- package/dist/vue.js.map +1 -1
- package/dist/web.d.ts.map +1 -1
- package/dist/web.js +2 -1
- package/dist/web.js.map +1 -1
- package/package.json +28 -27
- package/src/classes/ssh-client.ts +4 -6
- package/src/crypto-hash.ts +26 -24
- package/src/storages/redis/types.ts +2 -4
- package/src/time.ts +65 -15
- package/src/types/index.ts +0 -5
- package/src/types/vue.ts +1 -3
- package/src/vue.ts +6 -7
package/dist/types/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { FilteredKeyPath } from "./filtered-key-path.js";
|
|
2
2
|
import { Blob as Blob$1, Buffer, File as File$1 } from "node:buffer";
|
|
3
|
-
|
|
4
3
|
//#region src/types/index.d.ts
|
|
5
4
|
/**
|
|
6
5
|
* A generic string-keyed object for utility APIs that intentionally accept any value shape.
|
|
@@ -22,10 +21,6 @@ type MaybePartial<T> = Partial<T> | T;
|
|
|
22
21
|
* Accepts either a mutable value or a readonly view of that value.
|
|
23
22
|
*/
|
|
24
23
|
type MaybeReadonly<T> = Readonly<T> | T;
|
|
25
|
-
/**
|
|
26
|
-
* Explicitly nullable value helper.
|
|
27
|
-
*/
|
|
28
|
-
type Nullable<T> = null | T;
|
|
29
24
|
/**
|
|
30
25
|
* Number-like value represented as a number or a numeric string.
|
|
31
26
|
*/
|
|
@@ -43,5 +38,5 @@ type ReadonlyPartialRecord<K extends keyof any, T> = Readonly<PartialRecord<K, T
|
|
|
43
38
|
*/
|
|
44
39
|
type ReadonlyRecord<K extends keyof any, T> = Readonly<Record<K, T>>;
|
|
45
40
|
//#endregion
|
|
46
|
-
export { AnyRecord, BinaryInput, Booleanish, type FilteredKeyPath, MaybePartial, MaybeReadonly,
|
|
41
|
+
export { AnyRecord, BinaryInput, Booleanish, type FilteredKeyPath, MaybePartial, MaybeReadonly, Numberish, PartialRecord, ReadonlyPartialRecord, ReadonlyRecord };
|
|
47
42
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/types/index.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/types/index.ts"],"mappings":";;;;;;KAWY,YAAY;;;;KAKZ,cAAc,cAAc,OAAO,SAAS,OAAO,SAAW,SAAW;;;;KAKzE;;;;KAKA,aAAa,KAAK,QAAQ,KAAK;;;;KAK/B,cAAc,KAAK,SAAS,KAAK;;;;KAKjC;;;;KAKA,cAAc,qBAAqB,KAAK,QAAQ,OAAO,GAAG;;;;KAK1D,sBAAsB,qBAAqB,KAAK,SAAS,cAAc,GAAG;;;;KAK1E,eAAe,qBAAqB,KAAK,SAAS,OAAO,GAAG"}
|
package/dist/types/vue.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { Nullable } from "./index.js";
|
|
2
1
|
import { GlobalComponents } from "vue";
|
|
3
|
-
|
|
4
2
|
//#region src/types/vue.d.ts
|
|
5
3
|
/**
|
|
6
4
|
* A type that represents a reference to a Vue component instance.
|
|
@@ -15,7 +13,7 @@ import { GlobalComponents } from "vue";
|
|
|
15
13
|
* const keepAliveRef = ref<ComponentRef<'KeepAlive'>>(null);
|
|
16
14
|
* ```
|
|
17
15
|
*/
|
|
18
|
-
type ComponentRef<K extends keyof GlobalComponents> =
|
|
16
|
+
type ComponentRef<K extends keyof GlobalComponents> = InstanceType<GlobalComponents[K]> | null;
|
|
19
17
|
//#endregion
|
|
20
18
|
export { ComponentRef };
|
|
21
19
|
//# sourceMappingURL=vue.d.ts.map
|
package/dist/types/vue.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vue.d.ts","names":[],"sources":["../../src/types/vue.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"vue.d.ts","names":[],"sources":["../../src/types/vue.ts"],"mappings":";;;;;;;;;;;;;;;KAeY,aAAa,gBAAgB,oBAAoB,aAAa,iBAAiB"}
|
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":";;;;;;;;;;;;;;iBAagB,yBAAyB,aAAa;;;;;;;;;;;;iBAuBtC,mBAAmB,iBAAiB;;;;;;;;;;;;iBAmBpC,sBAAsB,gBAAgB"}
|
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 * (must be a safe same-origin application 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 safe same-origin application path\n */\nexport function appendRedirectParamToUrl(url: string, redirectPath: string) {\n // eslint-disable-next-line style/max-len\n if (!isSafeRedirectPath(redirectPath)) throw new Error(`Invalid redirect path: \"${redirectPath}\". Redirect paths must be safe same-origin paths starting with '/'.`);\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\n/**\n * Returns whether a value is a safe same-origin redirect path.\n *\n * Safe redirect paths are absolute application paths such as `/dashboard`.\n * Protocol-relative URLs (`//example.com`), absolute URLs, backslash paths,\n * and non-string values are rejected.\n *\n * @param {unknown} value - The value to check\n *\n * @returns {boolean} Whether the value is safe to use as an application redirect path\n */\nexport function isSafeRedirectPath(value: unknown): value is string {\n if (typeof value !== 'string') return false;\n if (!value.startsWith('/')) return false;\n if (value.startsWith('//')) return false;\n if (value.includes('\\\\')) return false;\n return true;\n}\n\n/**\n * Normalizes a redirect value into a safe same-origin application path.\n *\n * If an array is provided, the first value is checked. Unsafe values fall back\n * to the provided fallback path.\n *\n * @param {unknown} value - The redirect value to normalize\n * @param {string} fallback - The safe fallback path\n *\n * @returns {string} A safe redirect path\n */\nexport function normalizeRedirectPath(value: unknown, fallback = '/') {\n const redirectPath = Array.isArray(value) ? value[0] : value;\n return isSafeRedirectPath(redirectPath) ? redirectPath : fallback;\n}\n"],"mappings":";;;;;;;;;;;;;;AAaA,SAAgB,yBAAyB,KAAa,cAAsB;CAExE,IAAI,CAAC,mBAAmB,YAAY,GAAG,MAAM,IAAI,MAAM,2BAA2B,aAAa,oEAAoE;CAEnK,MAAM,CAAC,aAAa,WAAW,MAAM,IAAI,MAAM,GAAG;CAClD,MAAM,CAAC,MAAM,SAAS,eAAe,
|
|
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 a safe same-origin application 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 safe same-origin application path\n */\nexport function appendRedirectParamToUrl(url: string, redirectPath: string) {\n // eslint-disable-next-line style/max-len\n if (!isSafeRedirectPath(redirectPath)) throw new Error(`Invalid redirect path: \"${redirectPath}\". Redirect paths must be safe same-origin paths starting with '/'.`);\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\n/**\n * Returns whether a value is a safe same-origin redirect path.\n *\n * Safe redirect paths are absolute application paths such as `/dashboard`.\n * Protocol-relative URLs (`//example.com`), absolute URLs, backslash paths,\n * and non-string values are rejected.\n *\n * @param {unknown} value - The value to check\n *\n * @returns {boolean} Whether the value is safe to use as an application redirect path\n */\nexport function isSafeRedirectPath(value: unknown): value is string {\n if (typeof value !== 'string') return false;\n if (!value.startsWith('/')) return false;\n if (value.startsWith('//')) return false;\n if (value.includes('\\\\')) return false;\n return true;\n}\n\n/**\n * Normalizes a redirect value into a safe same-origin application path.\n *\n * If an array is provided, the first value is checked. Unsafe values fall back\n * to the provided fallback path.\n *\n * @param {unknown} value - The redirect value to normalize\n * @param {string} fallback - The safe fallback path\n *\n * @returns {string} A safe redirect path\n */\nexport function normalizeRedirectPath(value: unknown, fallback = '/') {\n const redirectPath = Array.isArray(value) ? value[0] : value;\n return isSafeRedirectPath(redirectPath) ? redirectPath : fallback;\n}\n"],"mappings":";;;;;;;;;;;;;;AAaA,SAAgB,yBAAyB,KAAa,cAAsB;CAExE,IAAI,CAAC,mBAAmB,YAAY,GAAG,MAAM,IAAI,MAAM,2BAA2B,aAAa,oEAAoE;CAEnK,MAAM,CAAC,aAAa,WAAW,MAAM,IAAI,MAAM,GAAG;CAClD,MAAM,CAAC,MAAM,SAAS,eAAe,GAAA,CAAI,MAAM,GAAG;CAClD,MAAM,eAAe,IAAI,gBAAgB,QAAQ;CACjD,aAAa,IAAI,YAAY,YAAY;CACzC,MAAM,cAAc,aAAa,SAAS;CAC1C,OAAO,OAAO,GAAG,KAAK,GAAG,YAAY,GAAG,SAAS,GAAG,KAAK,GAAG;AAChE;;;;;;;;;;;;AAaA,SAAgB,mBAAmB,OAAiC;CAChE,IAAI,OAAO,UAAU,UAAU,OAAO;CACtC,IAAI,CAAC,MAAM,WAAW,GAAG,GAAG,OAAO;CACnC,IAAI,MAAM,WAAW,IAAI,GAAG,OAAO;CACnC,IAAI,MAAM,SAAS,IAAI,GAAG,OAAO;CACjC,OAAO;AACX;;;;;;;;;;;;AAaA,SAAgB,sBAAsB,OAAgB,WAAW,KAAK;CAClE,MAAM,eAAe,MAAM,QAAQ,KAAK,IAAI,MAAM,KAAK;CACvD,OAAO,mBAAmB,YAAY,IAAI,eAAe;AAC7D"}
|
package/dist/vue.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { Nullable } from "./types/index.js";
|
|
2
1
|
import { Ref } from "vue";
|
|
3
|
-
|
|
4
2
|
//#region src/vue.d.ts
|
|
5
3
|
/**
|
|
6
4
|
* Appends the current Vue Router route's fullPath as the `redirect` query parameter to the given URL.
|
|
@@ -13,15 +11,15 @@ declare function appendRedirectParamFromCurrentRouteToUrl(url: string): string;
|
|
|
13
11
|
/**
|
|
14
12
|
* Clears an interval referenced by a Vue ref and sets it to null.
|
|
15
13
|
*
|
|
16
|
-
* @param {Ref<
|
|
14
|
+
* @param {Ref<null | ReturnType<typeof setInterval>>} intervalRef - A Vue ref holding a NodeJS.Timeout or null
|
|
17
15
|
*/
|
|
18
|
-
declare function clearIntervalRef(intervalRef: Ref<
|
|
16
|
+
declare function clearIntervalRef(intervalRef: Ref<null | ReturnType<typeof setInterval>>): void;
|
|
19
17
|
/**
|
|
20
18
|
* Clears a timeout referenced by a Vue ref and sets it to null.
|
|
21
19
|
*
|
|
22
|
-
* @param {Ref<
|
|
20
|
+
* @param {Ref<null | ReturnType<typeof setTimeout>>} timeoutRef - A Vue ref holding a NodeJS.Timeout or null
|
|
23
21
|
*/
|
|
24
|
-
declare function clearTimeoutRef(timeoutRef: Ref<
|
|
22
|
+
declare function clearTimeoutRef(timeoutRef: Ref<null | ReturnType<typeof setTimeout>>): void;
|
|
25
23
|
/**
|
|
26
24
|
* A Vue composition function that remembers and restores scroll position
|
|
27
25
|
* of a scrollable container across route changes and keep-alive activation.
|
|
@@ -34,9 +32,9 @@ declare function clearTimeoutRef(timeoutRef: Ref<Nullable<ReturnType<typeof setT
|
|
|
34
32
|
*
|
|
35
33
|
* @template T - The type of the scrollable element (defaults to HTMLElement)
|
|
36
34
|
*
|
|
37
|
-
* @param {Ref<
|
|
35
|
+
* @param {Ref<null | T>} containerRef - A ref to the scrollable HTML element
|
|
38
36
|
*/
|
|
39
|
-
declare function usePreserveScroll<T extends Element = HTMLElement>(containerRef: Ref<
|
|
37
|
+
declare function usePreserveScroll<T extends Element = HTMLElement>(containerRef: Ref<null | T>): void;
|
|
40
38
|
//#endregion
|
|
41
39
|
export { appendRedirectParamFromCurrentRouteToUrl, clearIntervalRef, clearTimeoutRef, usePreserveScroll };
|
|
42
40
|
//# sourceMappingURL=vue.d.ts.map
|
package/dist/vue.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vue.d.ts","names":[],"sources":["../src/vue.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"vue.d.ts","names":[],"sources":["../src/vue.ts"],"mappings":";;;;;;;;;iBAgBgB,yCAAyC;;;;;;iBASzC,iBAAiB,aAAa,WAAW,kBAAkB;;;;;;iBAU3D,gBAAgB,YAAY,WAAW,kBAAkB;;;;;;;;;;;;;;;iBAmBzD,kBAAkB,UAAU,UAAU,aAAa,cAAc,WAAW"}
|
package/dist/vue.js
CHANGED
|
@@ -15,7 +15,7 @@ function appendRedirectParamFromCurrentRouteToUrl(url) {
|
|
|
15
15
|
/**
|
|
16
16
|
* Clears an interval referenced by a Vue ref and sets it to null.
|
|
17
17
|
*
|
|
18
|
-
* @param {Ref<
|
|
18
|
+
* @param {Ref<null | ReturnType<typeof setInterval>>} intervalRef - A Vue ref holding a NodeJS.Timeout or null
|
|
19
19
|
*/
|
|
20
20
|
function clearIntervalRef(intervalRef) {
|
|
21
21
|
if (intervalRef.value) clearInterval(intervalRef.value);
|
|
@@ -24,7 +24,7 @@ function clearIntervalRef(intervalRef) {
|
|
|
24
24
|
/**
|
|
25
25
|
* Clears a timeout referenced by a Vue ref and sets it to null.
|
|
26
26
|
*
|
|
27
|
-
* @param {Ref<
|
|
27
|
+
* @param {Ref<null | ReturnType<typeof setTimeout>>} timeoutRef - A Vue ref holding a NodeJS.Timeout or null
|
|
28
28
|
*/
|
|
29
29
|
function clearTimeoutRef(timeoutRef) {
|
|
30
30
|
if (timeoutRef.value) clearTimeout(timeoutRef.value);
|
|
@@ -42,7 +42,7 @@ function clearTimeoutRef(timeoutRef) {
|
|
|
42
42
|
*
|
|
43
43
|
* @template T - The type of the scrollable element (defaults to HTMLElement)
|
|
44
44
|
*
|
|
45
|
-
* @param {Ref<
|
|
45
|
+
* @param {Ref<null | T>} containerRef - A ref to the scrollable HTML element
|
|
46
46
|
*/
|
|
47
47
|
function usePreserveScroll(containerRef) {
|
|
48
48
|
let scrollLeft = 0;
|
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
|
|
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 { 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<null | ReturnType<typeof setInterval>>} intervalRef - A Vue ref holding a NodeJS.Timeout or null\n */\nexport function clearIntervalRef(intervalRef: Ref<null | 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<null | ReturnType<typeof setTimeout>>} timeoutRef - A Vue ref holding a NodeJS.Timeout or null\n */\nexport function clearTimeoutRef(timeoutRef: Ref<null | 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<null | T>} containerRef - A ref to the scrollable HTML element\n */\nexport function usePreserveScroll<T extends Element = HTMLElement>(containerRef: Ref<null | 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":";;;;;;;;;;;AAgBA,SAAgB,yCAAyC,KAAa;CAClE,OAAO,yBAAyB,KAAK,SAAS,CAAC,CAAC,QAAQ;AAC5D;;;;;;AAOA,SAAgB,iBAAiB,aAAyD;CACtF,IAAI,YAAY,OAAO,cAAc,YAAY,KAAK;CACtD,YAAY,QAAQ;AACxB;;;;;;AAOA,SAAgB,gBAAgB,YAAuD;CACnF,IAAI,WAAW,OAAO,aAAa,WAAW,KAAK;CACnD,WAAW,QAAQ;AACvB;;;;;;;;;;;;;;;AAgBA,SAAgB,kBAAmD,cAA6B;CAC5F,IAAI,aAAa;CACjB,IAAI,YAAY;CAChB,kBAAkB;EACd,IAAI,CAAC,aAAa,OAAO;EACzB,aAAa,MAAM,aAAa;EAChC,aAAa,MAAM,YAAY;CACnC,CAAC;CAED,yBAAyB;EACrB,aAAa,aAAa,OAAO,cAAc;EAC/C,YAAY,aAAa,OAAO,aAAa;CACjD,CAAC;AACL"}
|
package/dist/web.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web.d.ts","names":[],"sources":["../src/web.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"web.d.ts","names":[],"sources":["../src/web.ts"],"mappings":";;;;;;;;iBASgB,4CAA4C;;;;;;;;;;;iBAe5C,8CAA8C,aAAa,mBAAgB,OAAA"}
|
package/dist/web.js
CHANGED
|
@@ -8,7 +8,8 @@ import { appendRedirectParamToUrl } from "./url.js";
|
|
|
8
8
|
* @returns {string} A new URL with the current location as the `redirect` parameter
|
|
9
9
|
*/
|
|
10
10
|
function appendRedirectParamFromCurrentLocationToUrl(url) {
|
|
11
|
-
|
|
11
|
+
const currentPath = `${window.location.pathname}${window.location.search}${window.location.hash}`;
|
|
12
|
+
return appendRedirectParamToUrl(url, currentPath);
|
|
12
13
|
}
|
|
13
14
|
/**
|
|
14
15
|
* Navigates to the given URL, appending the current browser location
|
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;
|
|
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;CACrE,MAAM,cAAc,GAAG,OAAO,SAAS,WAAW,OAAO,SAAS,SAAS,OAAO,SAAS;CAC3F,OAAO,yBAAyB,KAAK,WAAW;AACpD;;;;;;;;;;;AAYA,SAAgB,8CAA8C,KAAa,SAAkB;CACzF,IAAI,YAAY,KAAA,GAAW,OAAO,SAAS,OAAO,4CAA4C,GAAG,CAAC;MAC7F,OAAO,iBAAiB,OAAO,SAAS,OAAO,4CAA4C,GAAG,CAAC,GAAG,OAAO;AAClH"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kikiutils/shared",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "17.0.0",
|
|
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",
|
|
@@ -67,21 +67,21 @@
|
|
|
67
67
|
"typecheck": "tsc -b --noEmit"
|
|
68
68
|
},
|
|
69
69
|
"peerDependencies": {
|
|
70
|
-
"@noble/hashes": "^2.
|
|
70
|
+
"@noble/hashes": "^2.3.0",
|
|
71
71
|
"@types/ssh2": "^1.15.5",
|
|
72
72
|
"async-validator": "^4.2.5",
|
|
73
|
-
"bson": "^7.2
|
|
73
|
+
"bson": "^7.3.2",
|
|
74
74
|
"consola": "^3.4.2",
|
|
75
|
-
"date-fns": "^4.
|
|
75
|
+
"date-fns": "^4.4.0",
|
|
76
76
|
"decimal.js": "^10.6.0",
|
|
77
|
-
"element-plus": "^2.
|
|
78
|
-
"lru-cache": "^11.
|
|
77
|
+
"element-plus": "^2.14.4",
|
|
78
|
+
"lru-cache": "^11.5.2",
|
|
79
79
|
"millify": "^6.1.0",
|
|
80
|
-
"msgpackr": "^2.0.
|
|
80
|
+
"msgpackr": "^2.0.5",
|
|
81
81
|
"node-ssh": "^13.2.1",
|
|
82
82
|
"pino": "^10.3.1",
|
|
83
83
|
"pino-pretty": "^13.1.3",
|
|
84
|
-
"vue": "^3.5.
|
|
84
|
+
"vue": "^3.5.41",
|
|
85
85
|
"vue-router": ">= 4.6.4"
|
|
86
86
|
},
|
|
87
87
|
"peerDependenciesMeta": {
|
|
@@ -135,35 +135,36 @@
|
|
|
135
135
|
}
|
|
136
136
|
},
|
|
137
137
|
"devDependencies": {
|
|
138
|
-
"@antfu/eslint-config": "^9.
|
|
139
|
-
"@kikiutils/eslint-config": "^9.
|
|
140
|
-
"@kikiutils/tsconfigs": "^
|
|
141
|
-
"@noble/hashes": "^2.
|
|
142
|
-
"@types/node": "^
|
|
138
|
+
"@antfu/eslint-config": "^9.3.0",
|
|
139
|
+
"@kikiutils/eslint-config": "^9.2.0",
|
|
140
|
+
"@kikiutils/tsconfigs": "^7.0.0",
|
|
141
|
+
"@noble/hashes": "^2.3.0",
|
|
142
|
+
"@types/node": "^26.2.0",
|
|
143
143
|
"@types/ssh2": "^1.15.5",
|
|
144
|
-
"@vitest/coverage-v8": "^4.1.
|
|
144
|
+
"@vitest/coverage-v8": "^4.1.10",
|
|
145
145
|
"async-validator": "^4.2.5",
|
|
146
|
-
"bson": "^7.2
|
|
146
|
+
"bson": "^7.3.2",
|
|
147
147
|
"changelogen": "^0.6.2",
|
|
148
148
|
"consola": "^3.4.2",
|
|
149
149
|
"cross-env": "^10.1.0",
|
|
150
|
-
"date-fns": "^4.
|
|
150
|
+
"date-fns": "^4.4.0",
|
|
151
151
|
"decimal.js": "^10.6.0",
|
|
152
|
-
"element-plus": "^2.14.
|
|
153
|
-
"
|
|
154
|
-
"
|
|
155
|
-
"
|
|
152
|
+
"element-plus": "^2.14.4",
|
|
153
|
+
"eslint": "^10.8.1",
|
|
154
|
+
"jsdom": "^30.0.1",
|
|
155
|
+
"knip": "^6.32.2",
|
|
156
|
+
"lru-cache": "^11.5.2",
|
|
156
157
|
"millify": "^6.1.0",
|
|
157
|
-
"msgpackr": "^2.0.
|
|
158
|
+
"msgpackr": "^2.0.5",
|
|
158
159
|
"node-ssh": "^13.2.1",
|
|
159
160
|
"pino": "^10.3.1",
|
|
160
161
|
"pino-pretty": "^13.1.3",
|
|
161
|
-
"publint": "^0.3.
|
|
162
|
-
"tsdown": "^0.22.
|
|
162
|
+
"publint": "^0.3.23",
|
|
163
|
+
"tsdown": "^0.22.14",
|
|
163
164
|
"typescript": "^6.0.3",
|
|
164
|
-
"unplugin-unused": "^0.
|
|
165
|
-
"vitest": "^4.1.
|
|
166
|
-
"vue": "^3.5.
|
|
167
|
-
"vue-router": "^5.0
|
|
165
|
+
"unplugin-unused": "^0.6.0",
|
|
166
|
+
"vitest": "^4.1.10",
|
|
167
|
+
"vue": "^3.5.41",
|
|
168
|
+
"vue-router": "^5.2.0"
|
|
168
169
|
}
|
|
169
170
|
}
|
|
@@ -12,8 +12,6 @@ import type {
|
|
|
12
12
|
TransferOptions,
|
|
13
13
|
} from 'ssh2';
|
|
14
14
|
|
|
15
|
-
import type { Nullable } from '../types';
|
|
16
|
-
|
|
17
15
|
import type { PathLike } from './path';
|
|
18
16
|
|
|
19
17
|
const loggerLevelStringToConsolaLogLevelMap = {
|
|
@@ -101,8 +99,8 @@ export class SshClient {
|
|
|
101
99
|
async getFile(
|
|
102
100
|
localFile: PathLike,
|
|
103
101
|
remoteFile: PathLike,
|
|
104
|
-
givenSftp?:
|
|
105
|
-
transferOptions?:
|
|
102
|
+
givenSftp?: null | SFTPWrapper,
|
|
103
|
+
transferOptions?: null | TransferOptions,
|
|
106
104
|
) {
|
|
107
105
|
try {
|
|
108
106
|
await this.#nodeSsh.getFile(localFile.toString(), remoteFile.toString(), givenSftp, transferOptions);
|
|
@@ -141,8 +139,8 @@ export class SshClient {
|
|
|
141
139
|
async putFile(
|
|
142
140
|
localFile: PathLike,
|
|
143
141
|
remoteFile: PathLike,
|
|
144
|
-
givenSftp?:
|
|
145
|
-
transferOptions?:
|
|
142
|
+
givenSftp?: null | SFTPWrapper,
|
|
143
|
+
transferOptions?: null | TransferOptions,
|
|
146
144
|
) {
|
|
147
145
|
try {
|
|
148
146
|
await this.#nodeSsh.putFile(localFile.toString(), remoteFile.toString(), givenSftp, transferOptions);
|
package/src/crypto-hash.ts
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
|
+
import { Buffer } from 'node:buffer';
|
|
1
2
|
import { createHash } from 'node:crypto';
|
|
2
|
-
import type {
|
|
3
|
-
BinaryLike,
|
|
4
|
-
BinaryToTextEncoding,
|
|
5
|
-
} from 'node:crypto';
|
|
3
|
+
import type { BinaryLike } from 'node:crypto';
|
|
6
4
|
|
|
7
5
|
/**
|
|
8
6
|
* Computes the MD5 hash of the given data.
|
|
9
7
|
*
|
|
10
8
|
* @param {BinaryLike} data - The input data to hash
|
|
11
|
-
* @param {
|
|
9
|
+
* @param {BufferEncoding} [outputEncoding] - The output encoding (default: `'hex'`)
|
|
12
10
|
*
|
|
13
11
|
* @returns {string | Buffer} The hash digest in the specified encoding
|
|
14
12
|
*
|
|
@@ -19,8 +17,8 @@ import type {
|
|
|
19
17
|
* console.log(cryptoMd5('test')); // 098f6bcd4621d373cade4e832627b4f6
|
|
20
18
|
* ```
|
|
21
19
|
*/
|
|
22
|
-
export function cryptoMd5(data: BinaryLike, outputEncoding:
|
|
23
|
-
return createHash('md5').update(data).digest(outputEncoding);
|
|
20
|
+
export function cryptoMd5(data: BinaryLike, outputEncoding: BufferEncoding = 'hex') {
|
|
21
|
+
return createHash('md5').update(normalizeHashData(data)).digest(outputEncoding);
|
|
24
22
|
}
|
|
25
23
|
|
|
26
24
|
/**
|
|
@@ -38,14 +36,14 @@ export function cryptoMd5(data: BinaryLike, outputEncoding: BinaryToTextEncoding
|
|
|
38
36
|
* ```
|
|
39
37
|
*/
|
|
40
38
|
export function cryptoMd5ToBuffer(data: BinaryLike) {
|
|
41
|
-
return createHash('md5').update(data).digest();
|
|
39
|
+
return createHash('md5').update(normalizeHashData(data)).digest();
|
|
42
40
|
}
|
|
43
41
|
|
|
44
42
|
/**
|
|
45
43
|
* Computes the SHA-3 hash of the given data using the 224-bit digest.
|
|
46
44
|
*
|
|
47
45
|
* @param {BinaryLike} data - The input data to hash
|
|
48
|
-
* @param {
|
|
46
|
+
* @param {BufferEncoding} [outputEncoding] - The output encoding (default: `'hex'`)
|
|
49
47
|
*
|
|
50
48
|
* @returns {string | Buffer} The hash digest in the specified encoding
|
|
51
49
|
*
|
|
@@ -56,8 +54,8 @@ export function cryptoMd5ToBuffer(data: BinaryLike) {
|
|
|
56
54
|
* console.log(cryptoSha3224('test')); // 3797bf0afbbfca4a7bbba7602a2b552746876517a7f9b7ce2db0ae7b
|
|
57
55
|
* ```
|
|
58
56
|
*/
|
|
59
|
-
export function cryptoSha3224(data: BinaryLike, outputEncoding:
|
|
60
|
-
return createHash('sha3-224').update(data).digest(outputEncoding);
|
|
57
|
+
export function cryptoSha3224(data: BinaryLike, outputEncoding: BufferEncoding = 'hex') {
|
|
58
|
+
return createHash('sha3-224').update(normalizeHashData(data)).digest(outputEncoding);
|
|
61
59
|
}
|
|
62
60
|
|
|
63
61
|
/**
|
|
@@ -75,14 +73,14 @@ export function cryptoSha3224(data: BinaryLike, outputEncoding: BinaryToTextEnco
|
|
|
75
73
|
* ```
|
|
76
74
|
*/
|
|
77
75
|
export function cryptoSha3224ToBuffer(data: BinaryLike) {
|
|
78
|
-
return createHash('sha3-224').update(data).digest();
|
|
76
|
+
return createHash('sha3-224').update(normalizeHashData(data)).digest();
|
|
79
77
|
}
|
|
80
78
|
|
|
81
79
|
/**
|
|
82
80
|
* Computes the SHA-3 hash of the given data using the 256-bit digest.
|
|
83
81
|
*
|
|
84
82
|
* @param {BinaryLike} data - The input data to hash
|
|
85
|
-
* @param {
|
|
83
|
+
* @param {BufferEncoding} [outputEncoding] - The output encoding (default: `'hex'`)
|
|
86
84
|
*
|
|
87
85
|
* @returns {string | Buffer} The hash digest in the specified encoding
|
|
88
86
|
*
|
|
@@ -93,8 +91,8 @@ export function cryptoSha3224ToBuffer(data: BinaryLike) {
|
|
|
93
91
|
* console.log(cryptoSha3256('test')); // 36f028580bb02cc8272a9a020f4200e346e276ae664e45ee80745574e2f5ab80
|
|
94
92
|
* ```
|
|
95
93
|
*/
|
|
96
|
-
export function cryptoSha3256(data: BinaryLike, outputEncoding:
|
|
97
|
-
return createHash('sha3-256').update(data).digest(outputEncoding);
|
|
94
|
+
export function cryptoSha3256(data: BinaryLike, outputEncoding: BufferEncoding = 'hex') {
|
|
95
|
+
return createHash('sha3-256').update(normalizeHashData(data)).digest(outputEncoding);
|
|
98
96
|
}
|
|
99
97
|
|
|
100
98
|
/**
|
|
@@ -112,14 +110,14 @@ export function cryptoSha3256(data: BinaryLike, outputEncoding: BinaryToTextEnco
|
|
|
112
110
|
* ```
|
|
113
111
|
*/
|
|
114
112
|
export function cryptoSha3256ToBuffer(data: BinaryLike) {
|
|
115
|
-
return createHash('sha3-256').update(data).digest();
|
|
113
|
+
return createHash('sha3-256').update(normalizeHashData(data)).digest();
|
|
116
114
|
}
|
|
117
115
|
|
|
118
116
|
/**
|
|
119
117
|
* Computes the SHA-3 hash of the given data using the 384-bit digest.
|
|
120
118
|
*
|
|
121
119
|
* @param {BinaryLike} data - The input data to hash
|
|
122
|
-
* @param {
|
|
120
|
+
* @param {BufferEncoding} [outputEncoding] - The output encoding (default: `'hex'`)
|
|
123
121
|
*
|
|
124
122
|
* @returns {string | Buffer} The hash digest in the specified encoding
|
|
125
123
|
*
|
|
@@ -130,8 +128,8 @@ export function cryptoSha3256ToBuffer(data: BinaryLike) {
|
|
|
130
128
|
* console.log(cryptoSha3384('test')); // e516dabb23b6e30026863543282780a3ae0dccf05551cf0295178d7f...
|
|
131
129
|
* ```
|
|
132
130
|
*/
|
|
133
|
-
export function cryptoSha3384(data: BinaryLike, outputEncoding:
|
|
134
|
-
return createHash('sha3-384').update(data).digest(outputEncoding);
|
|
131
|
+
export function cryptoSha3384(data: BinaryLike, outputEncoding: BufferEncoding = 'hex') {
|
|
132
|
+
return createHash('sha3-384').update(normalizeHashData(data)).digest(outputEncoding);
|
|
135
133
|
}
|
|
136
134
|
|
|
137
135
|
/**
|
|
@@ -149,14 +147,14 @@ export function cryptoSha3384(data: BinaryLike, outputEncoding: BinaryToTextEnco
|
|
|
149
147
|
* ```
|
|
150
148
|
*/
|
|
151
149
|
export function cryptoSha3384ToBuffer(data: BinaryLike) {
|
|
152
|
-
return createHash('sha3-384').update(data).digest();
|
|
150
|
+
return createHash('sha3-384').update(normalizeHashData(data)).digest();
|
|
153
151
|
}
|
|
154
152
|
|
|
155
153
|
/**
|
|
156
154
|
* Computes the SHA-3 hash of the given data using the 512-bit digest.
|
|
157
155
|
*
|
|
158
156
|
* @param {BinaryLike} data - The input data to hash
|
|
159
|
-
* @param {
|
|
157
|
+
* @param {BufferEncoding} [outputEncoding] - The output encoding (default: `'hex'`)
|
|
160
158
|
*
|
|
161
159
|
* @returns {string | Buffer} The hash digest in the specified encoding
|
|
162
160
|
*
|
|
@@ -167,8 +165,8 @@ export function cryptoSha3384ToBuffer(data: BinaryLike) {
|
|
|
167
165
|
* console.log(cryptoSha3512('test')); // 9ece086e9bac491fac5c1d1046ca11d737b92a2b2ebd93f005d7...
|
|
168
166
|
* ```
|
|
169
167
|
*/
|
|
170
|
-
export function cryptoSha3512(data: BinaryLike, outputEncoding:
|
|
171
|
-
return createHash('sha3-512').update(data).digest(outputEncoding);
|
|
168
|
+
export function cryptoSha3512(data: BinaryLike, outputEncoding: BufferEncoding = 'hex') {
|
|
169
|
+
return createHash('sha3-512').update(normalizeHashData(data)).digest(outputEncoding);
|
|
172
170
|
}
|
|
173
171
|
|
|
174
172
|
/**
|
|
@@ -186,5 +184,9 @@ export function cryptoSha3512(data: BinaryLike, outputEncoding: BinaryToTextEnco
|
|
|
186
184
|
* ```
|
|
187
185
|
*/
|
|
188
186
|
export function cryptoSha3512ToBuffer(data: BinaryLike) {
|
|
189
|
-
return createHash('sha3-512').update(data).digest();
|
|
187
|
+
return createHash('sha3-512').update(normalizeHashData(data)).digest();
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function normalizeHashData(data: BinaryLike): NodeJS.ArrayBufferView | string {
|
|
191
|
+
return typeof data === 'string' || ArrayBuffer.isView(data) ? data : Buffer.from(data);
|
|
190
192
|
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import type { Nullable } from '../../types';
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* Low-level Redis-like adapter interface for raw buffer operations.
|
|
5
3
|
*/
|
|
@@ -12,7 +10,7 @@ export interface RedisLikeAdapter {
|
|
|
12
10
|
/**
|
|
13
11
|
* Gets the raw buffer value for a key.
|
|
14
12
|
*/
|
|
15
|
-
getBuffer: (key: string) => Promise<
|
|
13
|
+
getBuffer: (key: string) => Promise<null | Uint8Array>;
|
|
16
14
|
|
|
17
15
|
/**
|
|
18
16
|
* Checks if a key exists.
|
|
@@ -42,7 +40,7 @@ export interface RedisLikeStorage {
|
|
|
42
40
|
/**
|
|
43
41
|
* Gets a deserialized value by key.
|
|
44
42
|
*/
|
|
45
|
-
getItem: <T = unknown>(key: string) => Promise<
|
|
43
|
+
getItem: <T = unknown>(key: string) => Promise<null | T>;
|
|
46
44
|
|
|
47
45
|
/**
|
|
48
46
|
* Gets the TTL of a key in seconds.
|
package/src/time.ts
CHANGED
|
@@ -1,31 +1,81 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Delays execution until the specified duration elapses or the signal is aborted.
|
|
3
|
+
*
|
|
4
|
+
* Aborting the signal resolves the promise normally without throwing.
|
|
3
5
|
*
|
|
4
6
|
* @param {number} ms - Delay duration in milliseconds
|
|
5
|
-
* @param {AbortSignal} [signal] - Optional
|
|
7
|
+
* @param {AbortSignal} [signal] - Optional signal used to end the delay early
|
|
6
8
|
*
|
|
7
|
-
* @returns {Promise<
|
|
9
|
+
* @returns {Promise<void>} Resolves when the delay completes or the signal is aborted
|
|
8
10
|
*
|
|
9
11
|
* @example
|
|
10
12
|
* ```typescript
|
|
11
|
-
* import {
|
|
13
|
+
* import { delay } from '@kikiutils/shared/time';
|
|
12
14
|
*
|
|
13
15
|
* const controller = new AbortController();
|
|
14
16
|
* setTimeout(() => controller.abort(), 1000);
|
|
15
|
-
* await
|
|
17
|
+
* await delay(5000, controller.signal); // resolves after ~1s
|
|
16
18
|
* ```
|
|
17
19
|
*/
|
|
18
|
-
export function
|
|
20
|
+
export function delay(ms: number, signal?: AbortSignal): Promise<void> {
|
|
19
21
|
return new Promise((resolve) => {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
);
|
|
22
|
+
if (signal?.aborted) {
|
|
23
|
+
resolve();
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const done = () => {
|
|
28
|
+
// eslint-disable-next-line ts/no-use-before-define
|
|
29
|
+
clearTimeout(timeout);
|
|
30
|
+
signal?.removeEventListener('abort', done);
|
|
31
|
+
resolve();
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const timeout = setTimeout(done, ms);
|
|
35
|
+
signal?.addEventListener('abort', done, { once: true });
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Delays execution until the specified duration elapses or the signal is aborted.
|
|
41
|
+
*
|
|
42
|
+
* Aborting the signal rejects the promise with the signal's abort reason.
|
|
43
|
+
*
|
|
44
|
+
* @param {number} ms - Delay duration in milliseconds
|
|
45
|
+
* @param {AbortSignal} [signal] - Optional signal used to abort the delay
|
|
46
|
+
*
|
|
47
|
+
* @returns {Promise<void>} Resolves when the delay completes or rejects when the signal is aborted
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```typescript
|
|
51
|
+
* import { delayOrThrow } from '@kikiutils/shared/time';
|
|
52
|
+
*
|
|
53
|
+
* const controller = new AbortController();
|
|
54
|
+
* setTimeout(() => controller.abort(), 1000);
|
|
55
|
+
* await delayOrThrow(5000, controller.signal); // rejects after ~1s
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export function delayOrThrow(ms: number, signal?: AbortSignal): Promise<void> {
|
|
59
|
+
return new Promise((resolve, reject) => {
|
|
60
|
+
if (signal?.aborted) {
|
|
61
|
+
reject(signal.reason);
|
|
62
|
+
return;
|
|
29
63
|
}
|
|
64
|
+
|
|
65
|
+
const onAbort = () => {
|
|
66
|
+
// eslint-disable-next-line ts/no-use-before-define
|
|
67
|
+
clearTimeout(timeout);
|
|
68
|
+
reject(signal!.reason);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const timeout = setTimeout(
|
|
72
|
+
() => {
|
|
73
|
+
signal?.removeEventListener('abort', onAbort);
|
|
74
|
+
resolve();
|
|
75
|
+
},
|
|
76
|
+
ms,
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
signal?.addEventListener('abort', onAbort, { once: true });
|
|
30
80
|
});
|
|
31
81
|
}
|
package/src/types/index.ts
CHANGED
|
@@ -31,11 +31,6 @@ export type MaybePartial<T> = Partial<T> | T;
|
|
|
31
31
|
*/
|
|
32
32
|
export type MaybeReadonly<T> = Readonly<T> | T;
|
|
33
33
|
|
|
34
|
-
/**
|
|
35
|
-
* Explicitly nullable value helper.
|
|
36
|
-
*/
|
|
37
|
-
export type Nullable<T> = null | T;
|
|
38
|
-
|
|
39
34
|
/**
|
|
40
35
|
* Number-like value represented as a number or a numeric string.
|
|
41
36
|
*/
|
package/src/types/vue.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import type { GlobalComponents } from 'vue';
|
|
2
2
|
|
|
3
|
-
import type { Nullable } from './';
|
|
4
|
-
|
|
5
3
|
/**
|
|
6
4
|
* A type that represents a reference to a Vue component instance.
|
|
7
5
|
* The reference can be either an instance of the specified component or null.
|
|
@@ -15,4 +13,4 @@ import type { Nullable } from './';
|
|
|
15
13
|
* const keepAliveRef = ref<ComponentRef<'KeepAlive'>>(null);
|
|
16
14
|
* ```
|
|
17
15
|
*/
|
|
18
|
-
export type ComponentRef<K extends keyof GlobalComponents> =
|
|
16
|
+
export type ComponentRef<K extends keyof GlobalComponents> = InstanceType<GlobalComponents[K]> | null;
|