@kikiutils/shared 15.0.3 → 15.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 (55) hide show
  1. package/README.md +137 -67
  2. package/dist/buffer.js.map +1 -1
  3. package/dist/classes/path.d.ts +8 -0
  4. package/dist/classes/path.d.ts.map +1 -1
  5. package/dist/classes/path.js +5 -0
  6. package/dist/classes/path.js.map +1 -1
  7. package/dist/classes/precision-number.d.ts +215 -11
  8. package/dist/classes/precision-number.d.ts.map +1 -1
  9. package/dist/classes/precision-number.js +268 -25
  10. package/dist/classes/precision-number.js.map +1 -1
  11. package/dist/classes/ssh-client.js.map +1 -1
  12. package/dist/clipboard.js.map +1 -1
  13. package/dist/consola.js.map +1 -1
  14. package/dist/crypto-hash.d.ts +7 -7
  15. package/dist/crypto-hash.js +7 -7
  16. package/dist/crypto-hash.js.map +1 -1
  17. package/dist/datetime.js.map +1 -1
  18. package/dist/element-plus.js.map +1 -1
  19. package/dist/enum.js.map +1 -1
  20. package/dist/env.js.map +1 -1
  21. package/dist/event-awaiter.js.map +1 -1
  22. package/dist/general.js.map +1 -1
  23. package/dist/hash.d.ts +3 -3
  24. package/dist/hash.js +3 -3
  25. package/dist/hash.js.map +1 -1
  26. package/dist/math.js.map +1 -1
  27. package/dist/number.js.map +1 -1
  28. package/dist/object.js.map +1 -1
  29. package/dist/random.js.map +1 -1
  30. package/dist/storages/lru/keyed-store.d.ts +3 -3
  31. package/dist/storages/lru/keyed-store.js +3 -3
  32. package/dist/storages/lru/keyed-store.js.map +1 -1
  33. package/dist/storages/redis/keyed-store.d.ts +1 -1
  34. package/dist/storages/redis/keyed-store.js +1 -1
  35. package/dist/storages/redis/keyed-store.js.map +1 -1
  36. package/dist/storages/redis/msgpack.js.map +1 -1
  37. package/dist/string.d.ts +12 -6
  38. package/dist/string.d.ts.map +1 -1
  39. package/dist/string.js +9 -6
  40. package/dist/string.js.map +1 -1
  41. package/dist/time.js.map +1 -1
  42. package/dist/types/index.d.ts +30 -0
  43. package/dist/types/index.d.ts.map +1 -1
  44. package/dist/url.js.map +1 -1
  45. package/dist/vue.js.map +1 -1
  46. package/dist/web.js.map +1 -1
  47. package/package.json +8 -17
  48. package/src/classes/path.ts +9 -0
  49. package/src/classes/precision-number.ts +300 -25
  50. package/src/crypto-hash.ts +7 -7
  51. package/src/hash.ts +3 -3
  52. package/src/storages/lru/keyed-store.ts +3 -3
  53. package/src/storages/redis/keyed-store.ts +1 -1
  54. package/src/string.ts +12 -6
  55. package/src/types/index.ts +39 -0
@@ -9,7 +9,7 @@ import type { LRUCache } from 'lru-cache';
9
9
  *
10
10
  * @returns {(keyFn: (...args: P) => string) => Readonly<{
11
11
  * getItem, getItemTtl, hasItem, removeItem, resolveKey, setItem
12
- * }>} A keyed store factory that takes a key resolution function
12
+ * }>} A factory that accepts a key resolver and returns a frozen keyed cache facade
13
13
  *
14
14
  * @example
15
15
  * ```typescript
@@ -18,8 +18,8 @@ import type { LRUCache } from 'lru-cache';
18
18
  *
19
19
  * const lru = new LRUCache({ max: 100 });
20
20
  * const keyedStore = createLruKeyedStore(lru)((userId: string) => `user:${userId}`);
21
- * await keyedStore.setItem({ name: 'Alice' }, 'user-123');
22
- * const user = await keyedStore.getItem('user-123'); // { name: 'Alice' }
21
+ * keyedStore.setItem({ name: 'Alice' }, 'user-123');
22
+ * const user = keyedStore.getItem('user-123'); // { name: 'Alice' }
23
23
  * ```
24
24
  */
