@domql/utils 2.5.22 → 2.5.24
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/object.js +49 -14
- package/dist/cjs/types.js +4 -1
- package/object.js +45 -3
- package/package.json +2 -5
- package/types.js +4 -0
package/dist/cjs/object.js
CHANGED
|
@@ -32,7 +32,11 @@ __export(object_exports, {
|
|
|
32
32
|
diffObjects: () => diffObjects,
|
|
33
33
|
exec: () => exec,
|
|
34
34
|
flattenRecursive: () => flattenRecursive,
|
|
35
|
+
hasOwnProperty: () => hasOwnProperty,
|
|
36
|
+
isEmpty: () => isEmpty,
|
|
37
|
+
isEmptyObject: () => isEmptyObject,
|
|
35
38
|
isEqualDeep: () => isEqualDeep,
|
|
39
|
+
makeObjectWithoutPrototype: () => makeObjectWithoutPrototype,
|
|
36
40
|
map: () => map,
|
|
37
41
|
merge: () => merge,
|
|
38
42
|
mergeArrayExclude: () => mergeArrayExclude,
|
|
@@ -49,7 +53,6 @@ var import_globals = require("./globals.js");
|
|
|
49
53
|
var import_types = require("./types.js");
|
|
50
54
|
var import_array = require("./array.js");
|
|
51
55
|
var import_string = require("./string.js");
|
|
52
|
-
var import_deep_object_diff = require("deep-object-diff");
|
|
53
56
|
const exec = (param, element, state, context) => {
|
|
54
57
|
if ((0, import_types.isFunction)(param)) {
|
|
55
58
|
return param(
|
|
@@ -67,8 +70,8 @@ const map = (obj, extention, element) => {
|
|
|
67
70
|
};
|
|
68
71
|
const merge = (element, obj, excludeFrom = []) => {
|
|
69
72
|
for (const e in obj) {
|
|
70
|
-
const
|
|
71
|
-
if (!
|
|
73
|
+
const hasOwnProperty2 = Object.prototype.hasOwnProperty.call(obj, e);
|
|
74
|
+
if (!hasOwnProperty2 || excludeFrom.includes(e) || e.startsWith("__"))
|
|
72
75
|
continue;
|
|
73
76
|
const elementProp = element[e];
|
|
74
77
|
const objProp = obj[e];
|
|
@@ -80,8 +83,8 @@ const merge = (element, obj, excludeFrom = []) => {
|
|
|
80
83
|
};
|
|
81
84
|
const deepMerge = (element, extend, excludeFrom = []) => {
|
|
82
85
|
for (const e in extend) {
|
|
83
|
-
const
|
|
84
|
-
if (!
|
|
86
|
+
const hasOwnProperty2 = Object.prototype.hasOwnProperty.call(extend, e);
|
|
87
|
+
if (!hasOwnProperty2 || excludeFrom.includes(e) || e.startsWith("__"))
|
|
85
88
|
continue;
|
|
86
89
|
const elementProp = element[e];
|
|
87
90
|
const extendProp = extend[e];
|
|
@@ -96,8 +99,8 @@ const deepMerge = (element, extend, excludeFrom = []) => {
|
|
|
96
99
|
const clone = (obj, excludeFrom = []) => {
|
|
97
100
|
const o = {};
|
|
98
101
|
for (const prop in obj) {
|
|
99
|
-
const
|
|
100
|
-
if (!
|
|
102
|
+
const hasOwnProperty2 = Object.prototype.hasOwnProperty.call(obj, prop);
|
|
103
|
+
if (!hasOwnProperty2 || excludeFrom.includes(prop) || prop.startsWith("__"))
|
|
101
104
|
continue;
|
|
102
105
|
o[prop] = obj[prop];
|
|
103
106
|
}
|
|
@@ -109,8 +112,8 @@ const deepCloneExclude = (obj, excludeFrom = []) => {
|
|
|
109
112
|
}
|
|
110
113
|
const o = {};
|
|
111
114
|
for (const k in obj) {
|
|
112
|
-
const
|
|
113
|
-
if (!
|
|
115
|
+
const hasOwnProperty2 = Object.prototype.hasOwnProperty.call(obj, k);
|
|
116
|
+
if (!hasOwnProperty2 || excludeFrom.includes(k) || k.startsWith("__"))
|
|
114
117
|
continue;
|
|
115
118
|
let v = obj[k];
|
|
116
119
|
if (k === "extend" && (0, import_types.isArray)(v)) {
|
|
@@ -236,8 +239,8 @@ const detachFunctionsFromObject = (obj, detached = {}) => {
|
|
|
236
239
|
};
|
|
237
240
|
const deepDestringify = (obj, destringified = {}) => {
|
|
238
241
|
for (const prop in obj) {
|
|
239
|
-
const
|
|
240
|
-
if (!
|
|
242
|
+
const hasOwnProperty2 = Object.prototype.hasOwnProperty.call(obj, prop);
|
|
243
|
+
if (!hasOwnProperty2)
|
|
241
244
|
continue;
|
|
242
245
|
const objProp = obj[prop];
|
|
243
246
|
if ((0, import_types.isString)(objProp)) {
|
|
@@ -330,7 +333,39 @@ const diff = (original, objToDiff, cache = {}) => {
|
|
|
330
333
|
}
|
|
331
334
|
return cache;
|
|
332
335
|
};
|
|
333
|
-
const
|
|
336
|
+
const hasOwnProperty = (o, ...args) => Object.prototype.hasOwnProperty.call(o, ...args);
|
|
337
|
+
const isEmpty = (o) => Object.keys(o).length === 0;
|
|
338
|
+
const isEmptyObject = (o) => (0, import_types.isObject)(o) && isEmpty(o);
|
|
339
|
+
const makeObjectWithoutPrototype = () => /* @__PURE__ */ Object.create(null);
|
|
340
|
+
const deepDiff = (lhs, rhs) => {
|
|
341
|
+
if (lhs === rhs)
|
|
342
|
+
return {};
|
|
343
|
+
if (!(0, import_types.isObject)(lhs) || !(0, import_types.isObject)(rhs))
|
|
344
|
+
return rhs;
|
|
345
|
+
const deletedValues = Object.keys(lhs).reduce((acc, key) => {
|
|
346
|
+
if (!hasOwnProperty(rhs, key)) {
|
|
347
|
+
acc[key] = void 0;
|
|
348
|
+
}
|
|
349
|
+
return acc;
|
|
350
|
+
}, makeObjectWithoutPrototype());
|
|
351
|
+
if ((0, import_types.isDate)(lhs) || (0, import_types.isDate)(rhs)) {
|
|
352
|
+
if (lhs.valueOf() === rhs.valueOf())
|
|
353
|
+
return {};
|
|
354
|
+
return rhs;
|
|
355
|
+
}
|
|
356
|
+
return Object.keys(rhs).reduce((acc, key) => {
|
|
357
|
+
if (!hasOwnProperty(lhs, key)) {
|
|
358
|
+
acc[key] = rhs[key];
|
|
359
|
+
return acc;
|
|
360
|
+
}
|
|
361
|
+
const difference = diff(lhs[key], rhs[key]);
|
|
362
|
+
if (isEmptyObject(difference) && !(0, import_types.isDate)(difference) && (isEmptyObject(lhs[key]) || !isEmptyObject(rhs[key]))) {
|
|
363
|
+
return acc;
|
|
364
|
+
}
|
|
365
|
+
acc[key] = difference;
|
|
366
|
+
return acc;
|
|
367
|
+
}, deletedValues);
|
|
368
|
+
};
|
|
334
369
|
const overwrite = (element, params, excludeFrom = []) => {
|
|
335
370
|
const { ref } = element;
|
|
336
371
|
const changes = {};
|
|
@@ -426,8 +461,8 @@ const deepContains = (obj1, obj2) => {
|
|
|
426
461
|
}
|
|
427
462
|
} else if ((0, import_types.isObjectLike)(obj1) && obj2 !== null) {
|
|
428
463
|
for (const key in obj1) {
|
|
429
|
-
const
|
|
430
|
-
if (!
|
|
464
|
+
const hasOwnProperty2 = Object.prototype.hasOwnProperty.call(obj2, key);
|
|
465
|
+
if (!hasOwnProperty2 || !deepContains(obj1[key], obj2[key])) {
|
|
431
466
|
return false;
|
|
432
467
|
}
|
|
433
468
|
}
|
package/dist/cjs/types.js
CHANGED
|
@@ -22,6 +22,7 @@ __export(types_exports, {
|
|
|
22
22
|
is: () => is,
|
|
23
23
|
isArray: () => isArray,
|
|
24
24
|
isBoolean: () => isBoolean,
|
|
25
|
+
isDate: () => isDate,
|
|
25
26
|
isDefined: () => isDefined,
|
|
26
27
|
isFunction: () => isFunction,
|
|
27
28
|
isNot: () => isNot,
|
|
@@ -45,13 +46,14 @@ const isFunction = (arg) => typeof arg === "function";
|
|
|
45
46
|
const isBoolean = (arg) => arg === true || arg === false;
|
|
46
47
|
const isNull = (arg) => arg === null;
|
|
47
48
|
const isArray = (arg) => Array.isArray(arg);
|
|
49
|
+
const isDate = (d) => d instanceof Date;
|
|
48
50
|
const isObjectLike = (arg) => {
|
|
49
51
|
if (arg === null)
|
|
50
52
|
return false;
|
|
51
53
|
return typeof arg === "object";
|
|
52
54
|
};
|
|
53
55
|
const isDefined = (arg) => {
|
|
54
|
-
return isObject(arg) || isObjectLike(arg) || isString(arg) || isNumber(arg) || isFunction(arg) || isArray(arg) || isObjectLike(arg) || isBoolean(arg) || isNull(arg);
|
|
56
|
+
return isObject(arg) || isObjectLike(arg) || isString(arg) || isNumber(arg) || isFunction(arg) || isArray(arg) || isObjectLike(arg) || isBoolean(arg) || isDate(arg) || isNull(arg);
|
|
55
57
|
};
|
|
56
58
|
const isUndefined = (arg) => {
|
|
57
59
|
return arg === void 0;
|
|
@@ -61,6 +63,7 @@ const TYPES = {
|
|
|
61
63
|
array: isArray,
|
|
62
64
|
object: isObject,
|
|
63
65
|
string: isString,
|
|
66
|
+
date: isDate,
|
|
64
67
|
number: isNumber,
|
|
65
68
|
null: isNull,
|
|
66
69
|
function: isFunction,
|
package/object.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
import { window } from './globals.js'
|
|
4
|
-
import { isFunction, isObjectLike, isObject, isArray, isString, is, isUndefined } from './types.js'
|
|
4
|
+
import { isFunction, isObjectLike, isObject, isArray, isString, is, isUndefined, isDate } from './types.js'
|
|
5
5
|
import { mergeAndCloneIfArray, mergeArray } from './array.js'
|
|
6
6
|
import { stringIncludesAny } from './string.js'
|
|
7
|
-
import { diff as deepObjectDiff } from 'deep-object-diff'
|
|
8
7
|
|
|
9
8
|
export const exec = (param, element, state, context) => {
|
|
10
9
|
if (isFunction(param)) {
|
|
@@ -303,7 +302,50 @@ export const diff = (original, objToDiff, cache = {}) => {
|
|
|
303
302
|
return cache
|
|
304
303
|
}
|
|
305
304
|
|
|
306
|
-
export const
|
|
305
|
+
export const hasOwnProperty = (o, ...args) => Object.prototype.hasOwnProperty.call(o, ...args)
|
|
306
|
+
|
|
307
|
+
export const isEmpty = o => Object.keys(o).length === 0
|
|
308
|
+
|
|
309
|
+
export const isEmptyObject = (o) => isObject(o) && isEmpty(o)
|
|
310
|
+
|
|
311
|
+
export const makeObjectWithoutPrototype = () => Object.create(null)
|
|
312
|
+
|
|
313
|
+
// by mattphillips
|
|
314
|
+
// https://github.com/mattphillips/deep-object-diff/blob/main/src/diff.js
|
|
315
|
+
export const deepDiff = (lhs, rhs) => {
|
|
316
|
+
if (lhs === rhs) return {}
|
|
317
|
+
|
|
318
|
+
if (!isObject(lhs) || !isObject(rhs)) return rhs
|
|
319
|
+
|
|
320
|
+
const deletedValues = Object.keys(lhs).reduce((acc, key) => {
|
|
321
|
+
if (!hasOwnProperty(rhs, key)) {
|
|
322
|
+
acc[key] = undefined
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
return acc
|
|
326
|
+
}, makeObjectWithoutPrototype())
|
|
327
|
+
|
|
328
|
+
if (isDate(lhs) || isDate(rhs)) {
|
|
329
|
+
if (lhs.valueOf() === rhs.valueOf()) return {}
|
|
330
|
+
return rhs
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
return Object.keys(rhs).reduce((acc, key) => {
|
|
334
|
+
if (!hasOwnProperty(lhs, key)) {
|
|
335
|
+
acc[key] = rhs[key]
|
|
336
|
+
return acc
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
const difference = diff(lhs[key], rhs[key])
|
|
340
|
+
|
|
341
|
+
if (isEmptyObject(difference) && !isDate(difference) && (isEmptyObject(lhs[key]) || !isEmptyObject(rhs[key]))) {
|
|
342
|
+
return acc
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
acc[key] = difference
|
|
346
|
+
return acc
|
|
347
|
+
}, deletedValues)
|
|
348
|
+
}
|
|
307
349
|
|
|
308
350
|
/**
|
|
309
351
|
* Overwrites object properties with another
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domql/utils",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.24",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "index.js",
|
|
@@ -23,11 +23,8 @@
|
|
|
23
23
|
"build": "yarn build:cjs",
|
|
24
24
|
"prepublish": "rimraf -I dist && yarn build && yarn copy:package:cjs"
|
|
25
25
|
},
|
|
26
|
-
"gitHead": "
|
|
26
|
+
"gitHead": "95da8bcaf5250c1a6a339b7a5d11f49dd54a8369",
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@babel/core": "^7.12.0"
|
|
29
|
-
},
|
|
30
|
-
"dependencies": {
|
|
31
|
-
"deep-object-diff": "^1.1.9"
|
|
32
29
|
}
|
|
33
30
|
}
|
package/types.js
CHANGED
|
@@ -19,6 +19,8 @@ export const isNull = arg => arg === null
|
|
|
19
19
|
|
|
20
20
|
export const isArray = arg => Array.isArray(arg)
|
|
21
21
|
|
|
22
|
+
export const isDate = d => d instanceof Date
|
|
23
|
+
|
|
22
24
|
export const isObjectLike = arg => {
|
|
23
25
|
if (arg === null) return false
|
|
24
26
|
// if (isArray(arg)) return false
|
|
@@ -34,6 +36,7 @@ export const isDefined = arg => {
|
|
|
34
36
|
isArray(arg) ||
|
|
35
37
|
isObjectLike(arg) ||
|
|
36
38
|
isBoolean(arg) ||
|
|
39
|
+
isDate(arg) ||
|
|
37
40
|
isNull(arg)
|
|
38
41
|
}
|
|
39
42
|
|
|
@@ -46,6 +49,7 @@ export const TYPES = {
|
|
|
46
49
|
array: isArray,
|
|
47
50
|
object: isObject,
|
|
48
51
|
string: isString,
|
|
52
|
+
date: isDate,
|
|
49
53
|
number: isNumber,
|
|
50
54
|
null: isNull,
|
|
51
55
|
function: isFunction,
|