@kikiutils/shared 18.0.0 → 18.1.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 +425 -0
  6. package/dist/classes/enhanced-date.d.ts.map +1 -0
  7. package/dist/classes/enhanced-date.js +591 -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 +181 -52
  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 +12 -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 +35 -10
  103. package/dist/time.d.ts.map +1 -1
  104. package/dist/time.js +49 -9
  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 +20 -20
  125. package/src/buffer.ts +18 -19
  126. package/src/classes/enhanced-date.ts +665 -0
  127. package/src/classes/path.ts +232 -91
  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 +52 -8
  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
@@ -4,39 +4,39 @@ import { Blob as Blob$1, Buffer, File as File$1 } from "node:buffer";
4
4
  /**
5
5
  * A generic string-keyed object for utility APIs that intentionally accept any value shape.
6
6
  */
7
- type AnyRecord = Record<string, any>;
7
+ export type AnyRecord = Record<string, any>;
8
8
  /**
9
9
  * Binary-like inputs accepted by `toBuffer` across browser and Node.js runtimes.
10
10
  */
11
- type BinaryInput = ArrayBuffer | Blob | Buffer | File | Blob$1 | File$1 | Uint8Array;
11
+ export type BinaryInput = ArrayBuffer | Blob | Buffer | File | Blob$1 | File$1 | Uint8Array;
12
12
  /**
13
13
  * Boolean values represented either as booleans or common string literals.
14
14
  */
15
- type Booleanish = 'false' | 'true' | boolean;
15
+ export type Booleanish = 'false' | 'true' | boolean;
16
16
  /**
17
17
  * Accepts either a full object or a partial patch of that object.
18
18
  */
19
- type MaybePartial<T> = Partial<T> | T;
19
+ export type MaybePartial<T> = Partial<T> | T;
20
20
  /**
21
21
  * Accepts either a mutable value or a readonly view of that value.
22
22
  */
23
- type MaybeReadonly<T> = Readonly<T> | T;
23
+ export type MaybeReadonly<T> = Readonly<T> | T;
24
24
  /**
25
25
  * Number-like value represented as a number or a numeric string.
26
26
  */
27
- type Numberish = number | string;
27
+ export type Numberish = number | string;
28
28
  /**
29
29
  * A `Record` where every key is optional.
30
30
  */
31
- type PartialRecord<K extends keyof any, T> = Partial<Record<K, T>>;
31
+ export type PartialRecord<K extends keyof any, T> = Partial<Record<K, T>>;
32
32
  /**
33
33
  * A readonly `PartialRecord`.
34
34
  */
35
- type ReadonlyPartialRecord<K extends keyof any, T> = Readonly<PartialRecord<K, T>>;
35
+ export type ReadonlyPartialRecord<K extends keyof any, T> = Readonly<PartialRecord<K, T>>;
36
36
  /**
37
37
  * A readonly `Record`.
38
38
  */
39
- type ReadonlyRecord<K extends keyof any, T> = Readonly<Record<K, T>>;
39
+ export type ReadonlyRecord<K extends keyof any, T> = Readonly<Record<K, T>>;
40
40
  //#endregion
41
- export { AnyRecord, BinaryInput, Booleanish, type FilteredKeyPath, MaybePartial, MaybeReadonly, Numberish, PartialRecord, ReadonlyPartialRecord, ReadonlyRecord };
41
+ export type { FilteredKeyPath };
42
42
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
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"}
1
+ {"version":3,"file":"index.d.ts","names":["NodeBlob","NodeFile"],"sources":["../../src/types/index.ts"],"mappings":";;;;;;YAWY,YAAY;;;;YAKZ,cAAc,cAAc,OAAO,SAAS,OAAOA,SAAWC,SAAW;;;;YAKzE;;;;YAKA,aAAa,KAAK,QAAQ,KAAK;;;;YAK/B,cAAc,KAAK,SAAS,KAAK;;;;YAKjC;;;;YAKA,cAAc,qBAAqB,KAAK,QAAQ,OAAO,GAAG;;;;YAK1D,sBAAsB,qBAAqB,KAAK,SAAS,cAAc,GAAG;;;;YAK1E,eAAe,qBAAqB,KAAK,SAAS,OAAO,GAAG"}
@@ -1,19 +1,19 @@
1
1
  import { GlobalComponents } from "vue";
