@kikiutils/shared 10.3.0 → 10.4.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 (120) hide show
  1. package/dist/buffer.cjs +43 -0
  2. package/dist/buffer.cjs.map +1 -0
  3. package/dist/buffer.d.ts +34 -0
  4. package/dist/buffer.d.ts.map +1 -0
  5. package/dist/buffer.mjs +41 -0
  6. package/dist/buffer.mjs.map +1 -0
  7. package/dist/clipboard.cjs +4 -4
  8. package/dist/clipboard.cjs.map +1 -1
  9. package/dist/clipboard.d.ts +3 -3
  10. package/dist/clipboard.mjs +4 -4
  11. package/dist/clipboard.mjs.map +1 -1
  12. package/dist/datetime.cjs +13 -13
  13. package/dist/datetime.cjs.map +1 -1
  14. package/dist/datetime.d.ts +12 -12
  15. package/dist/datetime.mjs +13 -13
  16. package/dist/datetime.mjs.map +1 -1
  17. package/dist/element-plus.cjs +6 -6
  18. package/dist/element-plus.cjs.map +1 -1
  19. package/dist/element-plus.d.ts +6 -6
  20. package/dist/element-plus.mjs +6 -6
  21. package/dist/element-plus.mjs.map +1 -1
  22. package/dist/enum.cjs +12 -12
  23. package/dist/enum.cjs.map +1 -1
  24. package/dist/enum.d.ts +12 -12
  25. package/dist/enum.mjs +12 -12
  26. package/dist/enum.mjs.map +1 -1
  27. package/dist/env.cjs +4 -4
  28. package/dist/env.cjs.map +1 -1
  29. package/dist/env.d.ts +4 -4
  30. package/dist/env.mjs +4 -4
  31. package/dist/env.mjs.map +1 -1
  32. package/dist/general.cjs.map +1 -1
  33. package/dist/general.d.ts +5 -5
  34. package/dist/general.mjs.map +1 -1
  35. package/dist/math.cjs +4 -4
  36. package/dist/math.cjs.map +1 -1
  37. package/dist/math.d.ts +4 -4
  38. package/dist/math.mjs +4 -4
  39. package/dist/math.mjs.map +1 -1
  40. package/dist/number.cjs +3 -3
  41. package/dist/number.cjs.map +1 -1
  42. package/dist/number.d.ts +3 -3
  43. package/dist/number.mjs +3 -3
  44. package/dist/number.mjs.map +1 -1
  45. package/dist/object.cjs +4 -4
  46. package/dist/object.cjs.map +1 -1
  47. package/dist/object.d.ts +4 -4
  48. package/dist/object.mjs +4 -4
  49. package/dist/object.mjs.map +1 -1
  50. package/dist/random.cjs +7 -7
  51. package/dist/random.cjs.map +1 -1
  52. package/dist/random.d.ts +7 -7
  53. package/dist/random.mjs +7 -7
  54. package/dist/random.mjs.map +1 -1
  55. package/dist/storage/enhanced/local/core.cjs +11 -11
  56. package/dist/storage/enhanced/local/core.cjs.map +1 -1
  57. package/dist/storage/enhanced/local/core.d.ts +9 -9
  58. package/dist/storage/enhanced/local/core.mjs +11 -11
  59. package/dist/storage/enhanced/local/core.mjs.map +1 -1
  60. package/dist/storage/enhanced/local/keyed-store.cjs +3 -3
  61. package/dist/storage/enhanced/local/keyed-store.cjs.map +1 -1
  62. package/dist/storage/enhanced/local/keyed-store.d.ts +3 -3
  63. package/dist/storage/enhanced/local/keyed-store.mjs +3 -3
  64. package/dist/storage/enhanced/local/keyed-store.mjs.map +1 -1
  65. package/dist/storage/enhanced/redis/core.cjs +18 -18
  66. package/dist/storage/enhanced/redis/core.cjs.map +1 -1
  67. package/dist/storage/enhanced/redis/core.d.ts +16 -16
  68. package/dist/storage/enhanced/redis/core.mjs +18 -18
  69. package/dist/storage/enhanced/redis/core.mjs.map +1 -1
  70. package/dist/storage/enhanced/redis/keyed-store.cjs +4 -4
  71. package/dist/storage/enhanced/redis/keyed-store.cjs.map +1 -1
  72. package/dist/storage/enhanced/redis/keyed-store.d.ts +4 -4
  73. package/dist/storage/enhanced/redis/keyed-store.mjs +4 -4
  74. package/dist/storage/enhanced/redis/keyed-store.mjs.map +1 -1
  75. package/dist/storage/lru/keyed-store.cjs +3 -3
  76. package/dist/storage/lru/keyed-store.cjs.map +1 -1
  77. package/dist/storage/lru/keyed-store.d.ts +3 -3
  78. package/dist/storage/lru/keyed-store.mjs +3 -3
  79. package/dist/storage/lru/keyed-store.mjs.map +1 -1
  80. package/dist/string.cjs +5 -5
  81. package/dist/string.cjs.map +1 -1
  82. package/dist/string.d.ts +4 -4
  83. package/dist/string.mjs +5 -5
  84. package/dist/string.mjs.map +1 -1
  85. package/dist/url.cjs +3 -3
  86. package/dist/url.cjs.map +1 -1
  87. package/dist/url.d.ts +3 -3
  88. package/dist/url.mjs +3 -3
  89. package/dist/url.mjs.map +1 -1
  90. package/dist/vue.cjs +6 -6
  91. package/dist/vue.cjs.map +1 -1
  92. package/dist/vue.d.ts +6 -6
  93. package/dist/vue.mjs +6 -6
  94. package/dist/vue.mjs.map +1 -1
  95. package/dist/web.cjs +4 -4
  96. package/dist/web.cjs.map +1 -1
  97. package/dist/web.d.ts +4 -4
  98. package/dist/web.mjs +4 -4
  99. package/dist/web.mjs.map +1 -1
  100. package/package.json +1 -1
  101. package/src/buffer.ts +37 -0
  102. package/src/clipboard.ts +4 -4
  103. package/src/datetime.ts +13 -13
  104. package/src/element-plus.ts +6 -6
  105. package/src/enum.ts +12 -12
  106. package/src/env.ts +4 -4
  107. package/src/general.ts +5 -5
  108. package/src/math.ts +4 -4
  109. package/src/number.ts +3 -3
  110. package/src/object.ts +4 -4
  111. package/src/random.ts +7 -7
  112. package/src/storage/enhanced/local/core.ts +11 -11
  113. package/src/storage/enhanced/local/keyed-store.ts +3 -3
  114. package/src/storage/enhanced/redis/core.ts +18 -18
  115. package/src/storage/enhanced/redis/keyed-store.ts +4 -4
  116. package/src/storage/lru/keyed-store.ts +3 -3
  117. package/src/string.ts +5 -5
  118. package/src/url.ts +3 -3
  119. package/src/vue.ts +6 -6
  120. package/src/web.ts +4 -4