25
25
  export function createLruKeyedStore<D = unknown>(lruInstance: LRUCache<any, any, any>) {
@@ -11,7 +11,7 @@ import type { RedisLikeStorage } from './types';
11
11
  *
12
12
  * @returns {(keyFn: (...args: P) => string) => Readonly<{
13
13
  * getItem, getItemTtl, hasItem, removeItem, resolveKey, setItem, setItemWithTtl
14
- * }>} A keyed store factory that takes a key resolution function
14
+ * }>} A factory that accepts a key resolver and returns a frozen Redis keyed-store facade
15
15
  *
16
16
  * @example
17
17
  * ```typescript
package/src/string.ts CHANGED
@@ -1,3 +1,6 @@
1
+ /**
2
+ * Character-set presets supported by `randomString`.
3
+ */
1
4
  export type RandomStringMode =
2
5
  | 'alphabetic'
3
6
  | 'alphanumeric'
@@ -21,10 +24,13 @@ const CHARSETS: Record<RandomStringMode, string> = {
21
24
  };
22
25
 
23
26
  /**
24
- * Generates a random string of a given length using a specified character set.
27
+ * Generates a random string of a given length using a predefined character set.
28
+ *
29
+ * Uses `Math.random`, so this helper is suitable for display tokens, placeholders,
30
+ * and test data, but not for passwords, API keys, or other cryptographic secrets.
25
31
  *
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
32
+ * @param {number} length - The positive integer length of the string to generate
33
+ * @param {RandomStringMode} [mode] - The character set to use (default: `'alphabetic'`)
28
34
  *
29
35
  * @returns {string} The generated random string
30
36
  *
@@ -34,9 +40,9 @@ const CHARSETS: Record<RandomStringMode, string> = {
34
40
  * ```typescript
35
41
  * import { randomString } from '@kikiutils/shared/string';
36
42
  *
37
- * console.log(randomString(8)); // e.g. 'aZbXwTyQ' (alphabetic)
38
- * console.log(randomString(6, 'numeric')); // e.g. '402398'
39
- * console.log(randomString(10, 'alphanumeric')); // e.g. 'a9Z4pQ8xY2'
43
+ * randomString(8); // e.g. 'aZbXwTyQ'
44
+ * randomString(6, 'numeric'); // e.g. '402398'
45
+ * randomString(10, 'alphanumeric'); // e.g. 'a9Z4pQ8xY2'
40
46
  * ```
41
47
  */
42
48
  export function randomString(length: number, mode: RandomStringMode = 'alphabetic') {
@@ -6,13 +6,52 @@ import type {
6
6
 
7
7
  export type { FilteredKeyPath } from './filtered-key-path';
8
8
 
9
+ /**
10
+ * A generic string-keyed object for utility APIs that intentionally accept any value shape.
11
+ */
9
12
  export type AnyRecord = Record<string, any>;
13
+
14
+ /**
15
+ * Binary-like inputs accepted by `toBuffer` across browser and Node.js runtimes.
16
+ */
10
17
  export type BinaryInput = ArrayBuffer | Blob | Buffer | File | NodeBlob | NodeFile | Uint8Array;
18
+
19
+ /**
20
+ * Boolean values represented either as booleans or common string literals.
21
+ */
11
22
  export type Booleanish = 'false' | 'true' | boolean;
23
+
24
+ /**
25
+ * Accepts either a full object or a partial patch of that object.
26
+ */
12
27
  export type MaybePartial<T> = Partial<T> | T;
28
+
29
+ /**
30
+ * Accepts either a mutable value or a readonly view of that value.
31
+ */
13
32
  export type MaybeReadonly<T> = Readonly<T> | T;
33
+
34
+ /**
35
+ * Explicitly nullable value helper.
36
+ */
14
37
  export type Nullable<T> = null | T;
38
+
39
+ /**
40
+ * Number-like value represented as a number or a numeric string.
41
+ */
15
42
  export type Numberish = number | string;
43
+
44
+ /**
45
+ * A `Record` where every key is optional.
46
+ */
16
47
  export type PartialRecord<K extends keyof any, T> = Partial<Record<K, T>>;
48
+
49
+ /**
50
+ * A readonly `PartialRecord`.
51
+ */
17
52
  export type ReadonlyPartialRecord<K extends keyof any, T> = Readonly<PartialRecord<K, T>>;
53
+
54
+ /**
55
+ * A readonly `Record`.
56
+ */
18
57
  export type ReadonlyRecord<K extends keyof any, T> = Readonly<Record<K, T>>;