@kikiutils/shared 9.0.0 → 9.2.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 +23 -3
- package/dist/clipboard.cjs +87 -0
- package/dist/clipboard.cjs.map +1 -0
- package/dist/clipboard.d.ts +60 -0
- package/dist/clipboard.d.ts.map +1 -0
- package/dist/clipboard.mjs +84 -0
- package/dist/clipboard.mjs.map +1 -0
- package/dist/consola.cjs +1 -1
- package/dist/consola.cjs.map +1 -1
- package/dist/consola.d.ts +1 -1
- package/dist/consola.mjs +1 -1
- package/dist/consola.mjs.map +1 -1
- package/dist/crypto-hash.cjs +1 -0
- package/dist/crypto-hash.cjs.map +1 -1
- package/dist/crypto-hash.d.ts +1 -0
- package/dist/crypto-hash.d.ts.map +1 -1
- package/dist/crypto-hash.mjs +1 -0
- package/dist/crypto-hash.mjs.map +1 -1
- package/dist/datetime.cjs +3 -0
- package/dist/datetime.cjs.map +1 -1
- package/dist/datetime.d.ts +3 -0
- package/dist/datetime.d.ts.map +1 -1
- package/dist/datetime.mjs +3 -0
- package/dist/datetime.mjs.map +1 -1
- package/dist/enum.cjs +2 -0
- package/dist/enum.cjs.map +1 -1
- package/dist/enum.d.ts +2 -0
- package/dist/enum.d.ts.map +1 -1
- package/dist/enum.mjs +2 -0
- package/dist/enum.mjs.map +1 -1
- package/dist/env.cjs +2 -0
- package/dist/env.cjs.map +1 -1
- package/dist/env.d.ts +2 -0
- package/dist/env.d.ts.map +1 -1
- package/dist/env.mjs +2 -0
- package/dist/env.mjs.map +1 -1
- package/dist/general.cjs.map +1 -1
- package/dist/general.d.ts +1 -0
- package/dist/general.d.ts.map +1 -1
- package/dist/general.mjs.map +1 -1
- package/dist/math.cjs +1 -0
- package/dist/math.cjs.map +1 -1
- package/dist/math.d.ts +3 -0
- package/dist/math.d.ts.map +1 -1
- package/dist/math.mjs +1 -0
- package/dist/math.mjs.map +1 -1
- package/dist/number.cjs +1 -0
- package/dist/number.cjs.map +1 -1
- package/dist/number.d.ts +1 -0
- package/dist/number.d.ts.map +1 -1
- package/dist/number.mjs +1 -0
- package/dist/number.mjs.map +1 -1
- package/dist/pino.cjs +1 -1
- package/dist/pino.cjs.map +1 -1
- package/dist/pino.d.ts +1 -1
- package/dist/pino.mjs +1 -1
- package/dist/pino.mjs.map +1 -1
- package/dist/random.cjs +8 -7
- package/dist/random.cjs.map +1 -1
- package/dist/random.d.ts +8 -7
- package/dist/random.d.ts.map +1 -1
- package/dist/random.mjs +8 -7
- package/dist/random.mjs.map +1 -1
- package/dist/string.cjs +1 -0
- package/dist/string.cjs.map +1 -1
- package/dist/string.d.ts +1 -0
- package/dist/string.d.ts.map +1 -1
- package/dist/string.mjs +1 -0
- package/dist/string.mjs.map +1 -1
- package/dist/url.cjs +21 -0
- package/dist/url.cjs.map +1 -0
- package/dist/url.d.ts +12 -0
- package/dist/url.d.ts.map +1 -0
- package/dist/url.mjs +19 -0
- package/dist/url.mjs.map +1 -0
- package/dist/vue.cjs +64 -0
- package/dist/vue.cjs.map +1 -0
- package/dist/vue.d.ts +31 -0
- package/dist/vue.d.ts.map +1 -0
- package/dist/vue.mjs +59 -0
- package/dist/vue.mjs.map +1 -0
- package/dist/web.cjs +18 -0
- package/dist/web.cjs.map +1 -0
- package/dist/web.d.ts +9 -0
- package/dist/web.d.ts.map +1 -0
- package/dist/web.mjs +16 -0
- package/dist/web.mjs.map +1 -0
- package/package.json +5 -2
- package/src/clipboard.ts +85 -0
- package/src/consola.ts +1 -1
- package/src/crypto-hash.ts +1 -0
- package/src/datetime.ts +3 -0
- package/src/enum.ts +2 -0
- package/src/env.ts +2 -0
- package/src/general.ts +1 -0
- package/src/math.ts +3 -0
- package/src/number.ts +1 -0
- package/src/pino.ts +1 -1
- package/src/random.ts +8 -7
- package/src/string.ts +1 -0
- package/src/url.ts +16 -0
- package/src/vue.ts +62 -0
- package/src/web.ts +13 -0
package/dist/url.mjs
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Appends or updates the `redirect` query parameter on a given URL.
|
|
3
|
+
*
|
|
4
|
+
* Typically used to preserve the user's current path for post-login navigation.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} url - The target URL to modify.
|
|
7
|
+
* @param {string} redirectPath - The path to use as the redirect destination.
|
|
8
|
+
*
|
|
9
|
+
* @returns {string} A new URL string with the `redirect` query parameter.
|
|
10
|
+
*/
|
|
11
|
+
function appendRedirectParamToUrl(url, redirectPath) {
|
|
12
|
+
const [base, rawQuery = ''] = url.split('?');
|
|
13
|
+
const searchParams = new URLSearchParams(rawQuery);
|
|
14
|
+
searchParams.set('redirect', redirectPath);
|
|
15
|
+
return `${base}?${searchParams.toString()}`;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { appendRedirectParamToUrl };
|
|
19
|
+
//# sourceMappingURL=url.mjs.map
|
package/dist/url.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"url.mjs","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 [base, rawQuery = ''] = url.split('?');\n const searchParams = new URLSearchParams(rawQuery);\n searchParams.set('redirect', redirectPath);\n return `${base}?${searchParams.toString()}`;\n}\n"],"names":[],"mappings":"AAAA;;;;;;;;;AASG;AACa,SAAA,wBAAwB,CAAC,GAAW,EAAE,YAAoB,EAAA;AACtE,IAAA,MAAM,CAAC,IAAI,EAAE,QAAQ,GAAG,EAAE,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC;AAC5C,IAAA,MAAM,YAAY,GAAG,IAAI,eAAe,CAAC,QAAQ,CAAC;AAClD,IAAA,YAAY,CAAC,GAAG,CAAC,UAAU,EAAE,YAAY,CAAC;IAC1C,OAAO,CAAA,EAAG,IAAI,CAAI,CAAA,EAAA,YAAY,CAAC,QAAQ,EAAE,EAAE;AAC/C;;;;"}
|
package/dist/vue.cjs
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const vue = require('vue');
|
|
4
|
+
const vueRouter = require('vue-router');
|
|
5
|
+
const url = require('./url.cjs');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Appends the current Vue Router route's fullPath as the `redirect` query parameter to the given URL.
|
|
9
|
+
*
|
|
10
|
+
* @param {string} url - The base URL to modify.
|
|
11
|
+
*
|
|
12
|
+
* @returns {string} A new URL with the current route fullPath as the `redirect` parameter.
|
|
13
|
+
*/
|
|
14
|
+
function appendRedirectParamFromCurrentRouteToUrl(url$1) {
|
|
15
|
+
return url.appendRedirectParamToUrl(url$1, vueRouter.useRoute().fullPath);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Clears an interval referenced by a Vue ref and sets it to null.
|
|
19
|
+
*
|
|
20
|
+
* @param {Ref<null | ReturnType<typeof setInterval>>} intervalRef - A Vue ref holding a NodeJS.Timeout or null.
|
|
21
|
+
*/
|
|
22
|
+
function clearIntervalRef(intervalRef) {
|
|
23
|
+
if (intervalRef.value)
|
|
24
|
+
clearInterval(intervalRef.value);
|
|
25
|
+
intervalRef.value = null;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Clears a timeout referenced by a Vue ref and sets it to null.
|
|
29
|
+
*
|
|
30
|
+
* @param {Ref<null | ReturnType<typeof setTimeout>>} timeoutRef - A Vue ref holding a NodeJS.Timeout or null.
|
|
31
|
+
*/
|
|
32
|
+
function clearTimeoutRef(timeoutRef) {
|
|
33
|
+
if (timeoutRef.value)
|
|
34
|
+
clearTimeout(timeoutRef.value);
|
|
35
|
+
timeoutRef.value = null;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* A Vue composition function that remembers and restores scroll position
|
|
39
|
+
* of a scrollable container across route changes and keep-alive activation.
|
|
40
|
+
*
|
|
41
|
+
* @template T - The type of the scrollable element (defaults to HTMLElement).
|
|
42
|
+
*
|
|
43
|
+
* @param {Ref<null | T>} containerRef - A ref to the scrollable HTML element.
|
|
44
|
+
*/
|
|
45
|
+
function usePreserveScroll(containerRef) {
|
|
46
|
+
let scrollLeft = 0;
|
|
47
|
+
let scrollTop = 0;
|
|
48
|
+
vue.onActivated(() => {
|
|
49
|
+
if (!containerRef.value)
|
|
50
|
+
return;
|
|
51
|
+
containerRef.value.scrollLeft = scrollLeft;
|
|
52
|
+
containerRef.value.scrollTop = scrollTop;
|
|
53
|
+
});
|
|
54
|
+
vueRouter.onBeforeRouteLeave(() => {
|
|
55
|
+
scrollLeft = containerRef.value?.scrollLeft || 0;
|
|
56
|
+
scrollTop = containerRef.value?.scrollTop || 0;
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
exports.appendRedirectParamFromCurrentRouteToUrl = appendRedirectParamFromCurrentRouteToUrl;
|
|
61
|
+
exports.clearIntervalRef = clearIntervalRef;
|
|
62
|
+
exports.clearTimeoutRef = clearTimeoutRef;
|
|
63
|
+
exports.usePreserveScroll = usePreserveScroll;
|
|
64
|
+
//# sourceMappingURL=vue.cjs.map
|
package/dist/vue.cjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vue.cjs","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 * @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"],"names":["url","appendRedirectParamToUrl","useRoute","onActivated","onBeforeRouteLeave"],"mappings":";;;;;;AASA;;;;;;AAMG;AACG,SAAU,wCAAwC,CAACA,KAAW,EAAA;IAChE,OAAOC,4BAAwB,CAACD,KAAG,EAAEE,kBAAQ,EAAE,CAAC,QAAQ,CAAC;AAC7D;AAEA;;;;AAIG;AACG,SAAU,gBAAgB,CAAC,WAAuD,EAAA;IACpF,IAAI,WAAW,CAAC,KAAK;AAAE,QAAA,aAAa,CAAC,WAAW,CAAC,KAAK,CAAC;AACvD,IAAA,WAAW,CAAC,KAAK,GAAG,IAAI;AAC5B;AAEA;;;;AAIG;AACG,SAAU,eAAe,CAAC,UAAqD,EAAA;IACjF,IAAI,UAAU,CAAC,KAAK;AAAE,QAAA,YAAY,CAAC,UAAU,CAAC,KAAK,CAAC;AACpD,IAAA,UAAU,CAAC,KAAK,GAAG,IAAI;AAC3B;AAEA;;;;;;;AAOG;AACG,SAAU,iBAAiB,CAAkC,YAA2B,EAAA;IAC1F,IAAI,UAAU,GAAG,CAAC;IAClB,IAAI,SAAS,GAAG,CAAC;IACjBC,eAAW,CAAC,MAAK;QACb,IAAI,CAAC,YAAY,CAAC,KAAK;YAAE;AACzB,QAAA,YAAY,CAAC,KAAK,CAAC,UAAU,GAAG,UAAU;AAC1C,QAAA,YAAY,CAAC,KAAK,CAAC,SAAS,GAAG,SAAS;AAC5C,KAAC,CAAC;IAEFC,4BAAkB,CAAC,MAAK;QACpB,UAAU,GAAG,YAAY,CAAC,KAAK,EAAE,UAAU,IAAI,CAAC;QAChD,SAAS,GAAG,YAAY,CAAC,KAAK,EAAE,SAAS,IAAI,CAAC;AAClD,KAAC,CAAC;AACN;;;;;;;"}
|
package/dist/vue.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Ref } from 'vue';
|
|
2
|
+
/**
|
|
3
|
+
* Appends the current Vue Router route's fullPath as the `redirect` query parameter to the given URL.
|
|
4
|
+
*
|
|
5
|
+
* @param {string} url - The base URL to modify.
|
|
6
|
+
*
|
|
7
|
+
* @returns {string} A new URL with the current route fullPath as the `redirect` parameter.
|
|
8
|
+
*/
|
|
9
|
+
export declare function appendRedirectParamFromCurrentRouteToUrl(url: string): string;
|
|
10
|
+
/**
|
|
11
|
+
* Clears an interval referenced by a Vue ref and sets it to null.
|
|
12
|
+
*
|
|
13
|
+
* @param {Ref<null | ReturnType<typeof setInterval>>} intervalRef - A Vue ref holding a NodeJS.Timeout or null.
|
|
14
|
+
*/
|
|
15
|
+
export declare function clearIntervalRef(intervalRef: Ref<null | ReturnType<typeof setInterval>>): void;
|
|
16
|
+
/**
|
|
17
|
+
* Clears a timeout referenced by a Vue ref and sets it to null.
|
|
18
|
+
*
|
|
19
|
+
* @param {Ref<null | ReturnType<typeof setTimeout>>} timeoutRef - A Vue ref holding a NodeJS.Timeout or null.
|
|
20
|
+
*/
|
|
21
|
+
export declare function clearTimeoutRef(timeoutRef: Ref<null | ReturnType<typeof setTimeout>>): void;
|
|
22
|
+
/**
|
|
23
|
+
* A Vue composition function that remembers and restores scroll position
|
|
24
|
+
* of a scrollable container across route changes and keep-alive activation.
|
|
25
|
+
*
|
|
26
|
+
* @template T - The type of the scrollable element (defaults to HTMLElement).
|
|
27
|
+
*
|
|
28
|
+
* @param {Ref<null | T>} containerRef - A ref to the scrollable HTML element.
|
|
29
|
+
*/
|
|
30
|
+
export declare function usePreserveScroll<T extends Element = HTMLElement>(containerRef: Ref<null | T>): void;
|
|
31
|
+
//# sourceMappingURL=vue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vue.d.ts","sourceRoot":"","sources":["../src/vue.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAQ/B;;;;;;GAMG;AACH,wBAAgB,wCAAwC,CAAC,GAAG,EAAE,MAAM,UAEnE;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,GAAG,CAAC,IAAI,GAAG,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC,QAGvF;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,UAAU,EAAE,GAAG,CAAC,IAAI,GAAG,UAAU,CAAC,OAAO,UAAU,CAAC,CAAC,QAGpF;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,OAAO,GAAG,WAAW,EAAE,YAAY,EAAE,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,QAa7F"}
|
package/dist/vue.mjs
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { onActivated } from 'vue';
|
|
2
|
+
import { useRoute, onBeforeRouteLeave } from 'vue-router';
|
|
3
|
+
import { appendRedirectParamToUrl } from './url.mjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Appends the current Vue Router route's fullPath as the `redirect` query parameter to the given URL.
|
|
7
|
+
*
|
|
8
|
+
* @param {string} url - The base URL to modify.
|
|
9
|
+
*
|
|
10
|
+
* @returns {string} A new URL with the current route fullPath as the `redirect` parameter.
|
|
11
|
+
*/
|
|
12
|
+
function appendRedirectParamFromCurrentRouteToUrl(url) {
|
|
13
|
+
return appendRedirectParamToUrl(url, useRoute().fullPath);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Clears an interval referenced by a Vue ref and sets it to null.
|
|
17
|
+
*
|
|
18
|
+
* @param {Ref<null | ReturnType<typeof setInterval>>} intervalRef - A Vue ref holding a NodeJS.Timeout or null.
|
|
19
|
+
*/
|
|
20
|
+
function clearIntervalRef(intervalRef) {
|
|
21
|
+
if (intervalRef.value)
|
|
22
|
+
clearInterval(intervalRef.value);
|
|
23
|
+
intervalRef.value = null;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Clears a timeout referenced by a Vue ref and sets it to null.
|
|
27
|
+
*
|
|
28
|
+
* @param {Ref<null | ReturnType<typeof setTimeout>>} timeoutRef - A Vue ref holding a NodeJS.Timeout or null.
|
|
29
|
+
*/
|
|
30
|
+
function clearTimeoutRef(timeoutRef) {
|
|
31
|
+
if (timeoutRef.value)
|
|
32
|
+
clearTimeout(timeoutRef.value);
|
|
33
|
+
timeoutRef.value = null;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* A Vue composition function that remembers and restores scroll position
|
|
37
|
+
* of a scrollable container across route changes and keep-alive activation.
|
|
38
|
+
*
|
|
39
|
+
* @template T - The type of the scrollable element (defaults to HTMLElement).
|
|
40
|
+
*
|
|
41
|
+
* @param {Ref<null | T>} containerRef - A ref to the scrollable HTML element.
|
|
42
|
+
*/
|
|
43
|
+
function usePreserveScroll(containerRef) {
|
|
44
|
+
let scrollLeft = 0;
|
|
45
|
+
let scrollTop = 0;
|
|
46
|
+
onActivated(() => {
|
|
47
|
+
if (!containerRef.value)
|
|
48
|
+
return;
|
|
49
|
+
containerRef.value.scrollLeft = scrollLeft;
|
|
50
|
+
containerRef.value.scrollTop = scrollTop;
|
|
51
|
+
});
|
|
52
|
+
onBeforeRouteLeave(() => {
|
|
53
|
+
scrollLeft = containerRef.value?.scrollLeft || 0;
|
|
54
|
+
scrollTop = containerRef.value?.scrollTop || 0;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export { appendRedirectParamFromCurrentRouteToUrl, clearIntervalRef, clearTimeoutRef, usePreserveScroll };
|
|
59
|
+
//# sourceMappingURL=vue.mjs.map
|
package/dist/vue.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vue.mjs","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 * @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"],"names":[],"mappings":";;;;AASA;;;;;;AAMG;AACG,SAAU,wCAAwC,CAAC,GAAW,EAAA;IAChE,OAAO,wBAAwB,CAAC,GAAG,EAAE,QAAQ,EAAE,CAAC,QAAQ,CAAC;AAC7D;AAEA;;;;AAIG;AACG,SAAU,gBAAgB,CAAC,WAAuD,EAAA;IACpF,IAAI,WAAW,CAAC,KAAK;AAAE,QAAA,aAAa,CAAC,WAAW,CAAC,KAAK,CAAC;AACvD,IAAA,WAAW,CAAC,KAAK,GAAG,IAAI;AAC5B;AAEA;;;;AAIG;AACG,SAAU,eAAe,CAAC,UAAqD,EAAA;IACjF,IAAI,UAAU,CAAC,KAAK;AAAE,QAAA,YAAY,CAAC,UAAU,CAAC,KAAK,CAAC;AACpD,IAAA,UAAU,CAAC,KAAK,GAAG,IAAI;AAC3B;AAEA;;;;;;;AAOG;AACG,SAAU,iBAAiB,CAAkC,YAA2B,EAAA;IAC1F,IAAI,UAAU,GAAG,CAAC;IAClB,IAAI,SAAS,GAAG,CAAC;IACjB,WAAW,CAAC,MAAK;QACb,IAAI,CAAC,YAAY,CAAC,KAAK;YAAE;AACzB,QAAA,YAAY,CAAC,KAAK,CAAC,UAAU,GAAG,UAAU;AAC1C,QAAA,YAAY,CAAC,KAAK,CAAC,SAAS,GAAG,SAAS;AAC5C,KAAC,CAAC;IAEF,kBAAkB,CAAC,MAAK;QACpB,UAAU,GAAG,YAAY,CAAC,KAAK,EAAE,UAAU,IAAI,CAAC;QAChD,SAAS,GAAG,YAAY,CAAC,KAAK,EAAE,SAAS,IAAI,CAAC;AAClD,KAAC,CAAC;AACN;;;;"}
|
package/dist/web.cjs
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const url = require('./url.cjs');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Appends the current browser URL (including path, query, and hash) as the `redirect` query parameter to the given URL.
|
|
7
|
+
*
|
|
8
|
+
* @param {string} url - The base URL to modify.
|
|
9
|
+
*
|
|
10
|
+
* @returns {string} A new URL with the current location as the `redirect` parameter.
|
|
11
|
+
*/
|
|
12
|
+
function appendRedirectParamFromCurrentLocationToUrl(url$1) {
|
|
13
|
+
const currentPath = `${window.location.pathname}${window.location.search}${window.location.hash}`;
|
|
14
|
+
return url.appendRedirectParamToUrl(url$1, currentPath);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
exports.appendRedirectParamFromCurrentLocationToUrl = appendRedirectParamFromCurrentLocationToUrl;
|
|
18
|
+
//# sourceMappingURL=web.cjs.map
|
package/dist/web.cjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web.cjs","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"],"names":["url","appendRedirectParamToUrl"],"mappings":";;;;AAEA;;;;;;AAMG;AACG,SAAU,2CAA2C,CAACA,KAAW,EAAA;IACnE,MAAM,WAAW,GAAG,CAAG,EAAA,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAG,EAAA,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAG,EAAA,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAA,CAAE;AACjG,IAAA,OAAOC,4BAAwB,CAACD,KAAG,EAAE,WAAW,CAAC;AACrD;;;;"}
|
package/dist/web.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Appends the current browser URL (including path, query, and hash) as the `redirect` query parameter to the given URL.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} url - The base URL to modify.
|
|
5
|
+
*
|
|
6
|
+
* @returns {string} A new URL with the current location as the `redirect` parameter.
|
|
7
|
+
*/
|
|
8
|
+
export declare function appendRedirectParamFromCurrentLocationToUrl(url: string): string;
|
|
9
|
+
//# sourceMappingURL=web.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web.d.ts","sourceRoot":"","sources":["../src/web.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,wBAAgB,2CAA2C,CAAC,GAAG,EAAE,MAAM,UAGtE"}
|
package/dist/web.mjs
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { appendRedirectParamToUrl } from './url.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Appends the current browser URL (including path, query, and hash) as the `redirect` query parameter to the given URL.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} url - The base URL to modify.
|
|
7
|
+
*
|
|
8
|
+
* @returns {string} A new URL with the current location as the `redirect` parameter.
|
|
9
|
+
*/
|
|
10
|
+
function appendRedirectParamFromCurrentLocationToUrl(url) {
|
|
11
|
+
const currentPath = `${window.location.pathname}${window.location.search}${window.location.hash}`;
|
|
12
|
+
return appendRedirectParamToUrl(url, currentPath);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { appendRedirectParamFromCurrentLocationToUrl };
|
|
16
|
+
//# sourceMappingURL=web.mjs.map
|
package/dist/web.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web.mjs","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"],"names":[],"mappings":";;AAEA;;;;;;AAMG;AACG,SAAU,2CAA2C,CAAC,GAAW,EAAA;IACnE,MAAM,WAAW,GAAG,CAAG,EAAA,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAG,EAAA,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAG,EAAA,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAA,CAAE;AACjG,IAAA,OAAO,wBAAwB,CAAC,GAAG,EAAE,WAAW,CAAC;AACrD;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kikiutils/shared",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.2.0",
|
|
4
4
|
"description": "A lightweight modular utility library for JavaScript and TypeScript, offering secure hashing, flexible logging, date utilities, Vue/web helpers, and more.",
|
|
5
5
|
"author": "kiki-kanri",
|
|
6
6
|
"license": "MIT",
|
|
@@ -66,12 +66,15 @@
|
|
|
66
66
|
"date-fns": "^4.1.0",
|
|
67
67
|
"decimal.js": "^10.5.0",
|
|
68
68
|
"jest": "^29.7.0",
|
|
69
|
+
"jest-environment-jsdom": "^29.7.0",
|
|
69
70
|
"millify": "^6.1.0",
|
|
70
71
|
"pino": "^9.6.0",
|
|
71
72
|
"pino-pretty": "^13.0.0",
|
|
72
73
|
"ts-jest": "^29.3.2",
|
|
73
74
|
"ts-project-builder": "5.0.1",
|
|
74
|
-
"typescript": "^5.8.3"
|
|
75
|
+
"typescript": "^5.8.3",
|
|
76
|
+
"vue": "^3.5.13",
|
|
77
|
+
"vue-router": "^4.5.1"
|
|
75
78
|
},
|
|
76
79
|
"pnpm": {
|
|
77
80
|
"onlyBuiltDependencies": [
|
package/src/clipboard.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
type CopyResult =
|
|
2
|
+
| { error: unknown; ok: false }
|
|
3
|
+
| { ok: true };
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Attempts to copy a Blob (e.g. image, plain text, HTML) to the user's clipboard using the ClipboardItem API.
|
|
7
|
+
*
|
|
8
|
+
* ⚠️ Usage Notes:
|
|
9
|
+
* - Must be called in a **secure context** (HTTPS or localhost).
|
|
10
|
+
* - Must be called **in response to a user interaction** (e.g. click, input).
|
|
11
|
+
* - Not supported in Safari and some older browsers.
|
|
12
|
+
*
|
|
13
|
+
* @param {Blob} blob - The Blob object to copy (e.g. from a File, image, or text content).
|
|
14
|
+
* @param {ClipboardItemOptions} [options] - Optional options passed to the ClipboardItem constructor.
|
|
15
|
+
*
|
|
16
|
+
* @returns {Promise<CopyResult>} A promise resolving to a `CopyResult`:
|
|
17
|
+
* - `{ ok: true }` if the copy succeeded
|
|
18
|
+
* - `{ ok: false, error }` if the copy failed, with the error included
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const blob = new Blob(['Hello world'], { type: 'text/plain' });
|
|
23
|
+
* const result = await copyBlobToClipboard(blob);
|
|
24
|
+
* if (result.ok) {
|
|
25
|
+
* console.log('Copied blob!');
|
|
26
|
+
* } else {
|
|
27
|
+
* console.error('Copy failed:', result.error);
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export async function copyBlobToClipboard(blob: Blob, options?: ClipboardItemOptions): Promise<CopyResult> {
|
|
32
|
+
if (!navigator.clipboard?.write) {
|
|
33
|
+
return {
|
|
34
|
+
error: new Error('Clipboard.write is not supported in this browser.'),
|
|
35
|
+
ok: false,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
try {
|
|
40
|
+
const item = new ClipboardItem({ [blob.type]: blob }, options);
|
|
41
|
+
await navigator.clipboard.write([item]);
|
|
42
|
+
return { ok: true };
|
|
43
|
+
} catch (error) {
|
|
44
|
+
return {
|
|
45
|
+
error,
|
|
46
|
+
ok: false,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Attempts to copy the given text to the user's clipboard using the modern Clipboard API.
|
|
53
|
+
*
|
|
54
|
+
* ⚠️ Usage Notes:
|
|
55
|
+
* - Must be called in a **secure context** (HTTPS or localhost).
|
|
56
|
+
* - Must be called **in response to a user interaction** (e.g. click, input).
|
|
57
|
+
* - Not supported in some older browsers (especially legacy Safari).
|
|
58
|
+
*
|
|
59
|
+
* @param {string} text - The string to be copied to the clipboard.
|
|
60
|
+
*
|
|
61
|
+
* @returns {Promise<CopyResult>} A promise resolving to a `CopyResult`:
|
|
62
|
+
* - `{ ok: true }` if the copy succeeded
|
|
63
|
+
* - `{ ok: false, error }` if the copy failed, with the error included
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* const result = await copyTextToClipboard('Hello!');
|
|
68
|
+
* if (result.ok) {
|
|
69
|
+
* console.log('Copied!');
|
|
70
|
+
* } else {
|
|
71
|
+
* console.error('Copy failed:', result.error);
|
|
72
|
+
* }
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
export async function copyTextToClipboard(text: string): Promise<CopyResult> {
|
|
76
|
+
try {
|
|
77
|
+
await navigator.clipboard.writeText(text);
|
|
78
|
+
return { ok: true };
|
|
79
|
+
} catch (error) {
|
|
80
|
+
return {
|
|
81
|
+
error,
|
|
82
|
+
ok: false,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
}
|
package/src/consola.ts
CHANGED
package/src/crypto-hash.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* This file provides a set of functions for creating hash digests using different algorithms and bit lengths.
|
|
3
3
|
* It includes functions for generating SHA-3 hash digests with bit lengths of 224, 256, 384, and 512,
|
|
4
4
|
* as well as a function for generating MD5 hash digests.
|
|
5
|
+
*
|
|
5
6
|
* These functions use the Node.js crypto module to generate the hashes.
|
|
6
7
|
* Can only be used in Node.js/Deno/Bun runtimes.
|
|
7
8
|
*
|
package/src/datetime.ts
CHANGED
|
@@ -26,6 +26,7 @@ export type DateRangeType = 'lastMonth' | 'lastWeek' | 'thisMonth' | 'thisWeek'
|
|
|
26
26
|
* @param {DateArg<Date>} date - The input date to format. Can be a Date object, a timestamp, or a string.
|
|
27
27
|
* @param {string} [format] - The target format string.
|
|
28
28
|
* @param {FormatOptions} [options] - Optional formatting options passed to `date-fns/format`.
|
|
29
|
+
*
|
|
29
30
|
* @returns {string} The formatted date string.
|
|
30
31
|
*
|
|
31
32
|
* @example
|
|
@@ -58,6 +59,7 @@ export function formatDate(date: DateArg<Date> & {}, format: string = 'yyyy-MM-d
|
|
|
58
59
|
* @param {object} [options] - Optional settings.
|
|
59
60
|
* @param {boolean} [options.setEndDateToNextDayStart] - If true, set `endDate` to 00:00:00.000 of the next day.
|
|
60
61
|
* @param {Day} [options.weekStartsOn] - The start day of the week (0 = Sunday, 1 = Monday, ..., 6 = Saturday).
|
|
62
|
+
*
|
|
61
63
|
* @returns {{ startDate: Date, endDate: Date }} An object with `startDate` and `endDate`.
|
|
62
64
|
*
|
|
63
65
|
* @example
|
|
@@ -135,6 +137,7 @@ export function getDateRangeFromDate(
|
|
|
135
137
|
* Returns a `Date` object set to midnight (00:00:00) of today, with an optional day offset.
|
|
136
138
|
*
|
|
137
139
|
* @param {number} [offsetDays] - Number of days to offset from today. Can be negative.
|
|
140
|
+
*
|
|
138
141
|
* @returns {Date} A `Date` object at 00:00:00 of the offset day.
|
|
139
142
|
*
|
|
140
143
|
* @example
|
package/src/enum.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @param {Record<number | string, number | string>} data - The enumeration-like object to extract numeric values from.
|
|
5
5
|
* The keys can be numbers or strings, and the values can be numbers or strings.
|
|
6
|
+
*
|
|
6
7
|
* @returns {number[]} An array of numeric values extracted from the object.
|
|
7
8
|
*
|
|
8
9
|
* @example
|
|
@@ -27,6 +28,7 @@ export function getEnumNumberValues(data: Record<number | string, number | strin
|
|
|
27
28
|
*
|
|
28
29
|
* @param {Record<number | string, number | string>} data - The enumeration-like object to extract string values from.
|
|
29
30
|
* The keys can be numbers or strings, and the values can be numbers or strings.
|
|
31
|
+
*
|
|
30
32
|
* @returns {string[]} An array of string values extracted from the object.
|
|
31
33
|
*
|
|
32
34
|
* @example
|
package/src/env.ts
CHANGED
|
@@ -25,7 +25,9 @@ export class EnvironmentNotFoundError extends Error {
|
|
|
25
25
|
* Retrieves the value of an environment variable, or throws an error if not set.
|
|
26
26
|
*
|
|
27
27
|
* @param {string} key - The environment variable key to check.
|
|
28
|
+
*
|
|
28
29
|
* @returns {string} The value of the environment variable.
|
|
30
|
+
*
|
|
29
31
|
* @throws {EnvironmentNotFoundError} If the environment variable is not defined.
|
|
30
32
|
*
|
|
31
33
|
* @example
|
package/src/general.ts
CHANGED
package/src/math.ts
CHANGED
|
@@ -8,12 +8,14 @@ type CalculableValue = Decimal.Value | { toString: () => string };
|
|
|
8
8
|
export interface ToPercentageStringOptions {
|
|
9
9
|
/**
|
|
10
10
|
* Number of decimal places to include in the result.
|
|
11
|
+
*
|
|
11
12
|
* @default 2
|
|
12
13
|
*/
|
|
13
14
|
decimalPlaces?: number;
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
17
|
* Whether to include the '%' symbol in the result.
|
|
18
|
+
*
|
|
17
19
|
* @default true
|
|
18
20
|
*/
|
|
19
21
|
withSymbol?: boolean;
|
|
@@ -29,6 +31,7 @@ export interface ToPercentageStringOptions {
|
|
|
29
31
|
* @param {CalculableValue} molecular - The numerator of the fraction.
|
|
30
32
|
* @param {CalculableValue} denominator - The denominator of the fraction.
|
|
31
33
|
* @param {ToPercentageStringOptions} [options] - Optional output settings.
|
|
34
|
+
*
|
|
32
35
|
* @returns {string} Formatted percentage string.
|
|
33
36
|
*
|
|
34
37
|
* @example
|
package/src/number.ts
CHANGED
package/src/pino.ts
CHANGED
package/src/random.ts
CHANGED
|
@@ -8,14 +8,15 @@
|
|
|
8
8
|
*
|
|
9
9
|
* This function supports any return type by using a generic type parameter.
|
|
10
10
|
*
|
|
11
|
-
* @
|
|
11
|
+
* @template T - The return type of the generator function.
|
|
12
12
|
*
|
|
13
|
-
* @param generator - A function that accepts a length and returns a value of type T.
|
|
14
|
-
* @param minMin - Lower bound of the first random range.
|
|
15
|
-
* @param minMax - Upper bound of the first random range.
|
|
16
|
-
* @param maxMin - Lower bound of the second random range.
|
|
17
|
-
* @param maxMax - Upper bound of the second random range.
|
|
18
|
-
*
|
|
13
|
+
* @param {(length: number) => T} generator - A function that accepts a length and returns a value of type T.
|
|
14
|
+
* @param {number} minMin - Lower bound of the first random range.
|
|
15
|
+
* @param {number} minMax - Upper bound of the first random range.
|
|
16
|
+
* @param {number} maxMin - Lower bound of the second random range.
|
|
17
|
+
* @param {number} maxMax - Upper bound of the second random range.
|
|
18
|
+
*
|
|
19
|
+
* @returns {T} The result of the generator function using the computed final length.
|
|
19
20
|
*/
|
|
20
21
|
export function generateWithNestedRandomLength<T = string>(
|
|
21
22
|
generator: (length: number) => T,
|
package/src/string.ts
CHANGED
|
@@ -25,6 +25,7 @@ const CHARSETS: Record<RandomStringMode, string> = {
|
|
|
25
25
|
*
|
|
26
26
|
* @param {number} length - The length of the string to generate. Must be a positive integer.
|
|
27
27
|
* @param {RandomStringMode} [mode] - The character set to use.
|
|
28
|
+
*
|
|
28
29
|
* @returns {string} The generated random string.
|
|
29
30
|
*
|
|
30
31
|
* @throws {Error} If the length is not a positive integer or the mode is unsupported.
|
package/src/url.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Appends or updates the `redirect` query parameter on a given URL.
|
|
3
|
+
*
|
|
4
|
+
* Typically used to preserve the user's current path for post-login navigation.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} url - The target URL to modify.
|
|
7
|
+
* @param {string} redirectPath - The path to use as the redirect destination.
|
|
8
|
+
*
|
|
9
|
+
* @returns {string} A new URL string with the `redirect` query parameter.
|
|
10
|
+
*/
|
|
11
|
+
export function appendRedirectParamToUrl(url: string, redirectPath: string) {
|
|
12
|
+
const [base, rawQuery = ''] = url.split('?');
|
|
13
|
+
const searchParams = new URLSearchParams(rawQuery);
|
|
14
|
+
searchParams.set('redirect', redirectPath);
|
|
15
|
+
return `${base}?${searchParams.toString()}`;
|
|
16
|
+
}
|
package/src/vue.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { onActivated } from 'vue';
|
|
2
|
+
import type { Ref } from 'vue';
|
|
3
|
+
import {
|
|
4
|
+
onBeforeRouteLeave,
|
|
5
|
+
useRoute,
|
|
6
|
+
} from 'vue-router';
|
|
7
|
+
|
|
8
|
+
import { appendRedirectParamToUrl } from './url';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Appends the current Vue Router route's fullPath as the `redirect` query parameter to the given URL.
|
|
12
|
+
*
|
|
13
|
+
* @param {string} url - The base URL to modify.
|
|
14
|
+
*
|
|
15
|
+
* @returns {string} A new URL with the current route fullPath as the `redirect` parameter.
|
|
16
|
+
*/
|
|
17
|
+
export function appendRedirectParamFromCurrentRouteToUrl(url: string) {
|
|
18
|
+
return appendRedirectParamToUrl(url, useRoute().fullPath);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Clears an interval referenced by a Vue ref and sets it to null.
|
|
23
|
+
*
|
|
24
|
+
* @param {Ref<null | ReturnType<typeof setInterval>>} intervalRef - A Vue ref holding a NodeJS.Timeout or null.
|
|
25
|
+
*/
|
|
26
|
+
export function clearIntervalRef(intervalRef: Ref<null | ReturnType<typeof setInterval>>) {
|
|
27
|
+
if (intervalRef.value) clearInterval(intervalRef.value);
|
|
28
|
+
intervalRef.value = null;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Clears a timeout referenced by a Vue ref and sets it to null.
|
|
33
|
+
*
|
|
34
|
+
* @param {Ref<null | ReturnType<typeof setTimeout>>} timeoutRef - A Vue ref holding a NodeJS.Timeout or null.
|
|
35
|
+
*/
|
|
36
|
+
export function clearTimeoutRef(timeoutRef: Ref<null | ReturnType<typeof setTimeout>>) {
|
|
37
|
+
if (timeoutRef.value) clearTimeout(timeoutRef.value);
|
|
38
|
+
timeoutRef.value = null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* A Vue composition function that remembers and restores scroll position
|
|
43
|
+
* of a scrollable container across route changes and keep-alive activation.
|
|
44
|
+
*
|
|
45
|
+
* @template T - The type of the scrollable element (defaults to HTMLElement).
|
|
46
|
+
*
|
|
47
|
+
* @param {Ref<null | T>} containerRef - A ref to the scrollable HTML element.
|
|
48
|
+
*/
|
|
49
|
+
export function usePreserveScroll<T extends Element = HTMLElement>(containerRef: Ref<null | T>) {
|
|
50
|
+
let scrollLeft = 0;
|
|
51
|
+
let scrollTop = 0;
|
|
52
|
+
onActivated(() => {
|
|
53
|
+
if (!containerRef.value) return;
|
|
54
|
+
containerRef.value.scrollLeft = scrollLeft;
|
|
55
|
+
containerRef.value.scrollTop = scrollTop;
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
onBeforeRouteLeave(() => {
|
|
59
|
+
scrollLeft = containerRef.value?.scrollLeft || 0;
|
|
60
|
+
scrollTop = containerRef.value?.scrollTop || 0;
|
|
61
|
+
});
|
|
62
|
+
}
|
package/src/web.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { appendRedirectParamToUrl } from './url';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Appends the current browser URL (including path, query, and hash) as the `redirect` query parameter to the given URL.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} url - The base URL to modify.
|
|
7
|
+
*
|
|
8
|
+
* @returns {string} A new URL with the current location as the `redirect` parameter.
|
|
9
|
+
*/
|
|
10
|
+
export function appendRedirectParamFromCurrentLocationToUrl(url: string) {
|
|
11
|
+
const currentPath = `${window.location.pathname}${window.location.search}${window.location.hash}`;
|
|
12
|
+
return appendRedirectParamToUrl(url, currentPath);
|
|
13
|
+
}
|