2
2
  //#region src/types/vue.d.ts
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
  * ```
15
16
  */
16
- type ComponentRef<K extends keyof GlobalComponents> = InstanceType<GlobalComponents[K]> | null;
17
+ export type ComponentRef<K extends keyof GlobalComponents> = InstanceType<GlobalComponents[K]> | null;
17
18
  //#endregion
18
- export { ComponentRef };
19
19
  //# sourceMappingURL=vue.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"vue.d.ts","names":[],"sources":["../../src/types/vue.ts"],"mappings":";;;;;;;;;;;;;;;KAeY,aAAa,gBAAgB,oBAAoB,aAAa,iBAAiB"}
1
+ {"version":3,"file":"vue.d.ts","names":[],"sources":["../../src/types/vue.ts"],"mappings":";;;;;;;;;;;;;;;;YAgBY,aAAa,gBAAgB,oBAAoB,aAAa,iBAAiB"}
package/dist/url.d.ts CHANGED
@@ -2,41 +2,42 @@
2
2
  /**
3
3
  * Appends or updates the `redirect` query parameter on a given URL.
4
4
  *
5
+ * @remarks
5
6
  * Typically used to preserve the user's current path for post-login navigation.
6
7
  *
7
- * @param {string} url - The target URL to modify
8
- * @param {string} redirectPath - The path to use as the redirect destination
9
- * (must be a safe same-origin application path starting with `/`)
8
+ * @param url - The target URL to modify.
9
+ * @param redirectPath - The safe same-origin application path starting with `/` to use as the redirect destination.
10
10
  *
11
- * @returns {string} A new URL string with the `redirect` query parameter
11
+ * @returns A new URL string with the `redirect` query parameter.
12
12
  *
13
- * @throws {Error} If redirectPath is not a safe same-origin application path
13
+ * @throws Error if `redirectPath` is not a safe same-origin application path.
14
14
  */
15
- declare function appendRedirectParamToUrl(url: string, redirectPath: string): string;
15
+ export declare function appendRedirectParamToUrl(url: string, redirectPath: string): string;
16
16
  /**
17
17
  * Returns whether a value is a safe same-origin redirect path.
18
18
  *
19
+ * @remarks
19
20
  * Safe redirect paths are absolute application paths such as `/dashboard`.
20
21
  * Protocol-relative URLs (`//example.com`), absolute URLs, backslash paths,
21
22
  * and non-string values are rejected.
22
23
  *
23
- * @param {unknown} value - The value to check
24
+ * @param value - The value to check.
24
25
  *
25
- * @returns {boolean} Whether the value is safe to use as an application redirect path
26
+ * @returns Whether the value is safe to use as an application redirect path.
26
27
  */
27
- declare function isSafeRedirectPath(value: unknown): value is string;
28
+ export declare function isSafeRedirectPath(value: unknown): value is string;
28
29
  /**
29
30
  * Normalizes a redirect value into a safe same-origin application path.
30
31
  *
32
+ * @remarks
31
33
  * If an array is provided, the first value is checked. Unsafe values fall back
32
34
  * to the provided fallback path.
33
35
  *
34
- * @param {unknown} value - The redirect value to normalize
35
- * @param {string} fallback - The safe fallback path
36
+ * @param value - The redirect value to normalize.
37
+ * @param fallback - The caller-supplied safe fallback path; it is returned unchanged and is not validated.
36
38
  *
37
- * @returns {string} A safe redirect path
39
+ * @returns The validated input path, or the unvalidated fallback path.
38
40
  */
39
- declare function normalizeRedirectPath(value: unknown, fallback?: string): string;
41
+ export declare function normalizeRedirectPath(value: unknown, fallback?: string): string;
40
42
  //#endregion
41
- export { appendRedirectParamToUrl, isSafeRedirectPath, normalizeRedirectPath };
42
43
  //# sourceMappingURL=url.d.ts.map
