@kikiutils/shared 18.0.1 → 18.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.
Files changed (156) hide show
  1. package/dist/buffer.d.ts +19 -21
  2. package/dist/buffer.d.ts.map +1 -1
  3. package/dist/buffer.js +18 -19
  4. package/dist/buffer.js.map +1 -1
  5. package/dist/classes/enhanced-date.d.ts +457 -0
  6. package/dist/classes/enhanced-date.d.ts.map +1 -0
  7. package/dist/classes/enhanced-date.js +635 -0
  8. package/dist/classes/enhanced-date.js.map +1 -0
  9. package/dist/classes/path.d.ts +211 -48
  10. package/dist/classes/path.d.ts.map +1 -1
  11. package/dist/classes/path.js +188 -54
  12. package/dist/classes/path.js.map +1 -1
  13. package/dist/classes/precision-number.d.ts +44 -39
  14. package/dist/classes/precision-number.d.ts.map +1 -1
  15. package/dist/classes/precision-number.js +51 -45
  16. package/dist/classes/precision-number.js.map +1 -1
  17. package/dist/classes/ssh-client.d.ts +3 -4
  18. package/dist/classes/ssh-client.d.ts.map +1 -1
  19. package/dist/classes/ssh-client.js +2 -2
  20. package/dist/classes/ssh-client.js.map +1 -1
  21. package/dist/clipboard.d.ts +25 -26
  22. package/dist/clipboard.d.ts.map +1 -1
  23. package/dist/clipboard.js +23 -23
  24. package/dist/clipboard.js.map +1 -1
  25. package/dist/consola.d.ts +12 -15
  26. package/dist/consola.d.ts.map +1 -1
  27. package/dist/consola.js +10 -12
  28. package/dist/consola.js.map +1 -1
  29. package/dist/crypto-hash.d.ts +65 -56
  30. package/dist/crypto-hash.d.ts.map +1 -1
  31. package/dist/crypto-hash.js +55 -45
  32. package/dist/crypto-hash.js.map +1 -1
  33. package/dist/datetime.d.ts +41 -53
  34. package/dist/datetime.d.ts.map +1 -1
  35. package/dist/datetime.js +53 -66
  36. package/dist/datetime.js.map +1 -1
  37. package/dist/element-plus.d.ts +13 -14
  38. package/dist/element-plus.d.ts.map +1 -1
  39. package/dist/element-plus.js +11 -11
  40. package/dist/element-plus.js.map +1 -1
  41. package/dist/enum.d.ts +39 -36
  42. package/dist/enum.d.ts.map +1 -1
  43. package/dist/enum.js +36 -32
  44. package/dist/enum.js.map +1 -1
  45. package/dist/env.d.ts +22 -15
  46. package/dist/env.d.ts.map +1 -1
  47. package/dist/env.js +20 -12
  48. package/dist/env.js.map +1 -1
  49. package/dist/event-awaiter.d.ts +47 -52
  50. package/dist/event-awaiter.d.ts.map +1 -1
  51. package/dist/event-awaiter.js +46 -50
  52. package/dist/event-awaiter.js.map +1 -1
  53. package/dist/general.d.ts +22 -17
  54. package/dist/general.d.ts.map +1 -1
  55. package/dist/general.js.map +1 -1
  56. package/dist/hash.d.ts +24 -21
  57. package/dist/hash.d.ts.map +1 -1
  58. package/dist/hash.js +20 -16
  59. package/dist/hash.js.map +1 -1
  60. package/dist/math.d.ts +20 -19
  61. package/dist/math.d.ts.map +1 -1
  62. package/dist/math.js +14 -12
  63. package/dist/math.js.map +1 -1
  64. package/dist/number.d.ts +10 -9
  65. package/dist/number.d.ts.map +1 -1
  66. package/dist/number.js +9 -7
  67. package/dist/number.js.map +1 -1
  68. package/dist/object.d.ts +22 -10
  69. package/dist/object.d.ts.map +1 -1
  70. package/dist/object.js +21 -8
  71. package/dist/object.js.map +1 -1
  72. package/dist/pino.d.ts +13 -15
  73. package/dist/pino.d.ts.map +1 -1
  74. package/dist/pino.js +10 -15
  75. package/dist/pino.js.map +1 -1
  76. package/dist/random.d.ts +17 -15
  77. package/dist/random.d.ts.map +1 -1
  78. package/dist/random.js +16 -13
  79. package/dist/random.js.map +1 -1
  80. package/dist/redis/script-runner.d.ts +57 -0
  81. package/dist/redis/script-runner.d.ts.map +1 -0
  82. package/dist/redis/script-runner.js +46 -0
  83. package/dist/redis/script-runner.js.map +1 -0
  84. package/dist/storages/lru/keyed-store.d.ts +18 -14
  85. package/dist/storages/lru/keyed-store.d.ts.map +1 -1
  86. package/dist/storages/lru/keyed-store.js +17 -12
  87. package/dist/storages/lru/keyed-store.js.map +1 -1
  88. package/dist/storages/redis/keyed-store.d.ts +11 -21
  89. package/dist/storages/redis/keyed-store.d.ts.map +1 -1
  90. package/dist/storages/redis/keyed-store.js +10 -19
  91. package/dist/storages/redis/keyed-store.js.map +1 -1
  92. package/dist/storages/redis/msgpack.d.ts +33 -13
  93. package/dist/storages/redis/msgpack.d.ts.map +1 -1
  94. package/dist/storages/redis/msgpack.js +32 -11
  95. package/dist/storages/redis/msgpack.js.map +1 -1
  96. package/dist/storages/redis/types.d.ts +34 -17
  97. package/dist/storages/redis/types.d.ts.map +1 -1
  98. package/dist/string.d.ts +12 -11
  99. package/dist/string.d.ts.map +1 -1
  100. package/dist/string.js +20 -15
  101. package/dist/string.js.map +1 -1
  102. package/dist/time.d.ts +26 -21
  103. package/dist/time.d.ts.map +1 -1
  104. package/dist/time.js +24 -18
  105. package/dist/time.js.map +1 -1
  106. package/dist/types/filtered-key-path.d.ts +4 -15
  107. package/dist/types/filtered-key-path.d.ts.map +1 -1
  108. package/dist/types/index.d.ts +10 -10
  109. package/dist/types/index.d.ts.map +1 -1
  110. package/dist/types/vue.d.ts +7 -7
  111. package/dist/types/vue.d.ts.map +1 -1
  112. package/dist/url.d.ts +15 -14
  113. package/dist/url.d.ts.map +1 -1
  114. package/dist/url.js +12 -10
  115. package/dist/url.js.map +1 -1
  116. package/dist/vue.d.ts +19 -21
  117. package/dist/vue.d.ts.map +1 -1
  118. package/dist/vue.js +15 -16
  119. package/dist/vue.js.map +1 -1
  120. package/dist/web.d.ts +14 -11
  121. package/dist/web.d.ts.map +1 -1
  122. package/dist/web.js +12 -8
  123. package/dist/web.js.map +1 -1
  124. package/package.json +21 -21
  125. package/src/buffer.ts +18 -19
  126. package/src/classes/enhanced-date.ts +715 -0
  127. package/src/classes/path.ts +248 -96
  128. package/src/classes/precision-number.ts +61 -53
  129. package/src/classes/ssh-client.ts +8 -5
  130. package/src/clipboard.ts +23 -23
  131. package/src/consola.ts +10 -12
  132. package/src/crypto-hash.ts +55 -45
  133. package/src/datetime.ts +65 -85
  134. package/src/element-plus.ts +11 -11
  135. package/src/enum.ts +36 -32
  136. package/src/env.ts +20 -12
  137. package/src/event-awaiter.ts +49 -50
  138. package/src/general.ts +20 -14
  139. package/src/hash.ts +20 -16
  140. package/src/math.ts +18 -16
  141. package/src/number.ts +9 -7
  142. package/src/object.ts +21 -8
  143. package/src/pino.ts +11 -15
  144. package/src/random.ts +16 -13
  145. package/src/redis/script-runner.ts +107 -0
  146. package/src/storages/lru/keyed-store.ts +17 -12
  147. package/src/storages/redis/keyed-store.ts +10 -19
  148. package/src/storages/redis/msgpack.ts +32 -11
  149. package/src/storages/redis/types.ts +32 -14
  150. package/src/string.ts +10 -8
  151. package/src/time.ts +24 -18
  152. package/src/types/filtered-key-path.ts +9 -14
  153. package/src/types/vue.ts +6 -5
  154. package/src/url.ts +12 -10
  155. package/src/vue.ts +15 -16
  156. package/src/web.ts +12 -8
