hyperstorage-js 5.1.0 → 6.0.1
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 +47 -20
- package/dist/index.cjs +872 -46
- package/dist/index.d.ts +8 -5
- package/dist/index.mjs +872 -46
- package/dist/index.umd.js +1 -1
- package/package.json +7 -2
- package/src/index.ts +27 -54
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import superjson from 'superjson';
|
|
1
2
|
/**
|
|
2
3
|
* @class HyperStorage
|
|
3
4
|
* @classdesc A lightweight wrapper for localStorage/sessionStorage
|
|
@@ -9,6 +10,7 @@ declare class HyperStorage<T> {
|
|
|
9
10
|
#private;
|
|
10
11
|
/** Version of the library, injected via Rollup replace plugin. */
|
|
11
12
|
static readonly version: string;
|
|
13
|
+
static readonly superjson: typeof superjson;
|
|
12
14
|
/** Key name under which the data is stored. */
|
|
13
15
|
readonly itemName: string;
|
|
14
16
|
/** Default value used when the key does not exist in storage. */
|
|
@@ -25,7 +27,7 @@ declare class HyperStorage<T> {
|
|
|
25
27
|
* @param {string} itemName - The key name under which the data will be stored.
|
|
26
28
|
* @param {T} [defaultValue] - Default value assigned to the key if it does not exist yet.
|
|
27
29
|
* @param {Object} [options={}] - Optional configuration parameters.
|
|
28
|
-
* @param {(value:
|
|
30
|
+
* @param {(value: T) => string} [options.encodeFn] - Optional function to encode stored values.
|
|
29
31
|
* @param {(value: string) => string} [options.decodeFn] - Optional function to decode stored values.
|
|
30
32
|
* @param {Storage} [options.storage=window.localStorage] - Optional custom storage backend.
|
|
31
33
|
*
|
|
@@ -34,8 +36,8 @@ declare class HyperStorage<T> {
|
|
|
34
36
|
* @throws {TypeError} If `storage` does not implement the standard Storage API.
|
|
35
37
|
*/
|
|
36
38
|
constructor(itemName: string, defaultValue: T, options?: {
|
|
37
|
-
encodeFn?: (value:
|
|
38
|
-
decodeFn?: (value: string) =>
|
|
39
|
+
encodeFn?: (value: T) => string;
|
|
40
|
+
decodeFn?: (value: string) => T;
|
|
39
41
|
storage?: Storage;
|
|
40
42
|
});
|
|
41
43
|
/**
|
|
@@ -48,8 +50,9 @@ declare class HyperStorage<T> {
|
|
|
48
50
|
*/
|
|
49
51
|
get value(): T;
|
|
50
52
|
/**
|
|
51
|
-
* Allows using the setter with a callback.
|
|
53
|
+
* Allows using the setter with property assignment or a callback.
|
|
52
54
|
*/
|
|
55
|
+
set<K extends keyof T>(key: K, value: T[K]): T;
|
|
53
56
|
set(callback: (value: T) => T): T;
|
|
54
57
|
/**
|
|
55
58
|
* Synchronizes the internal cache (`#value`) with the actual value in storage.
|
|
@@ -57,7 +60,7 @@ declare class HyperStorage<T> {
|
|
|
57
60
|
* This is only necessary if the stored value may have been modified externally.
|
|
58
61
|
* Using this function should be avoided when possible and is not type safe.
|
|
59
62
|
*/
|
|
60
|
-
sync(decodeFn?: (value: string) =>
|
|
63
|
+
sync(decodeFn?: (value: string) => T): unknown;
|
|
61
64
|
/**
|
|
62
65
|
* Resets the stored value to its configured default.
|
|
63
66
|
*
|