package/dist/url.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"url.d.ts","names":[],"sources":["../src/url.ts"],"mappings":";;;;;;;;;;;;;;iBAagB,yBAAyB,aAAa;;;;;;;;;;;;iBAuBtC,mBAAmB,iBAAiB;;;;;;;;;;;;iBAmBpC,sBAAsB,gBAAgB"}
1
+ {"version":3,"file":"url.d.ts","names":[],"sources":["../src/url.ts"],"mappings":";;;;;;;;;;;;;;wBAagB,yBAAyB,aAAa;;;;;;;;;;;;;wBAwBtC,mBAAmB,iBAAiB;;;;;;;;;;;;;wBAoBpC,sBAAsB,gBAAgB"}
package/dist/url.js CHANGED
@@ -2,15 +2,15 @@
2
2
  /**
3
3
  * Appends or updates the `redirect` query parameter on a given URL.
4
4
  *
5
+ * @remarks
5
6
  * Typically used to preserve the user's current path for post-login navigation.
6
7
  *
7
- * @param {string} url - The target URL to modify
8
- * @param {string} redirectPath - The path to use as the redirect destination
9
- * (must be a safe same-origin application path starting with `/`)
8
+ * @param url - The target URL to modify.
9
+ * @param redirectPath - The safe same-origin application path starting with `/` to use as the redirect destination.
10
10
  *
11
- * @returns {string} A new URL string with the `redirect` query parameter
11
+ * @returns A new URL string with the `redirect` query parameter.
12
12
  *
13
- * @throws {Error} If redirectPath is not a safe same-origin application path
13
+ * @throws Error if `redirectPath` is not a safe same-origin application path.
14
14
  */