@@ -34,11 +34,11 @@ export const enhancedLocalStorage = Object.freeze({
34
34
  /**
35
35
  * Retrieves a value by key and decodes it using SuperJSON or raw string.
36
36
  *
37
- * @template T - The expected type of the value.
37
+ * @template T - The expected type of the value
38
38
  *
39
- * @param {string} key - The key of the value to retrieve.
39
+ * @param {string} key - The key of the value to retrieve
40
40
  *
41
- * @returns {null | T} The decoded value or null if not found.
41
+ * @returns {null | T} The decoded value or null if not found
42
42
  */
43
43
  getItem<T = unknown>(key: string) {
44
44
  const rawValue = window.localStorage.getItem(key);
@@ -47,15 +47,15 @@ export const enhancedLocalStorage = Object.freeze({
47
47
  /**
48
48
  * Checks whether a key exists in localStorage.
49
49
  *
50
- * @param {string} key - The key to check.
50
+ * @param {string} key - The key to check
51
51
  *
52
- * @returns {boolean} True if the key exists, false otherwise.
52
+ * @returns {boolean} True if the key exists, false otherwise
53
53
  */
54
54
  hasItem: (key: string) => window.localStorage.getItem(key) !== null,
55
55
  /**
56
56
  * Returns the number of items stored in localStorage.
57
57
  *
58
- * @returns {number} The number of items stored in localStorage.
58
+ * @returns {number} The number of items stored in localStorage
59
59
  */
60
60
  get length() {
61
61
  return window.localStorage.length;
@@ -63,14 +63,14 @@ export const enhancedLocalStorage = Object.freeze({
63
63
  /**
64
64
  * Removes a specific key from localStorage.
65
65
  *
66
- * @param {string} key - The key to remove.
66
+ * @param {string} key - The key to remove
67
67
  */
68
68
  removeItem: (key: string) => window.localStorage.removeItem(key),
69
69
  /**
70
70
  * Stores a value in localStorage with automatic serialization.
71
71
  *
72
- * @param {string} key - The key to store the value under.
73
- * @param {any} value - The value to store.
72
+ * @param {string} key - The key to store the value under
73
+ * @param {any} value - The value to store
74
74
  */
75
75
  setItem: (key: string, value: any) => window.localStorage.setItem(key, encodeToStorageValue(value)),
76
76
  });
@@ -84,11 +84,11 @@ function decodeStorageValue(data: string) {
84
84
  try {
85
85
  return deserialize(JSON.parse(payload));
86
86
  } catch {
87
- throw new Error('[EnhancedLocalStorage] Failed to parse JSON payload.');
87
+ throw new Error('[EnhancedLocalStorage] Failed to parse JSON payload');
88
88
  }
89
89
  case StorageValueEncodingType.String: return payload;
90
90
  default:
91
- throw new Error(`[EnhancedLocalStorage] Unknown encoding type: ${type}.`);
91
+ throw new Error(`[EnhancedLocalStorage] Unknown encoding type: ${type}`);
92
92
  }
93
93
  }
94
94
 
@@ -7,9 +7,9 @@ import { enhancedLocalStorage } from './core';
7
7
  * This utility allows you to abstract away key construction logic and work directly
8
8
  * with scoped key-value operations like `getItem`, `setItem`, and `removeItem`.
9
9
  *
10
- * @template D - The value type to store.
10
+ * @template D - The value type to store
11
11
  *
12
- * @returns A factory that accepts a key generator function and returns a scoped storage interface.
12
+ * @returns A factory that accepts a key generator function and returns a scoped storage interface
13
13
  *
14
14
  * @example
15
15
  * ```typescript
@@ -28,7 +28,7 @@ export function createKeyedEnhancedLocalStore<D = unknown>() {
28
28
  /**
29
29
  * Resolves the storage key from the given arguments.
30
30
  *
31
- * @returns {string} The final string key used internally.
31
+ * @returns {string} The final string key used internally
32
32
  */
33
33
  resolveKey: (...args: P) => getKeyFunction(...args),
34
34
  setItem: (value: D, ...args: P) => enhancedLocalStorage.setItem(getKeyFunction(...args), value),
@@ -26,9 +26,9 @@ const customValueHeaderLength = customValueHeader.byteLength + 1;
26
26
  * This utility provides a typed, serializable key-value store backed by Redis,
27
27
  * supporting TTL operations and safe deserialization of complex types (e.g. Date, Map).
28
28
  *
29
- * @param {Redis | string} ioRedisInstanceOrUrl - Either an existing `ioredis` instance or a Redis connection string.
29
+ * @param {Redis | string} ioRedisInstanceOrUrl - Either an existing `ioredis` instance or a Redis connection string
30
30
  *
31
- * @returns A frozen object that wraps Redis commands with typed get/set logic and encoding.
31
+ * @returns A frozen object that wraps Redis commands with typed get/set logic and encoding
32
32
  *
33
33
  * @example
34
34
  * ```typescript
@@ -45,11 +45,11 @@ export function createEnhancedRedisStorage(ioRedisInstanceOrUrl: Redis | string)
45
45
  /**
46
46
  * Retrieves a value from Redis and decodes it.
47
47
  *
48
- * @template T - The expected return type.
48
+ * @template T - The expected return type
49
49
  *
50
- * @param {string} key - The Redis key.
50
+ * @param {string} key - The Redis key
51
51
  *
52
- * @returns {Promise<null | T>} The decoded value or null if not found.
52
+ * @returns {Promise<null | T>} The decoded value or null if not found
53
53
  */
54
54
  async getItem<T = unknown>(key: string) {
55
55
  const rawValue = await instance.getBuffer(key);
@@ -58,24 +58,24 @@ export function createEnhancedRedisStorage(ioRedisInstanceOrUrl: Redis | string)
58
58
  /**
59
59
  * Gets the remaining TTL (in seconds) for a given key.
60
60
  *
61
- * @param {string} key - The Redis key.
61
+ * @param {string} key - The Redis key
62
62
  *
63
- * @returns {Promise<number>} The number of seconds until the key expires, or -1 if no expiration is set.
63
+ * @returns {Promise<number>} The number of seconds until the key expires, or -1 if no expiration is set
64
64
  */
65
65
  getItemTtl: (key: string) => instance.ttl(key),
66
66
  /**
67
67
  * Checks whether a key exists in Redis.
68
68
  *
69
- * @param {string} key - The Redis key.
69
+ * @param {string} key - The Redis key
70
70
  *
71
- * @returns {Promise<boolean>} True if the key exists, false otherwise.
71
+ * @returns {Promise<boolean>} True if the key exists, false otherwise
72
72
  */
73
73
  hasItem: async (key: string) => await instance.exists(key) === 1,
74
74
  /**
75
75
  * The underlying Redis instance, exposed for advanced operations.
76
76
  * Use with caution; most use cases should rely on the wrapper methods.
77
77
  *
78
- * @returns {Redis} The underlying Redis instance.
78
+ * @returns {Redis} The underlying Redis instance
79
79
  */
80
80
  get instance() {
81
81
  return instance;
@@ -83,7 +83,7 @@ export function createEnhancedRedisStorage(ioRedisInstanceOrUrl: Redis | string)
83
83
  /**
84
84
  * Removes a key from Redis.
85
85
  *
86
- * @param {string} key - The Redis key to delete.
86
+ * @param {string} key - The Redis key to delete
87
87
  *
88
88
  * @returns {Promise<boolean>} A Promise that resolves to `true` if the key was removed,
89
89
  * or `false` if it did not exist.
@@ -92,16 +92,16 @@ export function createEnhancedRedisStorage(ioRedisInstanceOrUrl: Redis | string)
92
92
  /**
93
93
  * Stores a value in Redis without expiration.
94
94
  *
95
- * @param {string} key - The Redis key.
96
- * @param {any} value - The value to store. Will be serialized.
95
+ * @param {string} key - The Redis key
96
+ * @param {any} value - The value to store. Will be serialized
97
97
  */
98
98
  setItem: (key: string, value: any) => instance.set(key, encodeToStorageValue(value)),
99
99
  /**
100
100
  * Stores a value in Redis with a time-to-live (TTL).
101
101
  *
102
- * @param {string} key - The Redis key.
103
- * @param {number} seconds - Expiration time in seconds.
104
- * @param {any} value - The value to store. Will be serialized.
102
+ * @param {string} key - The Redis key
103
+ * @param {number} seconds - Expiration time in seconds
104
+ * @param {any} value - The value to store. Will be serialized
105
105
  */
106
106
  setItemWithTtl(key: string, seconds: number, value: any) {
107
107
  return instance.setex(key, seconds, encodeToStorageValue(value));
@@ -119,11 +119,11 @@ function decodeStorageValue(data: Buffer) {
119
119
  try {
120
120
  return deserialize(JSON.parse(payload.toString()));
121
121
  } catch {
122
- throw new Error('[RedisStorage] Failed to parse JSON payload.');
122
+ throw new Error('[RedisStorage] Failed to parse JSON payload');
123
123
  }
124
124
  case StorageValueEncodingType.String: return payload.toString();
125
125
  default:
126
- throw new Error(`[RedisStorage] Unknown encoding type: ${type}.`);
126
+ throw new Error(`[RedisStorage] Unknown encoding type: ${type}`);
127
127
  }
128
128
  }
129
129
 
@@ -8,11 +8,11 @@ import type { createEnhancedRedisStorage } from './core';
8
8
  * to Redis operations such as `getItem`, `setItem`, `setItemWithTtl`, and `getItemTtl`.
9
9
  * It is ideal for namespaced data, caching, and session handling.
10
10
  *
11
- * @template D - The value type to store.
11
+ * @template D - The value type to store
12
12
  *
13
- * @param {ReturnType<typeof createEnhancedRedisStorage>} storage - The enhanced Redis storage instance.
13
+ * @param {ReturnType<typeof createEnhancedRedisStorage>} storage - The enhanced Redis storage instance
14
14
  *
15
- * @returns A factory that accepts a key generator function and returns a scoped Redis storage interface.
15
+ * @returns A factory that accepts a key generator function and returns a scoped Redis storage interface
16
16
  *
17
17
  * @example
18
18
  * ```typescript
@@ -32,7 +32,7 @@ export function createKeyedEnhancedRedisStore<D = unknown>(storage: ReturnType<t
32
32
  /**
33
33
  * Resolves the storage key from the given arguments.
34
34
  *
35
- * @returns {string} The final string key used internally.
35
+ * @returns {string} The final string key used internally
36
36
  */
37
37
  resolveKey: (...args: P) => getKeyFunction(...args),
38
38
  setItem: (value: D, ...args: P) => storage.setItem(getKeyFunction(...args), value),
@@ -5,11 +5,11 @@ import type { LRUCache } from 'lru-cache';
5
5
  *
6
6
  * This utility allows structured access to cache entries using a dynamic key-generation function.
7
7
  *
8
- * @template D - The specific value type exposed by this store (must extend `V`).
8
+ * @template D - The specific value type exposed by this store (must extend `V`)
9
9
  *
10
- * @param {LRUCache<any, any, any>} lruInstance - An instance of `lru-cache`.
10
+ * @param {LRUCache<any, any, any>} lruInstance - An instance of `lru-cache`
11
11
  *
12
- * @returns A factory that accepts a key generator and returns a scoped, type-safe LRU-based store.
12
+ * @returns A factory that accepts a key generator and returns a scoped, type-safe LRU-based store
13
13
  *
14
14
  * @example
15
15
  * ```typescript
package/src/string.ts CHANGED
@@ -23,12 +23,12 @@ const CHARSETS: Record<RandomStringMode, string> = {
23
23
  /**
24
24
  * Generates a random string of a given length using a specified character set.
25
25
  *
26
- * @param {number} length - The length of the string to generate. Must be a positive integer.
27
- * @param {RandomStringMode} [mode] - The character set to use.
26
+ * @param {number} length - The length of the string to generate. Must be a positive integer
27
+ * @param {RandomStringMode} [mode] - The character set to use
28
28
  *
29
- * @returns {string} The generated random string.
29
+ * @returns {string} The generated random string
30
30
  *
31
- * @throws {Error} If the length is not a positive integer or the mode is unsupported.
31
+ * @throws {Error} If the length is not a positive integer or the mode is unsupported
32
32
  *
33
33
  * @example
34
34
  * ```typescript
@@ -41,7 +41,7 @@ const CHARSETS: Record<RandomStringMode, string> = {
41
41
  */
42
42
  export function randomString(length: number, mode: RandomStringMode = 'alphabetic') {
43
43
  if (!Number.isInteger(length) || length <= 0) {
44
- throw new Error(`Invalid length: ${length}. Must be a positive integer.`);
44
+ throw new Error(`Invalid length: ${length}. Must be a positive integer`);
45
45
  }
46
46
 
47
47
  const charset = CHARSETS[mode];
package/src/url.ts CHANGED
@@ -3,10 +3,10 @@
3
3
  *
4
4
  * Typically used to preserve the user's current path for post-login navigation.
5
5
  *
6
- * @param {string} url - The target URL to modify.
7
- * @param {string} redirectPath - The path to use as the redirect destination.
6
+ * @param {string} url - The target URL to modify
7
+ * @param {string} redirectPath - The path to use as the redirect destination
8
8
  *
9
- * @returns {string} A new URL string with the `redirect` query parameter.
9
+ * @returns {string} A new URL string with the `redirect` query parameter
10
10
  */
11
11
  export function appendRedirectParamToUrl(url: string, redirectPath: string) {
12
12
  const [base, rawQuery = ''] = url.split('?');
package/src/vue.ts CHANGED
@@ -10,9 +10,9 @@ import { appendRedirectParamToUrl } from './url';
10
10
  /**
11
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 {string} 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 {string} 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);
@@ -21,7 +21,7 @@ export function appendRedirectParamFromCurrentRouteToUrl(url: string) {
21
21
  /**
22
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 {Ref<null | ReturnType<typeof setInterval>>} intervalRef - A Vue ref holding a NodeJS.Timeout or null
25
25
  */
26
26
  export function clearIntervalRef(intervalRef: Ref<null | ReturnType<typeof setInterval>>) {
27
27
  if (intervalRef.value) clearInterval(intervalRef.value);
@@ -31,7 +31,7 @@ export function clearIntervalRef(intervalRef: Ref<null | ReturnType<typeof setIn
31
31
  /**
32
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 {Ref<null | ReturnType<typeof setTimeout>>} timeoutRef - A Vue ref holding a NodeJS.Timeout or null
35
35
  */
36
36
  export function clearTimeoutRef(timeoutRef: Ref<null | ReturnType<typeof setTimeout>>) {
37
37
  if (timeoutRef.value) clearTimeout(timeoutRef.value);
@@ -42,9 +42,9 @@ export function clearTimeoutRef(timeoutRef: Ref<null | ReturnType<typeof setTime
42
42
  * A Vue composition function that remembers and restores scroll position
43
43
  * of a scrollable container across route changes and keep-alive activation.
44
44
  *
45
- * @template T - The type of the scrollable element (defaults to HTMLElement).
45
+ * @template T - The type of the scrollable element (defaults to HTMLElement)
46
46
  *
47
- * @param {Ref<null | T>} containerRef - A ref to the scrollable HTML element.
47
+ * @param {Ref<null | T>} containerRef - A ref to the scrollable HTML element
48
48
  */
49
49
  export function usePreserveScroll<T extends Element = HTMLElement>(containerRef: Ref<null | T>) {
50
50
  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 {string} url - The base URL to modify
7
7
  *
8
- * @returns {string} A new URL with the current location as the `redirect` parameter.
8
+ * @returns {string} 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}`;
@@ -19,8 +19,8 @@ export function appendRedirectParamFromCurrentLocationToUrl(url: string) {
19
19
  * Useful for redirecting to login or other gateways while preserving
20
20
  * the current location for post-auth navigation.
21
21
  *
22
- * @param {string} url - The destination URL to navigate to.
23
- * @param {number} [delayMs] - Optional delay in milliseconds before navigation.
22
+ * @param {string} url - The destination URL to navigate to
23
+ * @param {number} [delayMs] - Optional delay in milliseconds before navigation
24
24
  */
25
25
  export function assignUrlWithRedirectParamFromCurrentLocation(url: string, delayMs?: number) {
26
26
  if (delayMs === undefined) window.location.assign(appendRedirectParamFromCurrentLocationToUrl(url));