web-manager 3.2.46 → 3.2.48

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/lib/debug.js CHANGED
@@ -8,7 +8,7 @@ function Debug(utilObj) {
8
8
  Debug.promise = function(status, data, options) {
9
9
  options = options || {};
10
10
  options.wait = options.wait || {enabled: false};
11
- return new Promise((resolve, reject) => {
11
+ return new Promise(function (resolve, reject) {
12
12
  if (status == 'resolve') {
13
13
  if (options.wait.enabled) {
14
14
  Debug.wait(options.wait.msec, options.wait.range)
@@ -48,7 +48,9 @@ Debug.wait = function(msec, range) {
48
48
  msec = msec + randomNumPlus - randomNumMinus;
49
49
  msec = (msec <= 0) ? 50 : msec;
50
50
  console.log('[DEBUG] waiting...', msec);
51
- return new Promise(resolve => setTimeout(resolve, msec));
51
+ return new Promise(function (resolve, reject) {
52
+ setTimeout(resolve, msec);
53
+ });
52
54
  }
53
55
 
54
56
  module.exports = Debug;
package/lib/dom.js CHANGED
@@ -275,7 +275,7 @@ Dom.loadScript = function(options, callback) {
275
275
 
276
276
  // Set the script attributes
277
277
  options.attributes
278
- .forEach(attribute => {
278
+ .forEach(function (attribute) {
279
279
  s.setAttribute(attribute.name, attribute.value);
280
280
  });
281
281
 
package/lib/utilities.js CHANGED
@@ -7,23 +7,26 @@ function Utilities(utilObj) {
7
7
  this.utilities = utilObj;
8
8
  }
9
9
 
10
- /* https://gist.github.com/jeneg/9767afdcca45601ea44930ea03e0febf */
11
- Utilities.get = function (obj, path, def) {
12
- var fullPath = (path || '')
13
- .replace(/\[/g, '.')
14
- .replace(/]/g, '')
15
- .split('.')
16
- .filter(Boolean);
17
-
18
- return fullPath.every(everyFunc) ? obj : def;
19
-
20
- function everyFunc(step) {
21
- // return !(step && (obj = obj[step]) === undefined);
22
- // console.log(' CHECK > ', !(step && (obj = obj[step]) === undefined));
23
- // console.log('step', step, 'obj', obj, 'objstep', obj[step]);
24
- // return !(step && (obj = obj[step]) === undefined);
25
- return !(step && (obj = obj[step]) === undefined);
10
+ Utilities.get = function (object, path, defaultValue) {
11
+ // If the path is not defined or it has false value
12
+ if (!path) {
13
+ return defaultValue;
14
+ }
15
+
16
+ // Check if the path is a string or array. If it is a string, convert it to array
17
+ const pathArray = Array.isArray(path) ? path : path.split('.');
18
+
19
+ // For each item in the path, dig into the object
20
+ let currentObject = object;
21
+ for (const key of pathArray) {
22
+ if (!currentObject || currentObject[key] === undefined) {
23
+ return defaultValue;
24
+ }
25
+ currentObject = currentObject[key];
26
26
  }
27
+
28
+ // Return the value
29
+ return currentObject === undefined ? defaultValue : currentObject;
27
30
  }
28
31
 
29
32
  /* https://stackoverflow.com/questions/54733539/javascript-implementation-of-lodash-set-method */
@@ -48,6 +51,28 @@ Utilities.set = function (obj, path, value) {
48
51
  return obj; // Return the top-level object to allow chaining
49
52
  }
50
53
 
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
+ // }
75
+
51
76
  // https://dzone.com/articles/cross-browser-javascript-copy-and-paste
52
77
  // https://hackernoon.com/copying-text-to-clipboard-with-javascript-df4d4988697f
53
78
  Utilities.clipboardCopy = function (input) {
package/package.json CHANGED
@@ -1,10 +1,12 @@
1
1
  {
2
2
  "name": "web-manager",
3
- "version": "3.2.46",
3
+ "version": "3.2.48",
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
- "test": "echo \"Error: no test specified\" && exit 1"
7
+ "test": "./node_modules/mocha/bin/mocha test/ --recursive --timeout=10000",
8
+ "test_": "npm run prepare && ./node_modules/mocha/bin/mocha test/ --recursive --timeout=10000",
9
+ "prepare_": "node -e 'require(`prepare-package`)()'"
8
10
  },
9
11
  "engines": {
10
12
  "node": ">=6.0.0"
@@ -31,9 +33,13 @@
31
33
  }
32
34
  },
33
35
  "dependencies": {
34
- "@sentry/browser": "^7.108.0",
36
+ "@sentry/browser": "^7.110.1",
35
37
  "cookieconsent": "^3.1.1",
36
38
  "firebase": "^9.23.0",
37
39
  "lazysizes": "^5.3.2"
40
+ },
41
+ "devDependencies": {
42
+ "lodash": "^4.17.21",
43
+ "mocha": "^8.4.0"
38
44
  }
39
45
  }
package/test/test.js ADDED
@@ -0,0 +1,158 @@
1
+ const package = require('../package.json');
2
+ const assert = require('assert');
3
+
4
+ beforeEach(() => {
5
+ });
6
+
7
+ before(() => {
8
+ });
9
+
10
+ after(() => {
11
+ });
12
+
13
+ /*
14
+ * ============
15
+ * Test Cases
16
+ * ============
17
+ */
18
+ describe(`${package.name}`, () => {
19
+ const _ = require('../lib/utilities.js');
20
+ const lodash = require('lodash');
21
+
22
+ // Utilities
23
+ describe('.utilities()', () => {
24
+ const sample = {
25
+ main: {
26
+ true: true,
27
+ false: false,
28
+ zero: 0,
29
+ one: 1,
30
+ string: 'string',
31
+ stringEmpty: '',
32
+ object: {},
33
+ array: [],
34
+ null: null,
35
+ undefined: undefined,
36
+ nan: NaN,
37
+ infinity: Infinity,
38
+ negativeInfinity: -Infinity,
39
+ function: function () {},
40
+ }
41
+ }
42
+
43
+ // Normal Cases
44
+ describe('.get()', () => {
45
+ it('should return true', () => {
46
+ // console.log('---lodash', lodash.get(sample, 'main.true'));
47
+ // console.log('---_.get', _.get(sample, 'main.true'));
48
+ // console.log('---_.get2', _.get2(sample, 'main.true'));
49
+
50
+ assert.strictEqual(_.get(sample, 'main.true'), true);
51
+ });
52
+
53
+ it('should return false', () => {
54
+ assert.strictEqual(_.get(sample, 'main.false'), false);
55
+ });
56
+
57
+ it('should return 0', () => {
58
+ assert.strictEqual(_.get(sample, 'main.zero'), 0);
59
+ });
60
+
61
+ it('should return 1', () => {
62
+ assert.strictEqual(_.get(sample, 'main.one'), 1);
63
+ });
64
+
65
+ it('should return a string', () => {
66
+ assert.strictEqual(_.get(sample, 'main.string'), 'string');
67
+ });
68
+
69
+ it('should return an empty string', () => {
70
+ assert.strictEqual(_.get(sample, 'main.stringEmpty'), '');
71
+ });
72
+
73
+ it('should return an object', () => {
74
+ assert.deepStrictEqual(_.get(sample, 'main.object'), {});
75
+ });
76
+
77
+ it('should return an array', () => {
78
+ assert.deepStrictEqual(_.get(sample, 'main.array'), []);
79
+ });
80
+
81
+ it('should return null', () => {
82
+ assert.strictEqual(_.get(sample, 'main.null'), null);
83
+ });
84
+
85
+ it('should return undefined', () => {
86
+ assert.strictEqual(_.get(sample, 'main.undefined'), undefined);
87
+ });
88
+
89
+ it('should return NaN', () => {
90
+ assert.strictEqual(Number.isNaN(_.get(sample, 'main.nan')), true);
91
+ });
92
+
93
+ it('should return Infinity', () => {
94
+ assert.strictEqual(_.get(sample, 'main.infinity'), Infinity);
95
+ });
96
+
97
+ it('should return -Infinity', () => {
98
+ assert.strictEqual(_.get(sample, 'main.negativeInfinity'), -Infinity);
99
+ });
100
+
101
+ it('should return a function', () => {
102
+ assert.strictEqual(typeof _.get(sample, 'main.function'), 'function');
103
+ });
104
+
105
+ // Non-existent
106
+ it('should return undefined', () => {
107
+ assert.strictEqual(_.get(sample, 'main.nonexistent'), undefined);
108
+ });
109
+
110
+ // No path
111
+ it('should return undefined', () => {
112
+ assert.strictEqual(_.get(sample), undefined);
113
+ });
114
+
115
+ // Empty path
116
+ it('should return undefined', () => {
117
+ assert.strictEqual(_.get(sample, ''), undefined);
118
+ });
119
+
120
+ // Default value
121
+ it('should return default value', () => {
122
+ assert.strictEqual(_.get(sample, 'main.nonexistent', 'default'), 'default');
123
+ });
124
+
125
+ it('should return actual value', () => {
126
+ assert.strictEqual(_.get(sample, 'main.false', 'default'), false);
127
+ });
128
+
129
+ it('should return actual value', () => {
130
+ assert.strictEqual(_.get(sample, 'main.null', 'default'), null);
131
+ });
132
+
133
+ it('should return default value', () => {
134
+ assert.strictEqual(_.get(sample, 'main.undefined', 'default'), 'default');
135
+ });
136
+
137
+ // Non-object for object
138
+ it('should return undefined', () => {
139
+ assert.strictEqual(_.get(undefined, 'main.true'), undefined);
140
+ });
141
+
142
+ it('should return undefined', () => {
143
+ assert.strictEqual(_.get(null, 'main.true'), undefined);
144
+ });
145
+
146
+ it('should return undefined', () => {
147
+ assert.strictEqual(_.get(false, 'main.true'), undefined);
148
+ });
149
+
150
+ it('should return undefined', () => {
151
+ assert.strictEqual(_.get('', 'main.true'), undefined);
152
+ });
153
+
154
+ });
155
+
156
+ });
157
+
158
+ })