15
15
  function appendRedirectParamToUrl(url, redirectPath) {
16
16
  if (!isSafeRedirectPath(redirectPath)) throw new Error(`Invalid redirect path: "${redirectPath}". Redirect paths must be safe same-origin paths starting with '/'.`);
@@ -24,13 +24,14 @@ function appendRedirectParamToUrl(url, redirectPath) {
24
24
  /**
25
25
  * Returns whether a value is a safe same-origin redirect path.
26
26
  *
27
+ * @remarks
27
28
  * Safe redirect paths are absolute application paths such as `/dashboard`.
28
29
  * Protocol-relative URLs (`//example.com`), absolute URLs, backslash paths,
29
30
  * and non-string values are rejected.
30
31
  *
31
- * @param {unknown} value - The value to check
32
+ * @param value - The value to check.
32
33
  *
33
- * @returns {boolean} Whether the value is safe to use as an application redirect path
34
+ * @returns Whether the value is safe to use as an application redirect path.
34
35
  */
35
36
  function isSafeRedirectPath(value) {
36
37
  if (typeof value !== "string") return false;
@@ -42,13 +43,14 @@ function isSafeRedirectPath(value) {
42
43
  /**
43
44
  * Normalizes a redirect value into a safe same-origin application path.
44
45
  *
46
+ * @remarks
45
47
  * If an array is provided, the first value is checked. Unsafe values fall back
46
48
  * to the provided fallback path.
47
49
  *
48
- * @param {unknown} value - The redirect value to normalize
49
- * @param {string} fallback - The safe fallback path
50
+ * @param value - The redirect value to normalize.
51
+ * @param fallback - The caller-supplied safe fallback path; it is returned unchanged and is not validated.
50
52
  *
51
- * @returns {string} A safe redirect path
53
+ * @returns The validated input path, or the unvalidated fallback path.
52
54
  */
53
55
  function normalizeRedirectPath(value, fallback = "/") {
54
56
  const redirectPath = Array.isArray(value) ? value[0] : value;
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,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"}
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 * @remarks\n * Typically used to preserve the user's current path for post-login navigation.\n *\n * @param url - The target URL to modify.\n * @param redirectPath - The safe same-origin application path starting with `/` to use as the redirect destination.\n *\n * @returns 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 * @remarks\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 value - The value to check.\n *\n * @returns 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 * @remarks\n * If an array is provided, the first value is checked. Unsafe values fall back\n * to the provided fallback path.\n *\n * @param value - The redirect value to normalize.\n * @param fallback - The caller-supplied safe fallback path; it is returned unchanged and is not validated.\n *\n * @returns The validated input path, or the unvalidated fallback 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;;;;;;;;;;;;;AAcA,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;;;;;;;;;;;;;AAcA,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,40 +1,38 @@
1
1
  import { Ref } from "vue";
2
2
  //#region src/vue.d.ts
3
3
  /**
4
- * Appends the current Vue Router route's fullPath as the `redirect` query parameter to the given URL.
4
+ * Appends the current Vue Router route's `fullPath` 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 route fullPath as the `redirect` parameter
8
+ * @returns A new URL with the current route `fullPath` as the `redirect` parameter.
9
9
  */
10
- declare function appendRedirectParamFromCurrentRouteToUrl(url: string): string;
10
+ export declare function appendRedirectParamFromCurrentRouteToUrl(url: string): string;
11
11
  /**
12
- * Clears an interval referenced by a Vue ref and sets it to null.
12
+ * Clears an interval referenced by a Vue ref and sets it to `null`.
13
13
  *
14
- * @param {Ref<null | ReturnType<typeof setInterval>>} intervalRef - A Vue ref holding a NodeJS.Timeout or null
14
+ * @param intervalRef - A Vue ref holding a timer handle or `null`.
15
15
  */
16
- declare function clearIntervalRef(intervalRef: Ref<null | ReturnType<typeof setInterval>>): void;
16
+ export declare function clearIntervalRef(intervalRef: Ref<null | ReturnType<typeof setInterval>>): void;
17
17
  /**
18
- * Clears a timeout referenced by a Vue ref and sets it to null.
18
+ * Clears a timeout referenced by a Vue ref and sets it to `null`.
19
19
  *
20
- * @param {Ref<null | ReturnType<typeof setTimeout>>} timeoutRef - A Vue ref holding a NodeJS.Timeout or null
20
+ * @param timeoutRef - A Vue ref holding a timer handle or `null`.
21
21
  */
22
- declare function clearTimeoutRef(timeoutRef: Ref<null | ReturnType<typeof setTimeout>>): void;
22
+ export declare function clearTimeoutRef(timeoutRef: Ref<null | ReturnType<typeof setTimeout>>): void;
23
23
  /**
24
- * A Vue composition function that remembers and restores scroll position
25
- * of a scrollable container across route changes and keep-alive activation.
24
+ * Registers hooks that save and restore a container's scroll position across kept-alive route changes.
26
25
  *
27
- * Designed for use with `<KeepAlive>` components. Scroll state is saved on
28
- * route leave and restored when the component is activated again.
26
+ * @remarks
27
+ * Call within Vue component setup with Vue Router and `KeepAlive`.
28
+ * Route leave saves the current offsets, and each activation restores them to the currently referenced element.
29
+ * A missing element saves zero offsets and skips restoration. Without `KeepAlive`, unmounting discards the state.
30
+ * The hooks follow the component lifecycle; there is no separate cleanup handle.
29
31
  *
30
- * Note: Without `<KeepAlive>`, the component state is destroyed on unmount,
31
- * so scroll position will not be preserved.
32
+ * @typeParam T - The scrollable element type.
32
33
  *
33
- * @template T - The type of the scrollable element (defaults to HTMLElement)
34
- *
35
- * @param {Ref<null | T>} containerRef - A ref to the scrollable HTML element
34
+ * @param containerRef - The reference to the scrollable element, or `null` while it is unavailable.
36
35
  */
37
- declare function usePreserveScroll<T extends Element = HTMLElement>(containerRef: Ref<null | T>): void;
36
+ export declare function usePreserveScroll<T extends Element = HTMLElement>(containerRef: Ref<null | T>): void;
38
37
  //#endregion
39
- export { appendRedirectParamFromCurrentRouteToUrl, clearIntervalRef, clearTimeoutRef, usePreserveScroll };
40
38
  //# 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":";;;;;;;;;iBAgBgB,yCAAyC;;;;;;iBASzC,iBAAiB,aAAa,WAAW,kBAAkB;;;;;;iBAU3D,gBAAgB,YAAY,WAAW,kBAAkB;;;;;;;;;;;;;;;iBAmBzD,kBAAkB,UAAU,UAAU,aAAa,cAAc,WAAW"}
1
+ {"version":3,"file":"vue.d.ts","names":[],"sources":["../src/vue.ts"],"mappings":";;;;;;;;;wBAgBgB,yCAAyC;;;;;;wBASzC,iBAAiB,aAAa,WAAW,kBAAkB;;;;;;wBAU3D,gBAAgB,YAAY,WAAW,kBAAkB;;;;;;;;;;;;;;wBAkBzD,kBAAkB,UAAU,UAAU,aAAa,cAAc,WAAW"}
package/dist/vue.js CHANGED
@@ -3,46 +3,45 @@ import { onActivated } from "vue";
3
3
  import { onBeforeRouteLeave, useRoute } from "vue-router";
4
4
  //#region src/vue.ts
5
5
  /**
6
- * Appends the current Vue Router route's fullPath as the `redirect` query parameter to the given URL.
6
+ * Appends the current Vue Router route's `fullPath` as the `redirect` query parameter to the given URL.
7
7
  *
8
- * @param {string} url - The base URL to modify
8
+ * @param url - The base URL to modify.
9
9
  *
10
- * @returns {string} A new URL with the current route fullPath as the `redirect` parameter
10
+ * @returns A new URL with the current route `fullPath` as the `redirect` parameter.
11
11
  */
12
12
  function appendRedirectParamFromCurrentRouteToUrl(url) {
13
13
  return appendRedirectParamToUrl(url, useRoute().fullPath);
14
14
  }
15
15
  /**
16
- * Clears an interval referenced by a Vue ref and sets it to null.
16
+ * Clears an interval referenced by a Vue ref and sets it to `null`.
17
17
  *
18
- * @param {Ref<null | ReturnType<typeof setInterval>>} intervalRef - A Vue ref holding a NodeJS.Timeout or null
18
+ * @param intervalRef - A Vue ref holding a timer handle or `null`.
19
19
  */
20
20
  function clearIntervalRef(intervalRef) {
21
21
  if (intervalRef.value) clearInterval(intervalRef.value);
22
22
  intervalRef.value = null;
23
23
  }
24
24
  /**
25
- * Clears a timeout referenced by a Vue ref and sets it to null.
25
+ * Clears a timeout referenced by a Vue ref and sets it to `null`.
26
26
  *
27
- * @param {Ref<null | ReturnType<typeof setTimeout>>} timeoutRef - A Vue ref holding a NodeJS.Timeout or null
27
+ * @param timeoutRef - A Vue ref holding a timer handle or `null`.
28
28
  */
29
29
  function clearTimeoutRef(timeoutRef) {
30
30
  if (timeoutRef.value) clearTimeout(timeoutRef.value);
31
31
  timeoutRef.value = null;
32
32
  }
33
33
  /**
34
- * A Vue composition function that remembers and restores scroll position
35
- * of a scrollable container across route changes and keep-alive activation.
34
+ * Registers hooks that save and restore a container's scroll position across kept-alive route changes.
36
35
  *
37
- * Designed for use with `<KeepAlive>` components. Scroll state is saved on
38
- * route leave and restored when the component is activated again.
36
+ * @remarks
37
+ * Call within Vue component setup with Vue Router and `KeepAlive`.
38
+ * Route leave saves the current offsets, and each activation restores them to the currently referenced element.
39
+ * A missing element saves zero offsets and skips restoration. Without `KeepAlive`, unmounting discards the state.
40
+ * The hooks follow the component lifecycle; there is no separate cleanup handle.
39
41
  *
40
- * Note: Without `<KeepAlive>`, the component state is destroyed on unmount,
41
- * so scroll position will not be preserved.
42
+ * @typeParam T - The scrollable element type.
42
43
  *
43
- * @template T - The type of the scrollable element (defaults to HTMLElement)
44
- *
45
- * @param {Ref<null | T>} containerRef - A ref to the scrollable HTML element
44
+ * @param containerRef - The reference to the scrollable element, or `null` while it is unavailable.
46
45
  */
47
46
  function usePreserveScroll(containerRef) {
48
47
  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 { 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"}
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 url - The base URL to modify.\n *\n * @returns 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 intervalRef - A Vue ref holding a timer handle 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 timeoutRef - A Vue ref holding a timer handle 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 * Registers hooks that save and restore a container's scroll position across kept-alive route changes.\n *\n * @remarks\n * Call within Vue component setup with Vue Router and `KeepAlive`.\n * Route leave saves the current offsets, and each activation restores them to the currently referenced element.\n * A missing element saves zero offsets and skips restoration. Without `KeepAlive`, unmounting discards the state.\n * The hooks follow the component lifecycle; there is no separate cleanup handle.\n *\n * @typeParam T - The scrollable element type.\n *\n * @param containerRef - The reference to the scrollable element, or `null` while it is unavailable.\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;;;;;;;;;;;;;;AAeA,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 CHANGED
@@ -2,22 +2,25 @@
2
2
  /**
3
3
  * Appends the current browser URL (including path, query, and hash) as the `redirect` query parameter to the given URL.
4
4
  *
5
- * @param {string} url - The base URL to modify
5
+ * @param url - The base URL to modify.
6
6
  *
7
- * @returns {string} A new URL with the current location as the `redirect` parameter
7
+ * @returns A new URL with the current location as the `redirect` parameter.
8
8
  */
9
- declare function appendRedirectParamFromCurrentLocationToUrl(url: string): string;
9
+ export declare function appendRedirectParamFromCurrentLocationToUrl(url: string): string;
10
10
  /**
11
- * Navigates to the given URL, appending the current browser location
12
- * (path, query, and hash) as the `redirect` query parameter.
11
+ * Navigates to a URL with the current browser path, query, and hash as its redirect parameter.
13
12
  *
14
- * Useful for redirecting to login or other gateways while preserving
15
- * the current location for post-auth navigation.
13
+ * @remarks
14
+ * Omitting `delayMs` navigates immediately. Providing a delay, including `0`, schedules navigation;
15
+ * the current location is read when the timer fires, not when the timer is created.
16
+ * Requires a browser environment. Redirect-path validation errors propagate from the URL helper.
16
17
  *
17
- * @param {string} url - The destination URL to navigate to
18
- * @param {number} [delayMs] - Optional delay in milliseconds before navigation
18
+ * @param url - The destination URL.
19
+ * @param delayMs - The navigation delay in milliseconds, using native `setTimeout` timing rules.
20
+ *
21
+ * @returns A timer handle when delayed, which the caller can cancel with `clearTimeout`, or `undefined`
22
+ * when navigation is immediate.
19
23
  */
20
- declare function assignUrlWithRedirectParamFromCurrentLocation(url: string, delayMs?: number): NodeJS.Timeout | undefined;
24
+ export declare function assignUrlWithRedirectParamFromCurrentLocation(url: string, delayMs?: number): NodeJS.Timeout | undefined;
21
25
  //#endregion
22
- export { appendRedirectParamFromCurrentLocationToUrl, assignUrlWithRedirectParamFromCurrentLocation };
23
26
  //# sourceMappingURL=web.d.ts.map
package/dist/web.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"web.d.ts","names":[],"sources":["../src/web.ts"],"mappings":";;;;;;;;iBASgB,4CAA4C;;;;;;;;;;;iBAe5C,8CAA8C,aAAa,mBAAgB,OAAA"}
1
+ {"version":3,"file":"web.d.ts","names":[],"sources":["../src/web.ts"],"mappings":";;;;;;;;wBASgB,4CAA4C;;;;;;;;;;;;;;;wBAmB5C,8CAA8C,aAAa,mBAAgB,OAAA"}
package/dist/web.js CHANGED
@@ -3,23 +3,27 @@ import { appendRedirectParamToUrl } from "./url.js";
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
  function appendRedirectParamFromCurrentLocationToUrl(url) {
11
11
  const currentPath = `${window.location.pathname}${window.location.search}${window.location.hash}`;
12
12
  return appendRedirectParamToUrl(url, currentPath);
13
13
  }
14
14
  /**
15
- * Navigates to the given URL, appending the current browser location
16
- * (path, query, and hash) as the `redirect` query parameter.
15
+ * Navigates to a URL with the current browser path, query, and hash as its redirect parameter.
17
16
  *
18
- * Useful for redirecting to login or other gateways while preserving
19
- * the current location for post-auth navigation.
17
+ * @remarks
18
+ * Omitting `delayMs` navigates immediately. Providing a delay, including `0`, schedules navigation;
19
+ * the current location is read when the timer fires, not when the timer is created.
20
+ * Requires a browser environment. Redirect-path validation errors propagate from the URL helper.
20
21
  *
21
- * @param {string} url - The destination URL to navigate to
22
- * @param {number} [delayMs] - Optional delay in milliseconds before navigation
22
+ * @param url - The destination URL.
23
+ * @param delayMs - The navigation delay in milliseconds, using native `setTimeout` timing rules.
24
+ *
25
+ * @returns A timer handle when delayed, which the caller can cancel with `clearTimeout`, or `undefined`
26
+ * when navigation is immediate.
23
27
  */
24
28
  function assignUrlWithRedirectParamFromCurrentLocation(url, delayMs) {
25
29
  if (delayMs === void 0) window.location.assign(appendRedirectParamFromCurrentLocationToUrl(url));
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;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"}
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 url - The base URL to modify.\n *\n * @returns 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 a URL with the current browser path, query, and hash as its redirect parameter.\n *\n * @remarks\n * Omitting `delayMs` navigates immediately. Providing a delay, including `0`, schedules navigation;\n * the current location is read when the timer fires, not when the timer is created.\n * Requires a browser environment. Redirect-path validation errors propagate from the URL helper.\n *\n * @param url - The destination URL.\n * @param delayMs - The navigation delay in milliseconds, using native `setTimeout` timing rules.\n *\n * @returns A timer handle when delayed, which the caller can cancel with `clearTimeout`, or `undefined`\n * when navigation is immediate.\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;;;;;;;;;;;;;;;AAgBA,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": "18.0.0",
4
+ "version": "18.1.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",
@@ -62,7 +62,7 @@
62
62
  "lint:fix": "eslint --fix --max-warnings 0",
63
63
  "prepack": "pnpm run build",
64
64
  "release": "pnpm run lint && pnpm run typecheck && pnpm run test && pnpm run build && changelogen --hideAuthorEmail --push --release && npm publish",
65
- "test": "cross-env TZ=UTC vitest run --coverage",
65
+ "test": "cross-env TZ=UTC vitest run --coverage && cross-env TZ='America/New_York' vitest run tests/classes/enhanced-date.test.ts",
66
66
  "test:watch": "cross-env TZ=UTC vitest watch --coverage",
67
67
  "typecheck": "tsc -b --noEmit"
68
68
  },
@@ -135,36 +135,36 @@
135
135
  }
136
136
  },
137
137
  "devDependencies": {
138
- "@antfu/eslint-config": "^9.3.0",
139
- "@kikiutils/eslint-config": "^9.2.0",
138
+ "@antfu/eslint-config": "^9.5.1",
139
+ "@kikiutils/eslint-config": "^9.2.1",
140
140
  "@kikiutils/tsconfigs": "^7.0.0",
141
- "@noble/hashes": "^2.3.0",
142
- "@types/node": "^26.2.0",
143
- "@types/ssh2": "^1.15.5",
144
- "@vitest/coverage-v8": "^4.1.10",
141
+ "@noble/hashes": "^2.4.0",
142
+ "@types/node": "^26.6.3",
143
+ "@types/ssh2": "^1.15.6",
144
+ "@vitest/coverage-v8": "^5.0.3",
145
145
  "async-validator": "^4.2.5",
146
- "bson": "^7.3.2",
146
+ "bson": "^7.3.3",
147
147
  "changelogen": "^0.6.2",
148
148
  "consola": "^3.4.2",
149
149
  "cross-env": "^10.1.0",
150
150
  "date-fns": "^4.4.0",
151
151
  "decimal.js": "^10.6.0",
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",
152
+ "element-plus": "^2.14.7",
153
+ "eslint": "^10.11.0",
154
+ "jsdom": "^30.1.1",
155
+ "knip": "^6.39.0",
156
+ "lru-cache": "^11.5.3",
157
157
  "millify": "^6.1.0",
158
- "msgpackr": "^2.0.5",
158
+ "msgpackr": "^2.1.0",
159
159
  "node-ssh": "^13.2.1",
160
160
  "pino": "^10.3.1",
161
161
  "pino-pretty": "^13.1.3",
162
- "publint": "^0.3.23",
163
- "tsdown": "^0.22.14",
162
+ "publint": "^0.3.25",
163
+ "tsdown": "^0.23.0",
164
164
  "typescript": "^6.0.3",
165
165
  "unplugin-unused": "^0.6.0",
166
- "vitest": "^4.1.10",
167
- "vue": "^3.5.41",
168
- "vue-router": "^5.2.0"
166
+ "vitest": "^5.0.3",
167
+ "vue": "^3.5.43",
168
+ "vue-router": "^5.3.1"
169
169
  }
170
170
  }
package/src/buffer.ts CHANGED
@@ -3,33 +3,32 @@ import { Buffer } from 'node:buffer';
3
3
  import type { BinaryInput } from './types';
4
4
 
5
5
  /**
6
- * Converts various binary data types to a Node.js Buffer.
6
+ * Converts binary input to a Node.js `Buffer`.
7
7
  *
8
- * This function provides a unified, efficient way to convert different binary formats
9
- * (Blob, Buffer, File, ArrayBuffer, or Uint8Array) into a Node.js Buffer.
10
- * It prioritizes zero-copy conversions for TypedArrays and ArrayBuffers to ensure
11
- * optimal performance.
8
+ * @remarks
9
+ * An existing `Buffer` is returned unchanged. `ArrayBuffer` and `Uint8Array` inputs share their backing memory
10
+ * with the result, so changes are visible through both views. `Blob` and `File` inputs are read asynchronously.
12
11
  *
13
- * @param {ArrayBuffer | Blob | Buffer | File | Uint8Array} input - The binary data input to convert.
14
- * Supports Blob, Buffer, File, ArrayBuffer, and Uint8Array.
12
+ * @param input - The binary data to convert.
15
13
  *
16
- * @returns {Promise<Buffer>} A promise that resolves to a Node.js Buffer.
14
+ * @returns A promise resolving to the original buffer or a new buffer view after the input is available.
15
+ *
16
+ * @throws TypeError through promise rejection if the input is unsupported.
17
17
  *
18
18
  * @example
19
- * ```typescript
20
- * import { toBuffer } from '@kikiutils/shared/buffer';
21
19
  *
22
- * // From ArrayBuffer
23
- * const ab = new ArrayBuffer(8);
24
- * const bufferFromAB = await toBuffer(ab);
20
+ * ```ts
21
+ * import { toBuffer } from '@kikiutils/shared/buffer';
25
22
  *
26
- * // From Uint8Array (Zero-copy)
27
- * const u8 = new Uint8Array([10, 20, 30]);
28
- * const bufferFromU8 = await toBuffer(u8);
23
+ * const bytes = new Uint8Array([
24
+ * 10,
25
+ * 20,
26
+ * 30,
27
+ * ]);
29
28
  *
30
- * // From Blob or File
31
- * const blob = new Blob(['data'], { type: 'text/plain' });
32
- * const bufferFromBlob = await toBuffer(blob);
29
+ * const buffer = await toBuffer(bytes);
30
+ * bytes[0] = 40;
31
+ * console.log(buffer[0]); // => 40
33
32
  * ```
34
33
  */
35
34
  export async function toBuffer(input: BinaryInput) {