native-document 1.0.101 → 1.0.102
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/index.d.ts +2 -3
- package/package.json +1 -1
- package/router.d.ts +7 -0
- package/types/localStorage.ts +102 -0
package/index.d.ts
CHANGED
|
@@ -8,14 +8,13 @@ export * from './types/args-types';
|
|
|
8
8
|
export * from './types/memoize';
|
|
9
9
|
export * from './types/template-cloner';
|
|
10
10
|
export * from './types/singleton';
|
|
11
|
+
export * from './types/localStorage';
|
|
11
12
|
|
|
12
13
|
// Main static exports
|
|
13
14
|
import { ObservableStatic } from './types/observable';
|
|
14
|
-
import { RouterStatic } from './types/router';
|
|
15
15
|
import { StoreStatic } from './types/store';
|
|
16
16
|
|
|
17
17
|
export declare const Observable: ObservableStatic;
|
|
18
18
|
export declare const $: ObservableStatic;
|
|
19
19
|
export declare const obs: ObservableStatic;
|
|
20
|
-
export declare const Store: StoreStatic;
|
|
21
|
-
export declare const Router: RouterStatic;
|
|
20
|
+
export declare const Store: StoreStatic;
|
package/package.json
CHANGED
package/router.d.ts
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
export interface LocalStorageStatic {
|
|
2
|
+
/**
|
|
3
|
+
* Retrieves a value from localStorage and parses it as JSON.
|
|
4
|
+
* Throws a NativeDocumentError if the value is not valid JSON.
|
|
5
|
+
*
|
|
6
|
+
* @param key - The storage key
|
|
7
|
+
* @returns The parsed JSON value
|
|
8
|
+
* @throws NativeDocumentError if JSON parsing fails
|
|
9
|
+
*/
|
|
10
|
+
getJson<T = unknown>(key: string): T;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Retrieves a value from localStorage and converts it to a number.
|
|
14
|
+
*
|
|
15
|
+
* @param key - The storage key
|
|
16
|
+
* @returns The numeric value, or NaN if conversion fails
|
|
17
|
+
*/
|
|
18
|
+
getNumber(key: string): number;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Retrieves a value from localStorage and converts it to a boolean.
|
|
22
|
+
* Returns true if the stored value is 'true' or '1'.
|
|
23
|
+
*
|
|
24
|
+
* @param key - The storage key
|
|
25
|
+
* @returns The boolean value
|
|
26
|
+
*/
|
|
27
|
+
getBool(key: string): boolean;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Serializes a value as JSON and stores it in localStorage.
|
|
31
|
+
*
|
|
32
|
+
* @param key - The storage key
|
|
33
|
+
* @param value - The value to serialize and store
|
|
34
|
+
*/
|
|
35
|
+
setJson<T = unknown>(key: string, value: T): void;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Stores a boolean value in localStorage as 'true' or 'false'.
|
|
39
|
+
*
|
|
40
|
+
* @param key - The storage key
|
|
41
|
+
* @param value - The boolean value to store
|
|
42
|
+
*/
|
|
43
|
+
setBool(key: string, value: boolean): void;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Retrieves a raw string value from localStorage.
|
|
47
|
+
*
|
|
48
|
+
* @param key - The storage key
|
|
49
|
+
* @param defaultValue - Value returned if the key does not exist (default: null)
|
|
50
|
+
* @returns The stored string value, or defaultValue if not found
|
|
51
|
+
*/
|
|
52
|
+
get(key: string, defaultValue?: string | null): string | null;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Stores a value in localStorage.
|
|
56
|
+
*
|
|
57
|
+
* @param key - The storage key
|
|
58
|
+
* @param value - The value to store
|
|
59
|
+
*/
|
|
60
|
+
set(key: string, value: string): void;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Removes an entry from localStorage.
|
|
64
|
+
*
|
|
65
|
+
* @param key - The storage key to remove
|
|
66
|
+
*/
|
|
67
|
+
remove(key: string): void;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Checks whether a key exists in localStorage.
|
|
71
|
+
*
|
|
72
|
+
* @param key - The storage key to check
|
|
73
|
+
* @returns true if the key exists, false otherwise
|
|
74
|
+
*/
|
|
75
|
+
has(key: string): boolean;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export declare const LocalStorage: LocalStorageStatic;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Retrieves a value from localStorage, automatically casting it to the type of the provided default value.
|
|
82
|
+
* Returns the default value if the key does not exist.
|
|
83
|
+
*
|
|
84
|
+
* @param key - The storage key
|
|
85
|
+
* @param value - The default value (also determines the expected type)
|
|
86
|
+
* @returns The stored value cast to T, or the default value
|
|
87
|
+
*/
|
|
88
|
+
export declare function $getFromStorage<T>(key: string, value: T): T;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Returns the appropriate LocalStorage setter function based on the type of the provided value.
|
|
92
|
+
*
|
|
93
|
+
* @param value - The value whose type determines the setter to use
|
|
94
|
+
* @returns setJson for objects, setBool for booleans, set for all other types
|
|
95
|
+
*/
|
|
96
|
+
export declare function $saveToStorage<T>(
|
|
97
|
+
value: T
|
|
98
|
+
): T extends object
|
|
99
|
+
? typeof LocalStorage.setJson
|
|
100
|
+
: T extends boolean
|
|
101
|
+
? typeof LocalStorage.setBool
|
|
102
|
+
: typeof LocalStorage.set;
|