@@ -1,69 +1,87 @@
1
1
  /**
2
- * Low-level Redis-like adapter interface for raw buffer operations.
2
+ * A caller-owned asynchronous adapter for Redis-like binary operations.
3
+ *
4
+ * @remarks
5
+ * Each callback performs one operation and rejects its promise on backend failure.
6
+ * TTL results use Redis conventions: `-1` means no expiry, and `-2` means the key is missing.
3
7
  */
4
8
  export interface RedisLikeAdapter {
5
9
  /**
6
- * Deletes a key and returns the number of keys deleted.
10
+ * Deletes a key and resolves to the number of keys deleted.
7
11
  */
8
12
  delete: (key: string) => Promise<number>;
9
13
 
10
14
  /**
11
- * Gets the raw buffer value for a key.
15
+ * Reads a key and resolves to its raw bytes, or `null` when the key is missing.
12
16
  */
13
17
  getBuffer: (key: string) => Promise<null | Uint8Array>;
14
18
 
15
19
  /**
16
- * Checks if a key exists.
20
+ * Checks a key and resolves to whether it exists.
17
21
  */
18
22
  has: (key: string) => Promise<boolean>;
19
23
 
20
24
  /**
21
- * Sets a raw buffer value for a key.
25
+ * Writes raw bytes and resolves to the backend acknowledgment, or no value.
22
26
  */
23
27
  setBuffer: (key: string, value: Uint8Array) => Promise<'OK' | void>;
24
28
 
25
29
  /**
26
- * Sets a raw buffer value for a key with a TTL.
30
+ * Writes raw bytes with an expiry and resolves to the backend acknowledgment, or no value.
31
+ *
32
+ * @param key - The storage key.
33
+ * @param ttlSeconds - The expiry duration in seconds.
34
+ * @param value - The raw bytes to store.
27
35
  */
28
36
  setBufferEx: (key: string, ttlSeconds: number, value: Uint8Array) => Promise<'OK' | void>;
29
37
 
30
38
  /**
31
- * Gets the TTL of a key in seconds.
39
+ * Reads a key's remaining TTL in seconds, or `-1` for no expiry and `-2` for a missing key.
32
40
  */
33
41
  ttl: (key: string) => Promise<number>;
34
42
  }
