@etsoo/shared 1.2.52 → 1.2.55
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/.github/workflows/main.yml +6 -5
- package/__tests__/ArrayUtils.ts +126 -126
- package/__tests__/ColorUtils.ts +24 -24
- package/__tests__/ContentDisposition.ts +18 -18
- package/__tests__/DataTypes.ts +222 -204
- package/__tests__/DateUtils.ts +82 -82
- package/__tests__/DomUtils.ts +352 -352
- package/__tests__/EHistory.ts +62 -62
- package/__tests__/ExtendUtils.ts +40 -40
- package/__tests__/Keyboard.ts +14 -14
- package/__tests__/NumberUtils.ts +37 -39
- package/__tests__/StorageUtils.ts +27 -27
- package/__tests__/Utils.ts +361 -363
- package/__tests__/tsconfig.json +15 -15
- package/lib/cjs/ActionResult.d.ts +1 -1
- package/lib/cjs/ActionResult.js +3 -3
- package/lib/cjs/ArrayUtils.d.ts +1 -1
- package/lib/cjs/ArrayUtils.js +4 -4
- package/lib/cjs/ColorUtils.d.ts +1 -1
- package/lib/cjs/ColorUtils.js +2 -2
- package/lib/cjs/DataTypes.d.ts +6 -6
- package/lib/cjs/DataTypes.js +50 -51
- package/lib/cjs/DateUtils.d.ts +1 -1
- package/lib/cjs/DateUtils.js +27 -28
- package/lib/cjs/DomUtils.d.ts +3 -3
- package/lib/cjs/DomUtils.js +64 -73
- package/lib/cjs/ExtendUtils.d.ts +1 -1
- package/lib/cjs/ExtendUtils.js +6 -6
- package/lib/cjs/IActionResult.d.ts +1 -1
- package/lib/cjs/NumberUtils.d.ts +1 -1
- package/lib/cjs/NumberUtils.js +9 -9
- package/lib/cjs/StorageUtils.js +2 -2
- package/lib/cjs/Utils.d.ts +4 -4
- package/lib/cjs/Utils.js +58 -62
- package/lib/cjs/index.d.ts +22 -22
- package/lib/cjs/storage/WindowStorage.d.ts +1 -1
- package/lib/cjs/types/ContentDisposition.d.ts +2 -2
- package/lib/cjs/types/ContentDisposition.js +11 -13
- package/lib/cjs/types/EColor.js +5 -7
- package/lib/cjs/types/EHistory.d.ts +3 -3
- package/lib/cjs/types/EHistory.js +4 -4
- package/lib/cjs/types/ErrorData.d.ts +1 -1
- package/lib/cjs/types/EventClass.js +1 -1
- package/lib/mjs/ActionResult.d.ts +1 -1
- package/lib/mjs/ActionResult.js +3 -3
- package/lib/mjs/ArrayUtils.d.ts +1 -1
- package/lib/mjs/ArrayUtils.js +5 -5
- package/lib/mjs/ColorUtils.d.ts +1 -1
- package/lib/mjs/ColorUtils.js +3 -3
- package/lib/mjs/DataTypes.d.ts +6 -6
- package/lib/mjs/DataTypes.js +50 -51
- package/lib/mjs/DateUtils.d.ts +1 -1
- package/lib/mjs/DateUtils.js +27 -28
- package/lib/mjs/DomUtils.d.ts +3 -3
- package/lib/mjs/DomUtils.js +67 -76
- package/lib/mjs/ExtendUtils.d.ts +1 -1
- package/lib/mjs/ExtendUtils.js +6 -6
- package/lib/mjs/IActionResult.d.ts +1 -1
- package/lib/mjs/NumberUtils.d.ts +1 -1
- package/lib/mjs/NumberUtils.js +9 -9
- package/lib/mjs/StorageUtils.js +4 -4
- package/lib/mjs/Utils.d.ts +4 -4
- package/lib/mjs/Utils.js +61 -65
- package/lib/mjs/index.d.ts +22 -22
- package/lib/mjs/index.js +22 -22
- package/lib/mjs/storage/WindowStorage.d.ts +1 -1
- package/lib/mjs/storage/WindowStorage.js +2 -2
- package/lib/mjs/types/ContentDisposition.d.ts +2 -2
- package/lib/mjs/types/ContentDisposition.js +12 -14
- package/lib/mjs/types/EColor.js +5 -7
- package/lib/mjs/types/EHistory.d.ts +3 -3
- package/lib/mjs/types/EHistory.js +5 -5
- package/lib/mjs/types/ErrorData.d.ts +1 -1
- package/lib/mjs/types/EventClass.js +1 -1
- package/package.json +61 -63
- package/src/ActionResult.ts +23 -23
- package/src/ArrayUtils.ts +164 -172
- package/src/ColorUtils.ts +80 -82
- package/src/DataTypes.ts +745 -754
- package/src/DateUtils.ts +266 -268
- package/src/DomUtils.ts +806 -831
- package/src/ExtendUtils.ts +191 -191
- package/src/IActionResult.ts +42 -42
- package/src/Keyboard.ts +258 -258
- package/src/NumberUtils.ts +135 -135
- package/src/StorageUtils.ts +117 -117
- package/src/Utils.ts +908 -930
- package/src/index.ts +22 -22
- package/src/node/Storage.ts +53 -53
- package/src/storage/IStorage.ts +62 -62
- package/src/storage/WindowStorage.ts +140 -140
- package/src/types/ContentDisposition.ts +59 -63
- package/src/types/DataError.ts +15 -15
- package/src/types/DelayedExecutorType.ts +15 -15
- package/src/types/EColor.ts +241 -248
- package/src/types/EHistory.ts +151 -151
- package/src/types/ErrorData.ts +11 -11
- package/src/types/EventClass.ts +220 -220
- package/src/types/FormData.ts +25 -25
- package/src/types/ParsedPath.ts +5 -5
- package/tsconfig.cjs.json +16 -16
- package/tsconfig.json +16 -16
- package/.eslintignore +0 -3
- package/.eslintrc.json +0 -29
- package/.prettierignore +0 -5
- package/.prettierrc +0 -6
package/src/index.ts
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
8
|
-
export * from
|
|
1
|
+
export * from "./types/ContentDisposition";
|
|
2
|
+
export * from "./types/DataError";
|
|
3
|
+
export * from "./types/DelayedExecutorType";
|
|
4
|
+
export * from "./types/EColor";
|
|
5
|
+
export * from "./types/EHistory";
|
|
6
|
+
export * from "./types/ErrorData";
|
|
7
|
+
export * from "./types/EventClass";
|
|
8
|
+
export * from "./types/FormData";
|
|
9
9
|
|
|
10
|
-
export * from
|
|
11
|
-
export * from
|
|
10
|
+
export * from "./storage/IStorage";
|
|
11
|
+
export * from "./storage/WindowStorage";
|
|
12
12
|
|
|
13
|
-
export * from
|
|
14
|
-
export * from
|
|
15
|
-
export * from
|
|
16
|
-
export * from
|
|
17
|
-
export * from
|
|
18
|
-
export * from
|
|
19
|
-
export * from
|
|
20
|
-
export * from
|
|
21
|
-
export * from
|
|
22
|
-
export * from
|
|
23
|
-
export * from
|
|
24
|
-
export * from
|
|
13
|
+
export * from "./ActionResult";
|
|
14
|
+
export * from "./ArrayUtils";
|
|
15
|
+
export * from "./DataTypes";
|
|
16
|
+
export * from "./ColorUtils";
|
|
17
|
+
export * from "./DateUtils";
|
|
18
|
+
export * from "./DomUtils";
|
|
19
|
+
export * from "./ExtendUtils";
|
|
20
|
+
export * from "./IActionResult";
|
|
21
|
+
export * from "./Keyboard";
|
|
22
|
+
export * from "./NumberUtils";
|
|
23
|
+
export * from "./StorageUtils";
|
|
24
|
+
export * from "./Utils";
|
package/src/node/Storage.ts
CHANGED
|
@@ -3,65 +3,65 @@
|
|
|
3
3
|
* Please take care of the persistence with source property
|
|
4
4
|
*/
|
|
5
5
|
export class NodeStorage {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Storage source
|
|
8
|
+
*/
|
|
9
|
+
source: [string, string][] = [];
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Constructor
|
|
13
|
+
*/
|
|
14
|
+
constructor() {}
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Returns the number of key/value pairs currently present in the list
|
|
18
|
+
*/
|
|
19
|
+
get length(): number {
|
|
20
|
+
return this.source.length;
|
|
21
|
+
}
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Empties the list associated with the object of all key/value pairs, if there are any.
|
|
25
|
+
*/
|
|
26
|
+
clear(): void {
|
|
27
|
+
this.source = [];
|
|
28
|
+
}
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Returns the current value associated with the given key, or null if the given key does not exist in the list
|
|
32
|
+
* @param key Key
|
|
33
|
+
*/
|
|
34
|
+
getItem(key: string): string | null {
|
|
35
|
+
const item = this.source.find((p) => p[0] === key);
|
|
36
|
+
return item == null ? null : item[1];
|
|
37
|
+
}
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
39
|
+
/**
|
|
40
|
+
* Returns the name of the nth key in the list, or null if n is greater than or equal to the number of key/value pairs in the object.
|
|
41
|
+
*/
|
|
42
|
+
key(index: number): string | null {
|
|
43
|
+
if (index < 0 || index >= this.source.length) return null;
|
|
44
|
+
return this.source[index][0];
|
|
45
|
+
}
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
47
|
+
/**
|
|
48
|
+
* Removes the key/value pair with the given key from the list associated with the object, if a key/value pair with the given key exists.
|
|
49
|
+
*/
|
|
50
|
+
removeItem(key: string): void {
|
|
51
|
+
this.source.remove((p) => p[0] === key);
|
|
52
|
+
}
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
54
|
+
/**
|
|
55
|
+
* Sets the value of the pair identified by key to value, creating a new key/value pair if none existed for key previously.
|
|
56
|
+
*
|
|
57
|
+
* Throws a "QuotaExceededError" DOMException exception if the new value couldn't be set. (Setting could fail if, e.g., the user has disabled storage for the site, or if the quota has been exceeded.)
|
|
58
|
+
*/
|
|
59
|
+
setItem(key: string, value: string): void {
|
|
60
|
+
const item = this.source.find((p) => p[0] === key);
|
|
61
|
+
if (item) {
|
|
62
|
+
item[1] = value;
|
|
63
|
+
} else {
|
|
64
|
+
this.source.push([key, value]);
|
|
66
65
|
}
|
|
66
|
+
}
|
|
67
67
|
}
|
package/src/storage/IStorage.ts
CHANGED
|
@@ -2,76 +2,76 @@
|
|
|
2
2
|
* Storage interface
|
|
3
3
|
*/
|
|
4
4
|
export interface IStorage {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Clear keys
|
|
7
|
+
* @param keys Keys
|
|
8
|
+
* @param persisted Persisted or session data
|
|
9
|
+
*/
|
|
10
|
+
clear(keys: string[], persisted?: boolean): void;
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Copy keys to session from persisted source
|
|
14
|
+
* @param keys Keys
|
|
15
|
+
* @param removeSource Remove from the source
|
|
16
|
+
*/
|
|
17
|
+
copyFrom(keys: string[], removeSource?: boolean): void;
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Copy keys to persisted source
|
|
21
|
+
* @param keys Keys
|
|
22
|
+
* @param removeSource Remove from the source
|
|
23
|
+
*/
|
|
24
|
+
copyTo(keys: string[], removeSource?: boolean): void;
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
/**
|
|
27
|
+
* Get data
|
|
28
|
+
* @param key Key name
|
|
29
|
+
*/
|
|
30
|
+
getData<T>(key: string): T | undefined;
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Get data with default value
|
|
34
|
+
* @param key Key name
|
|
35
|
+
* @param defaultValue Default value
|
|
36
|
+
*/
|
|
37
|
+
getData<T>(key: string, defaultValue: T): T;
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
/**
|
|
40
|
+
* Get persisted data
|
|
41
|
+
* @param key Key name
|
|
42
|
+
*/
|
|
43
|
+
getPersistedData<T>(key: string): T | undefined;
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
45
|
+
/**
|
|
46
|
+
* Get persisted data with default value
|
|
47
|
+
* @param key Key name
|
|
48
|
+
* @param defaultValue Default value
|
|
49
|
+
*/
|
|
50
|
+
getPersistedData<T>(key: string, defaultValue: T): T;
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
52
|
+
/**
|
|
53
|
+
* Get object data
|
|
54
|
+
* @param key Key name
|
|
55
|
+
*/
|
|
56
|
+
getObject<T extends object>(key: string): T | undefined;
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
58
|
+
/**
|
|
59
|
+
* Get persisted object data
|
|
60
|
+
* @param key Key name
|
|
61
|
+
*/
|
|
62
|
+
getPersistedObject<T extends object>(key: string): T | undefined;
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
64
|
+
/**
|
|
65
|
+
* Set data
|
|
66
|
+
* @param key Key name
|
|
67
|
+
* @param data Data, null for removal
|
|
68
|
+
*/
|
|
69
|
+
setData(key: string, data: unknown): void;
|
|
70
70
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
71
|
+
/**
|
|
72
|
+
* Set persisted data
|
|
73
|
+
* @param key Key name
|
|
74
|
+
* @param data Data, null for removal
|
|
75
|
+
*/
|
|
76
|
+
setPersistedData(key: string, data: unknown): void;
|
|
77
77
|
}
|
|
@@ -1,147 +1,147 @@
|
|
|
1
|
-
import { StorageUtils } from
|
|
2
|
-
import { Utils } from
|
|
3
|
-
import { IStorage } from
|
|
1
|
+
import { StorageUtils } from "../StorageUtils";
|
|
2
|
+
import { Utils } from "../Utils";
|
|
3
|
+
import { IStorage } from "./IStorage";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Window storage
|
|
7
7
|
* https://developer.mozilla.org/en-US/docs/Web/API/Storage
|
|
8
8
|
*/
|
|
9
9
|
export class WindowStorage implements IStorage {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Clear keys
|
|
12
|
+
* @param keys Keys
|
|
13
|
+
* @param persisted Persisted or session data
|
|
14
|
+
*/
|
|
15
|
+
clear(keys: string[], persisted?: boolean) {
|
|
16
|
+
keys.forEach((key) => {
|
|
17
|
+
if (persisted) this.setPersistedData(key, undefined);
|
|
18
|
+
else this.setData(key, undefined);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Copy keys to session from persisted source
|
|
24
|
+
* @param keys Keys
|
|
25
|
+
* @param removeSource Remove from the source
|
|
26
|
+
*/
|
|
27
|
+
copyFrom(keys: string[], removeSource?: boolean) {
|
|
28
|
+
keys.forEach((key) => {
|
|
29
|
+
this.setData(key, this.getPersistedData(key));
|
|
30
|
+
if (removeSource) this.setPersistedData(key, undefined);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Copy keys to persisted source
|
|
36
|
+
* @param keys Keys
|
|
37
|
+
* @param removeSource Remove from the source
|
|
38
|
+
*/
|
|
39
|
+
copyTo(keys: string[], removeSource?: boolean) {
|
|
40
|
+
keys.forEach((key) => {
|
|
41
|
+
this.setPersistedData(key, this.getData(key));
|
|
42
|
+
if (removeSource) this.setData(key, undefined);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Get data
|
|
48
|
+
* @param key Key name
|
|
49
|
+
*/
|
|
50
|
+
getData<T>(key: string): T | undefined;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Get data with default value
|
|
54
|
+
* @param key Key name
|
|
55
|
+
* @param defaultValue Default value
|
|
56
|
+
*/
|
|
57
|
+
getData<T>(key: string, defaultValue: T): T;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Get data
|
|
61
|
+
* @param key Key name
|
|
62
|
+
* @param defaultValue Default value
|
|
63
|
+
*/
|
|
64
|
+
getData<T>(key: string, defaultValue?: T): T | undefined {
|
|
65
|
+
// Get storage
|
|
66
|
+
const data = sessionStorage.getItem(key);
|
|
67
|
+
|
|
68
|
+
// No default value
|
|
69
|
+
if (defaultValue == null) return Utils.parseString<T>(data);
|
|
70
|
+
|
|
71
|
+
// Return
|
|
72
|
+
return Utils.parseString<T>(data, defaultValue);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Get persisted data
|
|
77
|
+
* @param key Key name
|
|
78
|
+
*/
|
|
79
|
+
getPersistedData<T>(key: string): T | undefined;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Get persisted data with default value
|
|
83
|
+
* @param key Key name
|
|
84
|
+
* @param defaultValue Default value
|
|
85
|
+
*/
|
|
86
|
+
getPersistedData<T>(key: string, defaultValue: T): T;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Get persisted data
|
|
90
|
+
* @param key Key name
|
|
91
|
+
* @param defaultValue Default value
|
|
92
|
+
*/
|
|
93
|
+
getPersistedData<T>(key: string, defaultValue?: T): T | undefined {
|
|
94
|
+
// Get storage
|
|
95
|
+
const data = localStorage.getItem(key);
|
|
96
|
+
|
|
97
|
+
// No default value
|
|
98
|
+
if (defaultValue == null) return Utils.parseString<T>(data);
|
|
99
|
+
|
|
100
|
+
// Return
|
|
101
|
+
return Utils.parseString<T>(data, defaultValue);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Get object data
|
|
106
|
+
* @param key Key name
|
|
107
|
+
*/
|
|
108
|
+
getObject<T extends object>(key: string) {
|
|
109
|
+
// Get storage
|
|
110
|
+
const data = sessionStorage.getItem(key);
|
|
111
|
+
|
|
112
|
+
if (data == null) return undefined;
|
|
113
|
+
|
|
114
|
+
return <T>JSON.parse(data);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Get persisted object data
|
|
119
|
+
* @param key Key name
|
|
120
|
+
*/
|
|
121
|
+
getPersistedObject<T extends object>(key: string) {
|
|
122
|
+
// Get storage
|
|
123
|
+
const data = localStorage.getItem(key);
|
|
124
|
+
|
|
125
|
+
if (data == null) return undefined;
|
|
126
|
+
|
|
127
|
+
return <T>JSON.parse(data);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Set data
|
|
132
|
+
* @param key Key name
|
|
133
|
+
* @param data Data, null for removal
|
|
134
|
+
*/
|
|
135
|
+
setData(key: string, data: unknown) {
|
|
136
|
+
StorageUtils.setSessionData(key, data);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Set persisted data
|
|
141
|
+
* @param key Key name
|
|
142
|
+
* @param data Data, null for removal
|
|
143
|
+
*/
|
|
144
|
+
setPersistedData(key: string, data: unknown) {
|
|
145
|
+
StorageUtils.setLocalData(key, data);
|
|
146
|
+
}
|
|
147
147
|
}
|