@kikiutils/shared 15.0.2 → 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.
- package/README.md +137 -67
- package/dist/buffer.js.map +1 -1
- package/dist/classes/path.d.ts +8 -0
- package/dist/classes/path.d.ts.map +1 -1
- package/dist/classes/path.js +5 -0
- package/dist/classes/path.js.map +1 -1
- package/dist/classes/precision-number.d.ts +215 -11
- package/dist/classes/precision-number.d.ts.map +1 -1
- package/dist/classes/precision-number.js +268 -25
- package/dist/classes/precision-number.js.map +1 -1
- package/dist/classes/ssh-client.js.map +1 -1
- package/dist/clipboard.js.map +1 -1
- package/dist/consola.js.map +1 -1
- package/dist/crypto-hash.d.ts +7 -7
- package/dist/crypto-hash.js +7 -7
- package/dist/crypto-hash.js.map +1 -1
- package/dist/datetime.js.map +1 -1
- package/dist/element-plus.js.map +1 -1
- package/dist/enum.js.map +1 -1
- package/dist/env.js.map +1 -1
- package/dist/event-awaiter.js.map +1 -1
- package/dist/general.js.map +1 -1
- package/dist/hash.d.ts +3 -3
- package/dist/hash.js +3 -3
- package/dist/hash.js.map +1 -1
- package/dist/math.js.map +1 -1
- package/dist/number.js.map +1 -1
- package/dist/object.js.map +1 -1
- package/dist/pino.js.map +1 -1
- package/dist/random.js.map +1 -1
- package/dist/storages/lru/keyed-store.d.ts +3 -3
- package/dist/storages/lru/keyed-store.js +11 -3
- package/dist/storages/lru/keyed-store.js.map +1 -1
- package/dist/storages/redis/keyed-store.d.ts +1 -1
- package/dist/storages/redis/keyed-store.js +1 -1
- package/dist/storages/redis/keyed-store.js.map +1 -1
- package/dist/storages/redis/msgpack.js.map +1 -1
- package/dist/string.d.ts +12 -6
- package/dist/string.d.ts.map +1 -1
- package/dist/string.js +9 -6
- package/dist/string.js.map +1 -1
- package/dist/time.js.map +1 -1
- package/dist/types/index.d.ts +30 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/url.js.map +1 -1
- package/dist/vue.js.map +1 -1
- package/dist/web.js.map +1 -1
- package/package.json +15 -24
- package/src/classes/path.ts +9 -0
- package/src/classes/precision-number.ts +300 -25
- package/src/crypto-hash.ts +7 -7
- package/src/hash.ts +3 -3
- package/src/storages/lru/keyed-store.ts +3 -3
- package/src/storages/redis/keyed-store.ts +1 -1
- package/src/string.ts +12 -6
- package/src/types/index.ts +39 -0
package/src/crypto-hash.ts
CHANGED
|
@@ -16,7 +16,7 @@ import type {
|
|
|
16
16
|
* ```typescript
|
|
17
17
|
* import { cryptoMd5 } from '@kikiutils/shared/crypto-hash';
|
|
18
18
|
*
|
|
19
|
-
* console.log(cryptoMd5('test')); //
|
|
19
|
+
* console.log(cryptoMd5('test')); // 098f6bcd4621d373cade4e832627b4f6
|
|
20
20
|
* ```
|
|
21
21
|
*/
|
|
22
22
|
export function cryptoMd5(data: BinaryLike, outputEncoding: BinaryToTextEncoding = 'hex') {
|
|
@@ -53,7 +53,7 @@ export function cryptoMd5ToBuffer(data: BinaryLike) {
|
|
|
53
53
|
* ```typescript
|
|
54
54
|
* import { cryptoSha3224 } from '@kikiutils/shared/crypto-hash';
|
|
55
55
|
*
|
|
56
|
-
* console.log(cryptoSha3224('test')); //
|
|
56
|
+
* console.log(cryptoSha3224('test')); // 3797bf0afbbfca4a7bbba7602a2b552746876517a7f9b7ce2db0ae7b
|
|
57
57
|
* ```
|
|
58
58
|
*/
|
|
59
59
|
export function cryptoSha3224(data: BinaryLike, outputEncoding: BinaryToTextEncoding = 'hex') {
|
|
@@ -71,7 +71,7 @@ export function cryptoSha3224(data: BinaryLike, outputEncoding: BinaryToTextEnco
|
|
|
71
71
|
* ```typescript
|
|
72
72
|
* import { cryptoSha3224ToBuffer } from '@kikiutils/shared/crypto-hash';
|
|
73
73
|
*
|
|
74
|
-
* console.log(cryptoSha3224ToBuffer('test')); // <Buffer
|
|
74
|
+
* console.log(cryptoSha3224ToBuffer('test')); // <Buffer 37 97 bf 0a ...>
|
|
75
75
|
* ```
|
|
76
76
|
*/
|
|
77
77
|
export function cryptoSha3224ToBuffer(data: BinaryLike) {
|
|
@@ -127,7 +127,7 @@ export function cryptoSha3256ToBuffer(data: BinaryLike) {
|
|
|
127
127
|
* ```typescript
|
|
128
128
|
* import { cryptoSha3384 } from '@kikiutils/shared/crypto-hash';
|
|
129
129
|
*
|
|
130
|
-
* console.log(cryptoSha3384('test')); //
|
|
130
|
+
* console.log(cryptoSha3384('test')); // e516dabb23b6e30026863543282780a3ae0dccf05551cf0295178d7f...
|
|
131
131
|
* ```
|
|
132
132
|
*/
|
|
133
133
|
export function cryptoSha3384(data: BinaryLike, outputEncoding: BinaryToTextEncoding = 'hex') {
|
|
@@ -145,7 +145,7 @@ export function cryptoSha3384(data: BinaryLike, outputEncoding: BinaryToTextEnco
|
|
|
145
145
|
* ```typescript
|
|
146
146
|
* import { cryptoSha3384ToBuffer } from '@kikiutils/shared/crypto-hash';
|
|
147
147
|
*
|
|
148
|
-
* console.log(cryptoSha3384ToBuffer('test')); // <Buffer
|
|
148
|
+
* console.log(cryptoSha3384ToBuffer('test')); // <Buffer e5 16 da bb ...>
|
|
149
149
|
* ```
|
|
150
150
|
*/
|
|
151
151
|
export function cryptoSha3384ToBuffer(data: BinaryLike) {
|
|
@@ -164,7 +164,7 @@ export function cryptoSha3384ToBuffer(data: BinaryLike) {
|
|
|
164
164
|
* ```typescript
|
|
165
165
|
* import { cryptoSha3512 } from '@kikiutils/shared/crypto-hash';
|
|
166
166
|
*
|
|
167
|
-
* console.log(cryptoSha3512('test')); //
|
|
167
|
+
* console.log(cryptoSha3512('test')); // 9ece086e9bac491fac5c1d1046ca11d737b92a2b2ebd93f005d7...
|
|
168
168
|
* ```
|
|
169
169
|
*/
|
|
170
170
|
export function cryptoSha3512(data: BinaryLike, outputEncoding: BinaryToTextEncoding = 'hex') {
|
|
@@ -182,7 +182,7 @@ export function cryptoSha3512(data: BinaryLike, outputEncoding: BinaryToTextEnco
|
|
|
182
182
|
* ```typescript
|
|
183
183
|
* import { cryptoSha3512ToBuffer } from '@kikiutils/shared/crypto-hash';
|
|
184
184
|
*
|
|
185
|
-
* console.log(cryptoSha3512ToBuffer('test')); // <Buffer
|
|
185
|
+
* console.log(cryptoSha3512ToBuffer('test')); // <Buffer 9e ce 08 6e ...>
|
|
186
186
|
* ```
|
|
187
187
|
*/
|
|
188
188
|
export function cryptoSha3512ToBuffer(data: BinaryLike) {
|
package/src/hash.ts
CHANGED
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
* ```typescript
|
|
21
21
|
* import { sha3224 } from '@kikiutils/shared/hash';
|
|
22
22
|
*
|
|
23
|
-
* console.log(sha3224('test')); //
|
|
23
|
+
* console.log(sha3224('test')); // 3797bf0afbbfca4a7bbba7602a2b552746876517a7f9b7ce2db0ae7b
|
|
24
24
|
* ```
|
|
25
25
|
*/
|
|
26
26
|
export function sha3224(data: string | Uint8Array) {
|
|
@@ -56,7 +56,7 @@ export function sha3256(data: string | Uint8Array) {
|
|
|
56
56
|
* ```typescript
|
|
57
57
|
* import { sha3384 } from '@kikiutils/shared/hash';
|
|
58
58
|
*
|
|
59
|
-
* console.log(sha3384('test')); //
|
|
59
|
+
* console.log(sha3384('test')); // e516dabb23b6e30026863543282780a3ae0dccf05551cf0295178d7f...
|
|
60
60
|
* ```
|
|
61
61
|
*/
|
|
62
62
|
export function sha3384(data: string | Uint8Array) {
|
|
@@ -74,7 +74,7 @@ export function sha3384(data: string | Uint8Array) {
|
|
|
74
74
|
* ```typescript
|
|
75
75
|
* import { sha3512 } from '@kikiutils/shared/hash';
|
|
76
76
|
*
|
|
77
|
-
* console.log(sha3512('test')); //
|
|
77
|
+
* console.log(sha3512('test')); // 9ece086e9bac491fac5c1d1046ca11d737b92a2b2ebd93f005d7...
|
|
78
78
|
* ```
|
|
79
79
|
*/
|
|
80
80
|
export function sha3512(data: string | Uint8Array) {
|
|
@@ -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
|
|
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
|
-
*
|
|
22
|
-
* const user =
|
|
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
|
|
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
|
|
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
|
|
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
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
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') {
|
package/src/types/index.ts
CHANGED
|
@@ -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>>;
|