35
43
 
36
44
  /**
37
- * High-level Redis-like storage interface with typed get/set operations.
45
+ * An asynchronous Redis-like storage contract with typed reads and serialized writes.
46
+ *
47
+ * @remarks
48
+ * Operations reject on backend or serialization failure. TTL values are in seconds;
49
+ * `-1` means no expiry, and `-2` means the key is missing. Connection cleanup remains caller-owned.
38
50
  */
39
51
  export interface RedisLikeStorage {
40
52
  /**
41
- * Gets a deserialized value by key.
53
+ * Reads a deserialized value and resolves to `null` when the key is missing.
54
+ *
55
+ * @typeParam T - The expected value type; deserialization does not validate this type.
42
56
  */
43
57
  getItem: <T = unknown>(key: string) => Promise<null | T>;
44
58
 
45
59
  /**
46
- * Gets the TTL of a key in seconds.
60
+ * Reads a key's remaining TTL in seconds, or `-1` for no expiry and `-2` for a missing key.
47
61
  */
48
62
  getItemTtl: (key: string) => Promise<number>;
49
63
 
50
64
  /**
51
- * Checks if a key exists.
65
+ * Checks a key and resolves to whether it exists.
52
66
  */
53
67
  hasItem: (key: string) => Promise<boolean>;
54
68
 
55
69
  /**
56
- * Removes a key.
70
+ * Removes a key and resolves to whether a key was deleted.
57
71
  */
58
72
  removeItem: (key: string) => Promise<boolean>;
59
73
 
60
74
  /**
61
- * Sets a value for a key.
75
+ * Stores a value and resolves to whether the backend acknowledges the write.
62
76
  */
63
77
  setItem: (key: string, value: any) => Promise<boolean>;
64
78
 
65
79
  /**
66
- * Sets a value for a key with a TTL.
80
+ * Stores a value with an expiry and resolves to whether the backend acknowledges the write.
81
+ *
82
+ * @param key - The storage key.
83
+ * @param ttlSeconds - The expiry duration in seconds.
84
+ * @param value - The value to serialize and store.
67
85
  */
68
86
  setItemWithTtl: (key: string, ttlSeconds: number, value: any) => Promise<boolean>;
69
87
  }
