web-manager 3.2.48 → 3.2.49
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/storage.js +47 -12
- package/package.json +2 -2
package/lib/storage.js
CHANGED
@@ -1,38 +1,73 @@
|
|
1
1
|
/*
|
2
2
|
*/
|
3
3
|
var utilities = require('./utilities.js');
|
4
|
-
var support;
|
5
4
|
var pseudoStorage = {};
|
6
5
|
|
7
6
|
function Storage(storageObj) {
|
8
7
|
this.storage = storageObj;
|
9
8
|
}
|
10
9
|
|
11
|
-
Storage.get = function(path, def
|
10
|
+
Storage.get = function (path, def) {
|
11
|
+
// Setup the usable storage object
|
12
|
+
var usableStorage;
|
13
|
+
|
14
|
+
// Setup the path and default value
|
12
15
|
path = path || '';
|
16
|
+
// def = typeof def === 'undefined' ? {} : def;
|
17
|
+
// Important that defaults to undefined
|
18
|
+
// Because if default is empty obj, then a path to an undefined value like 'a.b.c' (assuming c is undefined) will return empty obj instead of undefined
|
19
|
+
def = typeof def === 'undefined' ? undefined : def;
|
13
20
|
|
21
|
+
// Try to parse the localStorage object
|
14
22
|
try {
|
15
|
-
|
23
|
+
usableStorage = JSON.parse(window.localStorage.getItem('_manager') || '{}');
|
16
24
|
} catch (e) {
|
17
|
-
|
25
|
+
usableStorage = pseudoStorage;
|
26
|
+
}
|
27
|
+
|
28
|
+
// If there's no path, return the entire storage object
|
29
|
+
if (!path) {
|
30
|
+
return usableStorage || def;
|
18
31
|
}
|
32
|
+
|
33
|
+
// Return the value at the path
|
34
|
+
return utilities.get(usableStorage, path, def);
|
19
35
|
}
|
20
36
|
|
21
|
-
Storage.set = function(path, value
|
22
|
-
|
37
|
+
Storage.set = function (path, value) {
|
38
|
+
// Setup the usable storage object
|
39
|
+
var usableStorage;
|
40
|
+
|
41
|
+
// Setup the path and default value
|
42
|
+
path = path || '';
|
43
|
+
value = typeof value === 'undefined' ? undefined : value;
|
44
|
+
|
45
|
+
// Try to parse the localStorage object
|
46
|
+
try {
|
47
|
+
usableStorage = Storage.get();
|
48
|
+
} catch (e) {
|
49
|
+
usableStorage = pseudoStorage;
|
50
|
+
}
|
51
|
+
|
52
|
+
// If there's no path, return the entire storage object
|
53
|
+
if (!path) {
|
54
|
+
usableStorage = value || {};
|
55
|
+
} else {
|
56
|
+
// Set the value at the path
|
57
|
+
utilities.set(usableStorage, path, value);
|
58
|
+
}
|
23
59
|
|
60
|
+
// Try to set the localStorage object
|
24
61
|
try {
|
25
|
-
|
26
|
-
utilities.set(existing, path, value);
|
27
|
-
window.localStorage.setItem('_manager', JSON.stringify(existing));
|
62
|
+
window.localStorage.setItem('_manager', JSON.stringify(usableStorage));
|
28
63
|
} catch (e) {
|
29
|
-
|
64
|
+
pseudoStorage = usableStorage;
|
30
65
|
}
|
31
66
|
|
32
|
-
return
|
67
|
+
return usableStorage;
|
33
68
|
}
|
34
69
|
|
35
|
-
Storage.clear = function(
|
70
|
+
Storage.clear = function () {
|
36
71
|
try {
|
37
72
|
window.localStorage.setItem('_manager', '{}');
|
38
73
|
} catch (e) {
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "web-manager",
|
3
|
-
"version": "3.2.
|
3
|
+
"version": "3.2.49",
|
4
4
|
"description": "Easily access important variables such as the query string, current domain, and current page in a single object.",
|
5
5
|
"main": "index.js",
|
6
6
|
"scripts": {
|
@@ -33,7 +33,7 @@
|
|
33
33
|
}
|
34
34
|
},
|
35
35
|
"dependencies": {
|
36
|
-
"@sentry/browser": "^7.
|
36
|
+
"@sentry/browser": "^7.112.2",
|
37
37
|
"cookieconsent": "^3.1.1",
|
38
38
|
"firebase": "^9.23.0",
|
39
39
|
"lazysizes": "^5.3.2"
|