web-manager 3.2.47 → 3.2.49

Sign up to get free protection for your applications and to get access to all the features.
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, options) {
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
- return utilities.get(JSON.parse(window.localStorage.getItem('_manager')) || {}, path, def);
23
+ usableStorage = JSON.parse(window.localStorage.getItem('_manager') || '{}');
16
24
  } catch (e) {
17
- return utilities.get(pseudoStorage, path, def)
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, options) {
22
- var existing;
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
- existing = Storage.get('', {});
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
- utilities.set(pseudoStorage, path, value)
64
+ pseudoStorage = usableStorage;
30
65
  }
31
66
 
32
- return existing;
67
+ return usableStorage;
33
68
  }
34
69
 
35
- Storage.clear = function(options) {
70
+ Storage.clear = function () {
36
71
  try {
37
72
  window.localStorage.setItem('_manager', '{}');
38
73
  } catch (e) {
package/lib/utilities.js CHANGED
@@ -19,7 +19,7 @@ Utilities.get = function (object, path, defaultValue) {
19
19
  // For each item in the path, dig into the object
20
20
  let currentObject = object;
21
21
  for (const key of pathArray) {
22
- if (!currentObject || !currentObject.hasOwnProperty(key)) {
22
+ if (!currentObject || currentObject[key] === undefined) {
23
23
  return defaultValue;
24
24
  }
25
25
  currentObject = currentObject[key];
@@ -52,26 +52,26 @@ Utilities.set = function (obj, path, value) {
52
52
  }
53
53
 
54
54
  /* https://gist.github.com/jeneg/9767afdcca45601ea44930ea03e0febf */
55
- Utilities.getLegacy = function (obj, path, def) {
56
- if (!path) {
57
- return def;
58
- }
59
- var fullPath = (path || '')
60
- .replace(/\[/g, '.')
61
- .replace(/]/g, '')
62
- .split('.')
63
- .filter(Boolean);
64
-
65
- return fullPath.every(everyFunc) ? obj : def;
66
-
67
- function everyFunc(step) {
68
- // return !(step && (obj = obj[step]) === undefined);
69
- // console.log(' CHECK > ', !(step && (obj = obj[step]) === undefined));
70
- // console.log('step', step, 'obj', obj, 'objstep', obj[step]);
71
- // return !(step && (obj = obj[step]) === undefined);
72
- return !(step && (obj = obj[step]) === undefined);
73
- }
74
- }
55
+ // Utilities.getLegacy = function (obj, path, def) {
56
+ // if (!path) {
57
+ // return def;
58
+ // }
59
+ // var fullPath = (path || '')
60
+ // .replace(/\[/g, '.')
61
+ // .replace(/]/g, '')
62
+ // .split('.')
63
+ // .filter(Boolean);
64
+
65
+ // return fullPath.every(everyFunc) ? obj : def;
66
+
67
+ // function everyFunc(step) {
68
+ // // return !(step && (obj = obj[step]) === undefined);
69
+ // // console.log(' CHECK > ', !(step && (obj = obj[step]) === undefined));
70
+ // // console.log('step', step, 'obj', obj, 'objstep', obj[step]);
71
+ // // return !(step && (obj = obj[step]) === undefined);
72
+ // return !(step && (obj = obj[step]) === undefined);
73
+ // }
74
+ // }
75
75
 
76
76
  // https://dzone.com/articles/cross-browser-javascript-copy-and-paste
77
77
  // https://hackernoon.com/copying-text-to-clipboard-with-javascript-df4d4988697f
package/package.json CHANGED
@@ -1,11 +1,10 @@
1
1
  {
2
2
  "name": "web-manager",
3
- "version": "3.2.47",
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": {
7
7
  "test": "./node_modules/mocha/bin/mocha test/ --recursive --timeout=10000",
8
-
9
8
  "test_": "npm run prepare && ./node_modules/mocha/bin/mocha test/ --recursive --timeout=10000",
10
9
  "prepare_": "node -e 'require(`prepare-package`)()'"
11
10
  },
@@ -34,7 +33,7 @@
34
33
  }
35
34
  },
36
35
  "dependencies": {
37
- "@sentry/browser": "^7.108.0",
36
+ "@sentry/browser": "^7.112.2",
38
37
  "cookieconsent": "^3.1.1",
39
38
  "firebase": "^9.23.0",
40
39
  "lazysizes": "^5.3.2"