package/src/string.ts CHANGED
@@ -26,23 +26,25 @@ const CHARSETS: Record<RandomStringMode, string> = {
26
26
  /**
27
27
  * Generates a random string of a given length using a predefined character set.
28
28
  *
29
+ * @remarks
29
30
  * Uses `Math.random`, so this helper is suitable for display tokens, placeholders,
30
31
  * and test data, but not for passwords, API keys, or other cryptographic secrets.
31
32
  *
32
- * @param {number} length - The positive integer length of the string to generate
33
- * @param {RandomStringMode} [mode] - The character set to use (default: `'alphabetic'`)
33
+ * @param length - The positive integer length of the string to generate.
34
+ * @param mode - The character set to use (default: `'alphabetic'`).
34
35
  *
35
- * @returns {string} The generated random string
36
+ * @returns The generated random string.
36
37
  *
37
- * @throws {Error} If the length is not a positive integer or the mode is unsupported
38
+ * @throws Error if the length is not a positive integer or the mode is unsupported.
38
39
  *
39
40
  * @example
40
- * ```typescript
41
+ *
42
+ * ```ts
41
43
  * import { randomString } from '@kikiutils/shared/string';
42
44
  *
43
- * randomString(8); // e.g. 'aZbXwTyQ'
44
- * randomString(6, 'numeric'); // e.g. '402398'
45
- * randomString(10, 'alphanumeric'); // e.g. 'a9Z4pQ8xY2'
45
+ * randomString(8); // For example, 'aZbXwTyQ'.
46
+ * randomString(6, 'numeric'); // For example, '402398'.
47
+ * randomString(10, 'alphanumeric'); // For example, 'a9Z4pQ8xY2'.
46
48
  * ```
47
49
  */
48
50
  export function randomString(length: number, mode: RandomStringMode = 'alphabetic') {
package/src/time.ts CHANGED
@@ -1,20 +1,21 @@
1
1
  /**
2
- * Delays execution until the specified duration elapses or the signal is aborted.
2
+ * Waits until a duration elapses or cancellation occurs without rejecting on cancellation.
3
3
  *
4
- * Aborting the signal resolves the promise normally without throwing.
4
+ * @remarks
5
+ * The promise resolves without a value when the timer completes or the signal aborts.
6
+ * An already aborted signal resolves immediately; completion removes the abort listener and clears the timer.
5
7
  *
6
- * @param {number} ms - Delay duration in milliseconds
7
- * @param {AbortSignal} [signal] - Optional signal used to end the delay early
8
- *
9
- * @returns {Promise<void>} Resolves when the delay completes or the signal is aborted
8
+ * @param ms - The delay duration in milliseconds, using native `setTimeout` timing rules.
9
+ * @param signal - The signal that ends the wait early.
10
10
  *
11
11
  * @example
12
- * ```typescript
12
+ *
13
+ * ```ts
13
14
  * import { delay } from '@kikiutils/shared/time';
14
15
  *
15
16
  * const controller = new AbortController();
16
- * setTimeout(() => controller.abort(), 1000);
17
- * await delay(5000, controller.signal); // resolves after ~1s
17
+ * controller.abort();
18
+ * await delay(5000, controller.signal);
18
19
  * ```
19
20
  */
20
21
  export function delay(ms: number, signal?: AbortSignal): Promise<void> {
@@ -37,22 +38,27 @@ export function delay(ms: number, signal?: AbortSignal): Promise<void> {
37
38
  }
38
39
 
39
40
  /**
40
- * Delays execution until the specified duration elapses or the signal is aborted.
41
+ * Waits until a duration elapses and rejects on cancellation.
41
42
  *
42
- * Aborting the signal rejects the promise with the signal's abort reason.
43
+ * @remarks
44
+ * The promise resolves without a value when the timer completes and rejects with `signal.reason` if aborted.
45
+ * An already aborted signal rejects immediately. Aborting clears the timer; timer completion removes the listener.
43
46
  *
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
47
+ * @param ms - The delay duration in milliseconds, using native `setTimeout` timing rules.
48
+ * @param signal - The signal that cancels the wait.
48
49
  *
49
50
  * @example
50
- * ```typescript
51
+ *
52
+ * ```ts
51
53
  * import { delayOrThrow } from '@kikiutils/shared/time';
52
54
  *
53
55
  * const controller = new AbortController();
54
- * setTimeout(() => controller.abort(), 1000);
55
- * await delayOrThrow(5000, controller.signal); // rejects after ~1s
56
+ * controller.abort(new Error('Canceled'));
57
+ * try {
58
+ * await delayOrThrow(5000, controller.signal);
59
+ * } catch (error) {
60
+ * console.error(error);
61
+ * }
56
62
  * ```
57
63
  */
58
64
  export function delayOrThrow(ms: number, signal?: AbortSignal): Promise<void> {
@@ -1,14 +1,8 @@
1
1
  import type { ObjectId } from 'bson';
2
2
 
3
- /**
4
- * The following types are based on or inspired by types from the Element Plus project.
5
- * Source: https://github.com/element-plus/element-plus
6
- * License: MIT (https://opensource.org/licenses/MIT)
7
- *
8
- * Original types might have been modified to suit this project’s needs.
9
- */
3
+ // Types adapted from Element Plus: https://github.com/element-plus/element-plus.
4
+ // Original license: MIT (https://opensource.org/licenses/MIT).
10
5
 
11
- /***/
12
6
  type ConditionalPath<K extends number | string, V, U> = V extends U ? `${K}` : DefaultPath<K, V, U, never>;
13
7
  type DefaultPath<
14
8
  K extends number | string,
@@ -17,16 +11,17 @@ type DefaultPath<
17
11
  RK = `${K}`,
18
12
  > = V extends TerminalType ? RK : `${K}.${FilteredKeyPath<V, U>}`;
19
13
 
14
+ /* eslint-disable style/max-len -- The existing conditional type is kept on one source line. */
15
+
20
16
  /**
21
- * A utility type that generates a union of key paths from a given object type `T`,
22
- * filtered by a specific type `U`. If `U` is
23
- * not provided, it defaults to including all key paths.
17
+ * A union of nested object key paths optionally filtered by the matching value type.
24
18
  *
25
- * @template T - The object type to traverse.
26
- * @template U - The type used to filter key paths. Defaults to `never`, meaning no filtering.
19
+ * @typeParam T - The object type to traverse.
20
+ * @typeParam U - The value type to select; `never` disables filtering.
27
21
  */
28
- // eslint-disable-next-line style/max-len
29
22
  export type FilteredKeyPath<T, U = never> = T extends ReadonlyArray<infer V> ? (IsTuple<T> extends true ? { [K in TupleKey<T>]-?: PathImpl<Exclude<K, symbol>, T[K], U> }[TupleKey<T>] : PathImpl<number, V, U>) : { [K in keyof T]-?: PathImpl<Exclude<K, symbol>, T[K], U> }[keyof T];
23
+ /* eslint-enable style/max-len */
24
+
30
25
  type IsTuple<T extends ReadonlyArray<any>> = number extends T['length'] ? false : true;
31
26
  type PathImpl<K extends number | string, V, U> = [U] extends [never] ? DefaultPath<K, V> : ConditionalPath<K, V, U>;
32
27
  type TerminalType =
package/src/types/vue.ts CHANGED
@@ -1,14 +1,15 @@
1
1
  import type { GlobalComponents } from 'vue';
2
2
 
3
3
  /**
4
- * A type that represents a reference to a Vue component instance.
5
- * The reference can be either an instance of the specified component or null.
4
+ * A nullable reference to an instance of a globally registered Vue component.
6
5
  *
7
- * @template K - The key of the component in the GlobalComponents.
6
+ * @typeParam K - The component name in Vue's `GlobalComponents` registry.
8
7
  *
9
8
  * @example
10
- * ```typescript
11
- * import type { ComponentRef } from '@kikiutils/types/vue';
9
+ *
10
+ * ```ts
11
+ * import type { ComponentRef } from '@kikiutils/shared/types/vue';
12
+ * import { ref } from 'vue';
12
13
  *
13
14
  * const keepAliveRef = ref<ComponentRef<'KeepAlive'>>(null);
14
15
  * ```
package/src/url.ts CHANGED
@@ -1,15 +1,15 @@
1
1
  /**
2
2
  * Appends or updates the `redirect` query parameter on a given URL.
3
3
  *
4
+ * @remarks
4
5
  * Typically used to preserve the user's current path for post-login navigation.
5
6
  *
6
- * @param {string} url - The target URL to modify
7
- * @param {string} redirectPath - The path to use as the redirect destination
8
- * (must be a safe same-origin application path starting with `/`)
7
+ * @param url - The target URL to modify.
8
+ * @param redirectPath - The safe same-origin application path starting with `/` to use as the redirect destination.
9
9
  *
10
- * @returns {string} A new URL string with the `redirect` query parameter
10
+ * @returns A new URL string with the `redirect` query parameter.
11
11
  *
12
- * @throws {Error} If redirectPath is not a safe same-origin application path
12
+ * @throws Error if `redirectPath` is not a safe same-origin application path.
13
13
  */
14
14
  export function appendRedirectParamToUrl(url: string, redirectPath: string) {
15
15
  // eslint-disable-next-line style/max-len
@@ -26,13 +26,14 @@ export function appendRedirectParamToUrl(url: string, redirectPath: string) {
26
26
  /**
27
27
  * Returns whether a value is a safe same-origin redirect path.
28
28
  *
29
+ * @remarks
29
30
  * Safe redirect paths are absolute application paths such as `/dashboard`.
30
31
  * Protocol-relative URLs (`//example.com`), absolute URLs, backslash paths,
31
32
  * and non-string values are rejected.
32
33
  *
33
- * @param {unknown} value - The value to check
34
+ * @param value - The value to check.
34
35
  *
35
- * @returns {boolean} Whether the value is safe to use as an application redirect path
36
+ * @returns Whether the value is safe to use as an application redirect path.
36
37
  */
37
38
  export function isSafeRedirectPath(value: unknown): value is string {
38
39
  if (typeof value !== 'string') return false;
@@ -45,13 +46,14 @@ export function isSafeRedirectPath(value: unknown): value is string {
45
46
  /**
46
47
  * Normalizes a redirect value into a safe same-origin application path.
47
48
  *
49
+ * @remarks
48
50
  * If an array is provided, the first value is checked. Unsafe values fall back
49
51
  * to the provided fallback path.
50
52
  *
51
- * @param {unknown} value - The redirect value to normalize
52
- * @param {string} fallback - The safe fallback path
53
+ * @param value - The redirect value to normalize.
54
+ * @param fallback - The caller-supplied safe fallback path; it is returned unchanged and is not validated.
53
55
  *
54
- * @returns {string} A safe redirect path
56
+ * @returns The validated input path, or the unvalidated fallback path.
55
57
  */
56
58
  export function normalizeRedirectPath(value: unknown, fallback = '/') {
57
59
  const redirectPath = Array.isArray(value) ? value[0] : value;
package/src/vue.ts CHANGED
@@ -8,20 +8,20 @@ import {
8
8
  import { appendRedirectParamToUrl } from './url';
9
9
 
10
10
  /**
11
- * Appends the current Vue Router route's fullPath as the `redirect` query parameter to the given URL.
11
+ * Appends the current Vue Router route's `fullPath` as the `redirect` query parameter to the given URL.
12
12
  *
13
- * @param {string} url - The base URL to modify
13
+ * @param url - The base URL to modify.
14
14
  *
15
- * @returns {string} A new URL with the current route fullPath as the `redirect` parameter
15
+ * @returns A new URL with the current route `fullPath` as the `redirect` parameter.
16
16
  */
17
17
  export function appendRedirectParamFromCurrentRouteToUrl(url: string) {
18
18
  return appendRedirectParamToUrl(url, useRoute().fullPath);
19
19
  }
20
20
 
21
21
  /**
22
- * Clears an interval referenced by a Vue ref and sets it to null.
22
+ * Clears an interval referenced by a Vue ref and sets it to `null`.
23
23
  *
24
- * @param {Ref<null | ReturnType<typeof setInterval>>} intervalRef - A Vue ref holding a NodeJS.Timeout or null
24
+ * @param intervalRef - A Vue ref holding a timer handle or `null`.
25
25
  */
26
26
  export function clearIntervalRef(intervalRef: Ref<null | ReturnType<typeof setInterval>>) {
27
27
  if (intervalRef.value) clearInterval(intervalRef.value);
@@ -29,9 +29,9 @@ export function clearIntervalRef(intervalRef: Ref<null | ReturnType<typeof setIn
29
29
  }
30
30
 
31
31
  /**
32
- * Clears a timeout referenced by a Vue ref and sets it to null.
32
+ * Clears a timeout referenced by a Vue ref and sets it to `null`.
33
33
  *
34
- * @param {Ref<null | ReturnType<typeof setTimeout>>} timeoutRef - A Vue ref holding a NodeJS.Timeout or null
34
+ * @param timeoutRef - A Vue ref holding a timer handle or `null`.
35
35
  */
36
36
  export function clearTimeoutRef(timeoutRef: Ref<null | ReturnType<typeof setTimeout>>) {
37
37
  if (timeoutRef.value) clearTimeout(timeoutRef.value);
@@ -39,18 +39,17 @@ export function clearTimeoutRef(timeoutRef: Ref<null | ReturnType<typeof setTime
39
39
  }
40
40
 
41
41
  /**
42
- * A Vue composition function that remembers and restores scroll position
43
- * of a scrollable container across route changes and keep-alive activation.
42
+ * Registers hooks that save and restore a container's scroll position across kept-alive route changes.
44
43
  *
45
- * Designed for use with `<KeepAlive>` components. Scroll state is saved on
46
- * route leave and restored when the component is activated again.
44
+ * @remarks
45
+ * Call within Vue component setup with Vue Router and `KeepAlive`.
46
+ * Route leave saves the current offsets, and each activation restores them to the currently referenced element.
47
+ * A missing element saves zero offsets and skips restoration. Without `KeepAlive`, unmounting discards the state.
48
+ * The hooks follow the component lifecycle; there is no separate cleanup handle.
47
49
  *
48
- * Note: Without `<KeepAlive>`, the component state is destroyed on unmount,
49
- * so scroll position will not be preserved.
50
+ * @typeParam T - The scrollable element type.
50
51
  *
51
- * @template T - The type of the scrollable element (defaults to HTMLElement)
52
- *
53
- * @param {Ref<null | T>} containerRef - A ref to the scrollable HTML element
52
+ * @param containerRef - The reference to the scrollable element, or `null` while it is unavailable.
54
53
  */
55
54
  export function usePreserveScroll<T extends Element = HTMLElement>(containerRef: Ref<null | T>) {
56
55
  let scrollLeft = 0;
package/src/web.ts CHANGED
@@ -3,9 +3,9 @@ import { appendRedirectParamToUrl } from './url';
3
3
  /**
4
4
  * Appends the current browser URL (including path, query, and hash) as the `redirect` query parameter to the given URL.
5
5
  *
6
- * @param {string} url - The base URL to modify
6
+ * @param url - The base URL to modify.
7
7
  *
8
- * @returns {string} A new URL with the current location as the `redirect` parameter
8
+ * @returns A new URL with the current location as the `redirect` parameter.
9
9
  */
10
10
  export function appendRedirectParamFromCurrentLocationToUrl(url: string) {
11
11
  const currentPath = `${window.location.pathname}${window.location.search}${window.location.hash}`;
@@ -13,14 +13,18 @@ export function appendRedirectParamFromCurrentLocationToUrl(url: string) {
13
13
  }
14
14
 
15
15
  /**
16
- * Navigates to the given URL, appending the current browser location
17
- * (path, query, and hash) as the `redirect` query parameter.
16
+ * Navigates to a URL with the current browser path, query, and hash as its redirect parameter.
18
17
  *
19
- * Useful for redirecting to login or other gateways while preserving
20
- * the current location for post-auth navigation.
18
+ * @remarks
19
+ * Omitting `delayMs` navigates immediately. Providing a delay, including `0`, schedules navigation;
20
+ * the current location is read when the timer fires, not when the timer is created.
21
+ * Requires a browser environment. Redirect-path validation errors propagate from the URL helper.
21
22
  *
22
- * @param {string} url - The destination URL to navigate to
23
- * @param {number} [delayMs] - Optional delay in milliseconds before navigation
23
+ * @param url - The destination URL.
24
+ * @param delayMs - The navigation delay in milliseconds, using native `setTimeout` timing rules.
25
+ *
26
+ * @returns A timer handle when delayed, which the caller can cancel with `clearTimeout`, or `undefined`
27
+ * when navigation is immediate.
24
28
  */
25
29
  export function assignUrlWithRedirectParamFromCurrentLocation(url: string, delayMs?: number) {
26
30
  if (delayMs === undefined) window.location.assign(appendRedirectParamFromCurrentLocationToUrl(url));