@kikiutils/shared 15.0.0 → 15.0.2
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 +46 -119
- package/dist/classes/ssh-client.d.ts +3 -3
- package/dist/classes/ssh-client.d.ts.map +1 -1
- package/dist/consola.d.ts +3 -3
- package/dist/consola.d.ts.map +1 -1
- package/dist/crypto-hash.d.ts +145 -0
- package/dist/crypto-hash.d.ts.map +1 -1
- package/dist/crypto-hash.js +137 -7
- package/dist/crypto-hash.js.map +1 -1
- package/dist/datetime.d.ts +0 -2
- package/dist/datetime.d.ts.map +1 -1
- package/dist/datetime.js +0 -2
- package/dist/datetime.js.map +1 -1
- package/dist/env.d.ts +2 -0
- package/dist/env.d.ts.map +1 -1
- package/dist/env.js +2 -0
- package/dist/env.js.map +1 -1
- package/dist/event-awaiter.js +1 -1
- package/dist/event-awaiter.js.map +1 -1
- package/dist/hash.d.ts +48 -5
- package/dist/hash.d.ts.map +1 -1
- package/dist/hash.js +49 -6
- package/dist/hash.js.map +1 -1
- package/dist/math.js +1 -1
- package/dist/math.js.map +1 -1
- package/dist/object.d.ts +4 -0
- package/dist/object.d.ts.map +1 -1
- package/dist/object.js +4 -0
- package/dist/object.js.map +1 -1
- package/dist/pino.d.ts +3 -3
- package/dist/random.js +2 -0
- package/dist/random.js.map +1 -1
- package/dist/storages/lru/keyed-store.d.ts +22 -0
- package/dist/storages/lru/keyed-store.d.ts.map +1 -1
- package/dist/storages/lru/keyed-store.js +22 -0
- package/dist/storages/lru/keyed-store.js.map +1 -1
- package/dist/storages/redis/keyed-store.d.ts +25 -0
- package/dist/storages/redis/keyed-store.d.ts.map +1 -1
- package/dist/storages/redis/keyed-store.js +25 -0
- package/dist/storages/redis/keyed-store.js.map +1 -1
- package/dist/storages/redis/msgpack.d.ts +20 -0
- package/dist/storages/redis/msgpack.d.ts.map +1 -1
- package/dist/storages/redis/msgpack.js +20 -0
- package/dist/storages/redis/msgpack.js.map +1 -1
- package/dist/storages/redis/types.d.ts +42 -0
- package/dist/storages/redis/types.d.ts.map +1 -1
- package/dist/string.js +1 -1
- package/dist/string.js.map +1 -1
- package/dist/time.d.ts +17 -0
- package/dist/time.d.ts.map +1 -1
- package/dist/time.js +17 -0
- package/dist/time.js.map +1 -1
- package/dist/url.d.ts +3 -0
- package/dist/url.d.ts.map +1 -1
- package/dist/url.js +8 -2
- package/dist/url.js.map +1 -1
- package/dist/vue.d.ts +6 -0
- package/dist/vue.d.ts.map +1 -1
- package/dist/vue.js +6 -0
- package/dist/vue.js.map +1 -1
- package/package.json +22 -22
- package/src/crypto-hash.ts +143 -14
- package/src/datetime.ts +0 -2
- package/src/env.ts +2 -0
- package/src/event-awaiter.ts +1 -1
- package/src/hash.ts +56 -14
- package/src/math.ts +2 -1
- package/src/object.ts +4 -0
- package/src/random.ts +3 -0
- package/src/storages/lru/keyed-store.ts +22 -0
- package/src/storages/redis/keyed-store.ts +25 -0
- package/src/storages/redis/msgpack.ts +20 -0
- package/src/storages/redis/types.ts +52 -0
- package/src/string.ts +1 -1
- package/src/time.ts +17 -0
- package/src/url.ts +13 -2
- package/src/vue.ts +6 -0
package/src/hash.ts
CHANGED
|
@@ -1,17 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file provides a set of functions for creating SHA-3 hash digests
|
|
3
|
-
* using different bit lengths (224, 256, 384, 512).
|
|
4
|
-
* These functions use the [@noble/hashes](https://github.com/paulmillr/noble-hashes) library to generate the hashes.
|
|
5
|
-
* Can be used in the browser, mainly for Nuxt/Vue and other frameworks compiled and executed in the browser.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```typescript
|
|
9
|
-
* import { sha3256 } from '@kikiutils/shared/hash';
|
|
10
|
-
*
|
|
11
|
-
* console.log(sha3256('test')); // 36f028580bb02cc8272a9a020f4200e346e276ae664e45ee80745574e2f5ab80
|
|
12
|
-
* ```
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
1
|
import {
|
|
16
2
|
sha3_224,
|
|
17
3
|
sha3_256,
|
|
@@ -23,18 +9,74 @@ import {
|
|
|
23
9
|
utf8ToBytes,
|
|
24
10
|
} from '@noble/hashes/utils.js';
|
|
25
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Computes the SHA-3 hash of the given data using the 224-bit digest.
|
|
14
|
+
*
|
|
15
|
+
* @param {string | Uint8Array} data - The input data to hash
|
|
16
|
+
*
|
|
17
|
+
* @returns {string} The hexadecimal hash digest
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* import { sha3224 } from '@kikiutils/shared/hash';
|
|
22
|
+
*
|
|
23
|
+
* console.log(sha3224('test')); // 0qW8FoqDcFmkpuqR9J3uT8YXVb3pWnLYgA4JqyprhqZ5H...
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
26
|
export function sha3224(data: string | Uint8Array) {
|
|
27
27
|
return bytesToHex(sha3_224(typeof data === 'string' ? utf8ToBytes(data) : data));
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
/**
|
|
31
|
+
* Computes the SHA-3 hash of the given data using the 256-bit digest.
|
|
32
|
+
*
|
|
33
|
+
* @param {string | Uint8Array} data - The input data to hash
|
|
34
|
+
*
|
|
35
|
+
* @returns {string} The hexadecimal hash digest
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* import { sha3256 } from '@kikiutils/shared/hash';
|
|
40
|
+
*
|
|
41
|
+
* console.log(sha3256('test')); // 36f028580bb02cc8272a9a020f4200e346e276ae664e45ee80745574e2f5ab80
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
30
44
|
export function sha3256(data: string | Uint8Array) {
|
|
31
45
|
return bytesToHex(sha3_256(typeof data === 'string' ? utf8ToBytes(data) : data));
|
|
32
46
|
}
|
|
33
47
|
|
|
48
|
+
/**
|
|
49
|
+
* Computes the SHA-3 hash of the given data using the 384-bit digest.
|
|
50
|
+
*
|
|
51
|
+
* @param {string | Uint8Array} data - The input data to hash
|
|
52
|
+
*
|
|
53
|
+
* @returns {string} The hexadecimal hash digest
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* import { sha3384 } from '@kikiutils/shared/hash';
|
|
58
|
+
*
|
|
59
|
+
* console.log(sha3384('test')); // 1Q2wQAYaZ4o8vWX5bEB2n3Y...
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
34
62
|
export function sha3384(data: string | Uint8Array) {
|
|
35
63
|
return bytesToHex(sha3_384(typeof data === 'string' ? utf8ToBytes(data) : data));
|
|
36
64
|
}
|
|
37
65
|
|
|
66
|
+
/**
|
|
67
|
+
* Computes the SHA-3 hash of the given data using the 512-bit digest.
|
|
68
|
+
*
|
|
69
|
+
* @param {string | Uint8Array} data - The input data to hash
|
|
70
|
+
*
|
|
71
|
+
* @returns {string} The hexadecimal hash digest
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* import { sha3512 } from '@kikiutils/shared/hash';
|
|
76
|
+
*
|
|
77
|
+
* console.log(sha3512('test')); // b_NQJ8FJBY9dIjm1q7...
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
38
80
|
export function sha3512(data: string | Uint8Array) {
|
|
39
81
|
return bytesToHex(sha3_512(typeof data === 'string' ? utf8ToBytes(data) : data));
|
|
40
82
|
}
|
package/src/math.ts
CHANGED
|
@@ -51,7 +51,8 @@ export function toPercentageString(
|
|
|
51
51
|
const molecularDecimal = new Decimal(molecular.toString());
|
|
52
52
|
const denominatorDecimal = new Decimal(denominator.toString());
|
|
53
53
|
const calculationResult = molecularDecimal.div(denominatorDecimal);
|
|
54
|
-
|
|
54
|
+
|
|
55
|
+
const result = calculationResult.isNaN() || !calculationResult.isFinite()
|
|
55
56
|
? '0.00'
|
|
56
57
|
: calculationResult.times(100).toFixed(options?.decimalPlaces ?? 2);
|
|
57
58
|
|
package/src/object.ts
CHANGED
|
@@ -8,6 +8,9 @@
|
|
|
8
8
|
* It is designed for use cases such as signature generation, cache key construction,
|
|
9
9
|
* or any context requiring consistent and predictable object serialization.
|
|
10
10
|
*
|
|
11
|
+
* Note: Empty objects and arrays produce an empty string, which is useful for
|
|
12
|
+
* generating deterministic signature payloads.
|
|
13
|
+
*
|
|
11
14
|
* @param {Record<string, any>} input - The object to serialize. Can contain nested objects and arrays
|
|
12
15
|
* @param {string} kvSeparator - The string used to separate each key from its value (default: '=')
|
|
13
16
|
* @param {string} pairSeparator - The string used to separate each key-value pair (default: '&')
|
|
@@ -19,6 +22,7 @@
|
|
|
19
22
|
*
|
|
20
23
|
* console.log(stringifyObjectDeterministically({ b: 2, a: { x: 1, y: [3, 4] } })); // a.x=1&a.y.0=3&a.y.1=4&b=2
|
|
21
24
|
* console.log(stringifyObjectDeterministically({ foo: 'bar' }, ':', '|')); // foo:bar
|
|
25
|
+
* console.log(stringifyObjectDeterministically({})); // ''
|
|
22
26
|
* ```
|
|
23
27
|
*/
|
|
24
28
|
export function stringifyObjectDeterministically(
|
package/src/random.ts
CHANGED
|
@@ -25,6 +25,9 @@ export function generateWithNestedRandomLength<T = string>(
|
|
|
25
25
|
maxMin: number,
|
|
26
26
|
maxMax: number,
|
|
27
27
|
) {
|
|
28
|
+
if (minMin > minMax) throw new Error(`Invalid range: minMin (${minMin}) cannot be greater than minMax (${minMax})`);
|
|
29
|
+
if (maxMin > maxMax) throw new Error(`Invalid range: maxMin (${maxMin}) cannot be greater than maxMax (${maxMax})`);
|
|
30
|
+
|
|
28
31
|
const random = (min: number, max: number) => Math.floor(Math.random() * (max - min + 1)) + min;
|
|
29
32
|
const innerMin = random(minMin, minMax);
|
|
30
33
|
const finalLength = random(Math.max(innerMin, maxMin), maxMax);
|
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
import type { LRUCache } from 'lru-cache';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Creates a keyed store wrapper around an LRU cache instance.
|
|
5
|
+
*
|
|
6
|
+
* @template D - The data type stored in the keyed store
|
|
7
|
+
*
|
|
8
|
+
* @param {LRUCache<any, any, any>} lruInstance - The underlying lru-cache instance
|
|
9
|
+
*
|
|
10
|
+
* @returns {(keyFn: (...args: P) => string) => Readonly<{
|
|
11
|
+
* getItem, getItemTtl, hasItem, removeItem, resolveKey, setItem
|
|
12
|
+
* }>} A keyed store factory that takes a key resolution function
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* import { createLruKeyedStore } from '@kikiutils/shared/storages/lru/keyed-store';
|
|
17
|
+
* import { LRUCache } from 'lru-cache';
|
|
18
|
+
*
|
|
19
|
+
* const lru = new LRUCache({ max: 100 });
|
|
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' }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
3
25
|
export function createLruKeyedStore<D = unknown>(lruInstance: LRUCache<any, any, any>) {
|
|
4
26
|
return <P extends any[]>(keyFn: (...args: P) => string) => Object.freeze({
|
|
5
27
|
/**
|
|
@@ -2,6 +2,31 @@ import type { MaybeReadonly } from '../../types';
|
|
|
2
2
|
|
|
3
3
|
import type { RedisLikeStorage } from './types';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Creates a keyed store wrapper around a Redis-like storage.
|
|
7
|
+
*
|
|
8
|
+
* @template D - The data type stored in the keyed store
|
|
9
|
+
*
|
|
10
|
+
* @param {MaybeReadonly<RedisLikeStorage>} storage - The underlying Redis-like storage instance
|
|
11
|
+
*
|
|
12
|
+
* @returns {(keyFn: (...args: P) => string) => Readonly<{
|
|
13
|
+
* getItem, getItemTtl, hasItem, removeItem, resolveKey, setItem, setItemWithTtl
|
|
14
|
+
* }>} A keyed store factory that takes a key resolution function
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import { createRedisKeyedStore } from '@kikiutils/shared/storages/redis/keyed-store';
|
|
19
|
+
* import { createRedisMsgpackStorage } from '@kikiutils/shared/storages/redis/msgpack';
|
|
20
|
+
* import { createClient } from 'redis';
|
|
21
|
+
*
|
|
22
|
+
* const client = createClient();
|
|
23
|
+
* await client.connect();
|
|
24
|
+
* const storage = createRedisMsgpackStorage(client as unknown as RedisLikeAdapter);
|
|
25
|
+
* const keyedStore = createRedisKeyedStore(storage)((userId: string) => `user:${userId}`);
|
|
26
|
+
* await keyedStore.setItem({ name: 'Alice' }, 'user-123');
|
|
27
|
+
* const user = await keyedStore.getItem('user-123'); // { name: 'Alice' }
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
5
30
|
export function createRedisKeyedStore<D = unknown>(storage: MaybeReadonly<RedisLikeStorage>) {
|
|
6
31
|
return <P extends any[]>(keyFn: (...args: P) => string) => Object.freeze({
|
|
7
32
|
getItem: (...args: P) => storage.getItem<D>(keyFn(...args)),
|
|
@@ -13,6 +13,26 @@ if (!isNativeAccelerationEnabled) {
|
|
|
13
13
|
console.warn('Native acceleration not enabled for msgpackr, verify that install finished properly');
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Creates a Redis-like storage using msgpack serialization.
|
|
18
|
+
*
|
|
19
|
+
* @param {RedisLikeAdapter} adapter - The Redis-like adapter to use for raw buffer operations
|
|
20
|
+
*
|
|
21
|
+
* @returns {Readonly<RedisLikeStorage>} A readonly storage instance
|
|
22
|
+
* with getItem, setItem, hasItem, removeItem, getItemTtl, setItemWithTtl
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* import { createRedisMsgpackStorage } from '@kikiutils/shared/storages/redis/msgpack';
|
|
27
|
+
* import { createClient } from 'redis';
|
|
28
|
+
*
|
|
29
|
+
* const client = createClient();
|
|
30
|
+
* await client.connect();
|
|
31
|
+
* const storage = createRedisMsgpackStorage(client as unknown as RedisLikeAdapter);
|
|
32
|
+
* await storage.setItem('key', { foo: 'bar' });
|
|
33
|
+
* const value = await storage.getItem('key'); // { foo: 'bar' }
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
16
36
|
export function createRedisMsgpackStorage(adapter: RedisLikeAdapter): Readonly<RedisLikeStorage> {
|
|
17
37
|
return Object.freeze({
|
|
18
38
|
async getItem<T = unknown>(key: string) {
|
|
@@ -1,19 +1,71 @@
|
|
|
1
1
|
import type { Nullable } from '../../types';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Low-level Redis-like adapter interface for raw buffer operations.
|
|
5
|
+
*/
|
|
3
6
|
export interface RedisLikeAdapter {
|
|
7
|
+
/**
|
|
8
|
+
* Deletes a key and returns the number of keys deleted.
|
|
9
|
+
*/
|
|
4
10
|
delete: (key: string) => Promise<number>;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Gets the raw buffer value for a key.
|
|
14
|
+
*/
|
|
5
15
|
getBuffer: (key: string) => Promise<Nullable<Uint8Array>>;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Checks if a key exists.
|
|
19
|
+
*/
|
|
6
20
|
has: (key: string) => Promise<boolean>;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Sets a raw buffer value for a key.
|
|
24
|
+
*/
|
|
7
25
|
setBuffer: (key: string, value: Uint8Array) => Promise<'OK' | void>;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Sets a raw buffer value for a key with a TTL.
|
|
29
|
+
*/
|
|
8
30
|
setBufferEx: (key: string, ttlSeconds: number, value: Uint8Array) => Promise<'OK' | void>;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Gets the TTL of a key in seconds.
|
|
34
|
+
*/
|
|
9
35
|
ttl: (key: string) => Promise<number>;
|
|
10
36
|
}
|
|
11
37
|
|
|
38
|
+
/**
|
|
39
|
+
* High-level Redis-like storage interface with typed get/set operations.
|
|
40
|
+
*/
|
|
12
41
|
export interface RedisLikeStorage {
|
|
42
|
+
/**
|
|
43
|
+
* Gets a deserialized value by key.
|
|
44
|
+
*/
|
|
13
45
|
getItem: <T = unknown>(key: string) => Promise<Nullable<T>>;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Gets the TTL of a key in seconds.
|
|
49
|
+
*/
|
|
14
50
|
getItemTtl: (key: string) => Promise<number>;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Checks if a key exists.
|
|
54
|
+
*/
|
|
15
55
|
hasItem: (key: string) => Promise<boolean>;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Removes a key.
|
|
59
|
+
*/
|
|
16
60
|
removeItem: (key: string) => Promise<boolean>;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Sets a value for a key.
|
|
64
|
+
*/
|
|
17
65
|
setItem: (key: string, value: any) => Promise<boolean>;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Sets a value for a key with a TTL.
|
|
69
|
+
*/
|
|
18
70
|
setItemWithTtl: (key: string, ttlSeconds: number, value: any) => Promise<boolean>;
|
|
19
71
|
}
|
package/src/string.ts
CHANGED
|
@@ -46,5 +46,5 @@ export function randomString(length: number, mode: RandomStringMode = 'alphabeti
|
|
|
46
46
|
|
|
47
47
|
const charset = CHARSETS[mode];
|
|
48
48
|
if (!charset) throw new Error(`Unsupported mode: ${mode}`);
|
|
49
|
-
return Array.from({ length })
|
|
49
|
+
return Array.from({ length }, () => charset[Math.floor(Math.random() * charset.length)]).join('');
|
|
50
50
|
}
|
package/src/time.ts
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a delay that can be aborted via AbortSignal.
|
|
3
|
+
*
|
|
4
|
+
* @param {number} ms - Delay duration in milliseconds
|
|
5
|
+
* @param {AbortSignal} [signal] - Optional AbortSignal to cancel the delay
|
|
6
|
+
*
|
|
7
|
+
* @returns {Promise<undefined>} A promise that resolves after ms or resolves immediately on abort
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { abortableDelay } from '@kikiutils/shared/time';
|
|
12
|
+
*
|
|
13
|
+
* const controller = new AbortController();
|
|
14
|
+
* setTimeout(() => controller.abort(), 1000);
|
|
15
|
+
* await abortableDelay(5000, controller.signal); // resolves after ~1s when aborted
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
1
18
|
export function abortableDelay(ms: number, signal?: AbortSignal) {
|
|
2
19
|
return new Promise((resolve) => {
|
|
3
20
|
const timeout = setTimeout(resolve, ms);
|
package/src/url.ts
CHANGED
|
@@ -5,12 +5,23 @@
|
|
|
5
5
|
*
|
|
6
6
|
* @param {string} url - The target URL to modify
|
|
7
7
|
* @param {string} redirectPath - The path to use as the redirect destination
|
|
8
|
+
* (must be an absolute path starting with '/')
|
|
8
9
|
*
|
|
9
10
|
* @returns {string} A new URL string with the `redirect` query parameter
|
|
11
|
+
*
|
|
12
|
+
* @throws {Error} If redirectPath is not a valid relative path (must start with '/')
|
|
10
13
|
*/
|
|
11
14
|
export function appendRedirectParamToUrl(url: string, redirectPath: string) {
|
|
12
|
-
|
|
15
|
+
if (!redirectPath.startsWith('/')) {
|
|
16
|
+
throw new Error(
|
|
17
|
+
`Invalid redirect path: "${redirectPath}". Redirect paths must be absolute paths starting with '/'.`,
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const [baseAndHash, rawQuery = ''] = url.split('?');
|
|
22
|
+
const [base, hash] = (baseAndHash || '').split('#');
|
|
13
23
|
const searchParams = new URLSearchParams(rawQuery);
|
|
14
24
|
searchParams.set('redirect', redirectPath);
|
|
15
|
-
|
|
25
|
+
const queryString = searchParams.toString();
|
|
26
|
+
return hash ? `${base}?${queryString}#${hash}` : `${base}?${queryString}`;
|
|
16
27
|
}
|
package/src/vue.ts
CHANGED
|
@@ -43,6 +43,12 @@ export function clearTimeoutRef(timeoutRef: Ref<Nullable<ReturnType<typeof setTi
|
|
|
43
43
|
* A Vue composition function that remembers and restores scroll position
|
|
44
44
|
* of a scrollable container across route changes and keep-alive activation.
|
|
45
45
|
*
|
|
46
|
+
* Designed for use with `<KeepAlive>` components. Scroll state is saved on
|
|
47
|
+
* route leave and restored when the component is activated again.
|
|
48
|
+
*
|
|
49
|
+
* Note: Without `<KeepAlive>`, the component state is destroyed on unmount,
|
|
50
|
+
* so scroll position will not be preserved.
|
|
51
|
+
*
|
|
46
52
|
* @template T - The type of the scrollable element (defaults to HTMLElement)
|
|
47
53
|
*
|
|
48
54
|
* @param {Ref<Nullable<T>>} containerRef - A ref to the scrollable HTML element
|