@domql/utils 2.5.14 → 2.5.17
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/dist/cjs/function.js +19 -1
- package/dist/cjs/object.js +20 -22
- package/function.js +43 -1
- package/object.js +19 -22
- package/package.json +2 -2
package/dist/cjs/function.js
CHANGED
|
@@ -19,11 +19,29 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
var function_exports = {};
|
|
20
20
|
__export(function_exports, {
|
|
21
21
|
debounce: () => debounce,
|
|
22
|
+
debounceOnContext: () => debounceOnContext,
|
|
22
23
|
isStringFunction: () => isStringFunction,
|
|
23
24
|
memoize: () => memoize
|
|
24
25
|
});
|
|
25
26
|
module.exports = __toCommonJS(function_exports);
|
|
26
|
-
|
|
27
|
+
function debounce(func, wait, immediate) {
|
|
28
|
+
let timeout;
|
|
29
|
+
return function() {
|
|
30
|
+
const context = this;
|
|
31
|
+
const args = arguments;
|
|
32
|
+
const later = function() {
|
|
33
|
+
timeout = null;
|
|
34
|
+
if (!immediate)
|
|
35
|
+
func.apply(context, args);
|
|
36
|
+
};
|
|
37
|
+
const callNow = immediate && !timeout;
|
|
38
|
+
clearTimeout(timeout);
|
|
39
|
+
timeout = setTimeout(later, wait);
|
|
40
|
+
if (callNow)
|
|
41
|
+
func.apply(context, args);
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
const debounceOnContext = (element, func, timeout = 300) => {
|
|
27
45
|
let timer;
|
|
28
46
|
return (...args) => {
|
|
29
47
|
clearTimeout(timer);
|
package/dist/cjs/object.js
CHANGED
|
@@ -84,7 +84,7 @@ const deepMerge = (element, extend, excludeFrom = []) => {
|
|
|
84
84
|
const elementProp = element[e];
|
|
85
85
|
const extendProp = extend[e];
|
|
86
86
|
if ((0, import_types.isObjectLike)(elementProp) && (0, import_types.isObjectLike)(extendProp)) {
|
|
87
|
-
deepMerge(elementProp, extendProp);
|
|
87
|
+
deepMerge(elementProp, extendProp, excludeFrom);
|
|
88
88
|
} else if (elementProp === void 0) {
|
|
89
89
|
element[e] = extendProp;
|
|
90
90
|
}
|
|
@@ -174,8 +174,8 @@ const objectToString = (obj, indent = 0) => {
|
|
|
174
174
|
const spaces = " ".repeat(indent);
|
|
175
175
|
let str = "{\n";
|
|
176
176
|
for (const [key, value] of Object.entries(obj)) {
|
|
177
|
-
const
|
|
178
|
-
const stringedKey =
|
|
177
|
+
const keyNotAllowdChars = (0, import_string.stringIncludesAny)(key, ["-", ":", "@", ".", "/", "!"]);
|
|
178
|
+
const stringedKey = keyNotAllowdChars ? `'${key}'` : key;
|
|
179
179
|
str += `${spaces} ${stringedKey}: `;
|
|
180
180
|
if ((0, import_types.isArray)(value)) {
|
|
181
181
|
str += "[\n";
|
|
@@ -230,7 +230,7 @@ const detachFunctionsFromObject = (obj, detached = {}) => {
|
|
|
230
230
|
}
|
|
231
231
|
return detached;
|
|
232
232
|
};
|
|
233
|
-
const deepDestringify = (obj,
|
|
233
|
+
const deepDestringify = (obj, destringified = {}) => {
|
|
234
234
|
for (const prop in obj) {
|
|
235
235
|
const hasOwnProperty = Object.prototype.hasOwnProperty.call(obj, prop);
|
|
236
236
|
if (!hasOwnProperty)
|
|
@@ -240,52 +240,50 @@ const deepDestringify = (obj, stringified = {}) => {
|
|
|
240
240
|
if (objProp.includes("=>") || objProp.includes("function") || objProp.startsWith("(")) {
|
|
241
241
|
try {
|
|
242
242
|
const evalProp = import_globals.window.eval(`(${objProp})`);
|
|
243
|
-
|
|
243
|
+
destringified[prop] = evalProp;
|
|
244
244
|
} catch (e) {
|
|
245
245
|
if (e)
|
|
246
|
-
|
|
246
|
+
destringified[prop] = objProp;
|
|
247
247
|
}
|
|
248
248
|
} else {
|
|
249
|
-
|
|
249
|
+
destringified[prop] = objProp;
|
|
250
250
|
}
|
|
251
251
|
} else if ((0, import_types.isArray)(objProp)) {
|
|
252
|
-
|
|
252
|
+
destringified[prop] = [];
|
|
253
253
|
objProp.forEach((arrProp) => {
|
|
254
254
|
if ((0, import_types.isString)(arrProp)) {
|
|
255
255
|
if (arrProp.includes("=>") || arrProp.includes("function") || arrProp.startsWith("(")) {
|
|
256
256
|
try {
|
|
257
257
|
const evalProp = import_globals.window.eval(`(${arrProp})`);
|
|
258
|
-
|
|
258
|
+
destringified[prop].push(evalProp);
|
|
259
259
|
} catch (e) {
|
|
260
260
|
if (e)
|
|
261
|
-
|
|
261
|
+
destringified[prop].push(arrProp);
|
|
262
262
|
}
|
|
263
263
|
} else {
|
|
264
|
-
|
|
264
|
+
destringified[prop].push(arrProp);
|
|
265
265
|
}
|
|
266
266
|
} else if ((0, import_types.isObject)(arrProp)) {
|
|
267
|
-
|
|
267
|
+
destringified[prop].push(deepDestringify(arrProp));
|
|
268
268
|
} else {
|
|
269
|
-
|
|
269
|
+
destringified[prop].push(arrProp);
|
|
270
270
|
}
|
|
271
271
|
});
|
|
272
272
|
} else if ((0, import_types.isObject)(objProp)) {
|
|
273
|
-
|
|
273
|
+
destringified[prop] = deepDestringify(objProp, destringified[prop]);
|
|
274
274
|
} else {
|
|
275
|
-
|
|
275
|
+
destringified[prop] = objProp;
|
|
276
276
|
}
|
|
277
277
|
}
|
|
278
|
-
return
|
|
278
|
+
return destringified;
|
|
279
279
|
};
|
|
280
|
-
const stringToObject = (str) => {
|
|
281
|
-
let obj;
|
|
280
|
+
const stringToObject = (str, verbose) => {
|
|
282
281
|
try {
|
|
283
|
-
|
|
282
|
+
return import_globals.window.eval("(" + str + ")");
|
|
284
283
|
} catch (e) {
|
|
285
|
-
|
|
284
|
+
if (verbose)
|
|
285
|
+
console.warn(e);
|
|
286
286
|
}
|
|
287
|
-
if (obj)
|
|
288
|
-
return obj;
|
|
289
287
|
};
|
|
290
288
|
const diffObjects = (original, objToDiff, cache) => {
|
|
291
289
|
for (const e in objToDiff) {
|
package/function.js
CHANGED
|
@@ -1,6 +1,48 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Debounces a function, ensuring that it is only executed after a specified timeout
|
|
5
|
+
* period has elapsed since the last invocation.
|
|
6
|
+
*
|
|
7
|
+
* @param {function} func - The function to be debounced.
|
|
8
|
+
* @param {number} [timeout=300] - The time (in milliseconds) to wait after the last call to
|
|
9
|
+
* `debounce` before executing the `func`.
|
|
10
|
+
* @returns {function} - A debounced version of the input function `func`.
|
|
11
|
+
* @example
|
|
12
|
+
* // Usage example:
|
|
13
|
+
* const debouncedFunction = debounce(this, myFunction, 500);
|
|
14
|
+
* window.addEventListener('resize', debouncedFunction);
|
|
15
|
+
*/
|
|
16
|
+
export function debounce (func, wait, immediate) {
|
|
17
|
+
let timeout
|
|
18
|
+
return function () {
|
|
19
|
+
const context = this; const args = arguments
|
|
20
|
+
const later = function () {
|
|
21
|
+
timeout = null
|
|
22
|
+
if (!immediate) func.apply(context, args)
|
|
23
|
+
}
|
|
24
|
+
const callNow = immediate && !timeout
|
|
25
|
+
clearTimeout(timeout)
|
|
26
|
+
timeout = setTimeout(later, wait)
|
|
27
|
+
if (callNow) func.apply(context, args)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Debounces a function, ensuring that it is only executed after a specified timeout
|
|
33
|
+
* period has elapsed since the last invocation.
|
|
34
|
+
*
|
|
35
|
+
* @param {Object} element - The context (this) to which the debounced function will be applied.
|
|
36
|
+
* @param {function} func - The function to be debounced.
|
|
37
|
+
* @param {number} [timeout=300] - The time (in milliseconds) to wait after the last call to
|
|
38
|
+
* `debounce` before executing the `func`.
|
|
39
|
+
* @returns {function} - A debounced version of the input function `func`.
|
|
40
|
+
* @example
|
|
41
|
+
* // Usage example:
|
|
42
|
+
* const debouncedFunction = debounce(this, myFunction, 500);
|
|
43
|
+
* window.addEventListener('resize', debouncedFunction);
|
|
44
|
+
*/
|
|
45
|
+
export const debounceOnContext = (element, func, timeout = 300) => {
|
|
4
46
|
let timer
|
|
5
47
|
return (...args) => {
|
|
6
48
|
clearTimeout(timer)
|
package/object.js
CHANGED
|
@@ -42,7 +42,7 @@ export const deepMerge = (element, extend, excludeFrom = []) => {
|
|
|
42
42
|
const elementProp = element[e]
|
|
43
43
|
const extendProp = extend[e]
|
|
44
44
|
if (isObjectLike(elementProp) && isObjectLike(extendProp)) {
|
|
45
|
-
deepMerge(elementProp, extendProp)
|
|
45
|
+
deepMerge(elementProp, extendProp, excludeFrom)
|
|
46
46
|
} else if (elementProp === undefined) {
|
|
47
47
|
element[e] = extendProp
|
|
48
48
|
}
|
|
@@ -146,8 +146,8 @@ export const objectToString = (obj, indent = 0) => {
|
|
|
146
146
|
let str = '{\n'
|
|
147
147
|
|
|
148
148
|
for (const [key, value] of Object.entries(obj)) {
|
|
149
|
-
const
|
|
150
|
-
const stringedKey =
|
|
149
|
+
const keyNotAllowdChars = stringIncludesAny(key, ['-', ':', '@', '.', '/', '!'])
|
|
150
|
+
const stringedKey = keyNotAllowdChars ? `'${key}'` : key
|
|
151
151
|
str += `${spaces} ${stringedKey}: `
|
|
152
152
|
|
|
153
153
|
if (isArray(value)) {
|
|
@@ -208,7 +208,7 @@ export const detachFunctionsFromObject = (obj, detached = {}) => {
|
|
|
208
208
|
/**
|
|
209
209
|
* Detringify object
|
|
210
210
|
*/
|
|
211
|
-
export const deepDestringify = (obj,
|
|
211
|
+
export const deepDestringify = (obj, destringified = {}) => {
|
|
212
212
|
for (const prop in obj) {
|
|
213
213
|
const hasOwnProperty = Object.prototype.hasOwnProperty.call(obj, prop)
|
|
214
214
|
if (!hasOwnProperty) continue
|
|
@@ -217,45 +217,42 @@ export const deepDestringify = (obj, stringified = {}) => {
|
|
|
217
217
|
if (objProp.includes('=>') || objProp.includes('function') || objProp.startsWith('(')) {
|
|
218
218
|
try {
|
|
219
219
|
const evalProp = window.eval(`(${objProp})`) // use parentheses to convert string to function expression
|
|
220
|
-
|
|
221
|
-
} catch (e) { if (e)
|
|
220
|
+
destringified[prop] = evalProp
|
|
221
|
+
} catch (e) { if (e) destringified[prop] = objProp }
|
|
222
222
|
} else {
|
|
223
|
-
|
|
223
|
+
destringified[prop] = objProp
|
|
224
224
|
}
|
|
225
225
|
} else if (isArray(objProp)) {
|
|
226
|
-
|
|
226
|
+
destringified[prop] = []
|
|
227
227
|
objProp.forEach((arrProp) => {
|
|
228
228
|
if (isString(arrProp)) {
|
|
229
229
|
if (arrProp.includes('=>') || arrProp.includes('function') || arrProp.startsWith('(')) {
|
|
230
230
|
try {
|
|
231
231
|
const evalProp = window.eval(`(${arrProp})`) // use parentheses to convert string to function expression
|
|
232
|
-
|
|
233
|
-
} catch (e) { if (e)
|
|
232
|
+
destringified[prop].push(evalProp)
|
|
233
|
+
} catch (e) { if (e) destringified[prop].push(arrProp) }
|
|
234
234
|
} else {
|
|
235
|
-
|
|
235
|
+
destringified[prop].push(arrProp)
|
|
236
236
|
}
|
|
237
237
|
} else if (isObject(arrProp)) {
|
|
238
|
-
|
|
238
|
+
destringified[prop].push(deepDestringify(arrProp))
|
|
239
239
|
} else {
|
|
240
|
-
|
|
240
|
+
destringified[prop].push(arrProp)
|
|
241
241
|
}
|
|
242
242
|
})
|
|
243
243
|
} else if (isObject(objProp)) {
|
|
244
|
-
|
|
244
|
+
destringified[prop] = deepDestringify(objProp, destringified[prop]) // recursively call deepDestringify for nested objects
|
|
245
245
|
} else {
|
|
246
|
-
|
|
246
|
+
destringified[prop] = objProp
|
|
247
247
|
}
|
|
248
248
|
}
|
|
249
|
-
return
|
|
249
|
+
return destringified
|
|
250
250
|
}
|
|
251
251
|
|
|
252
|
-
export const stringToObject = (str) => {
|
|
253
|
-
let obj
|
|
252
|
+
export const stringToObject = (str, verbose) => {
|
|
254
253
|
try {
|
|
255
|
-
|
|
256
|
-
} catch (e) { console.warn(e) }
|
|
257
|
-
|
|
258
|
-
if (obj) return obj
|
|
254
|
+
return window.eval('(' + str + ')') // eslint-disable-line
|
|
255
|
+
} catch (e) { if (verbose) console.warn(e) }
|
|
259
256
|
}
|
|
260
257
|
|
|
261
258
|
export const diffObjects = (original, objToDiff, cache) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domql/utils",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.17",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "index.js",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"build": "yarn build:cjs",
|
|
24
24
|
"prepublish": "rimraf -I dist && yarn build && yarn copy:package:cjs"
|
|
25
25
|
},
|
|
26
|
-
"gitHead": "
|
|
26
|
+
"gitHead": "b08d17a7f2bf1a70714ab9f1718cbf98862becf0",
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@babel/core": "^7.12.0"
|
|
29
29
|
}
|