MCPcopy
hub / github.com/uNmAnNeR/imaskjs / objectIncludes

Function objectIncludes

packages/imask/src/core/utils.ts:60–99  ·  view source on GitHub ↗
(b: any, a: any)

Source from the content-addressed store, hash-verified

58// cloned from https://github.com/epoberezkin/fast-deep-equal with small changes
59export
60function objectIncludes (b: any, a: any): boolean {
61 if (a === b) return true;
62
63 const arrA = Array.isArray(a), arrB = Array.isArray(b);
64 let i;
65
66 if (arrA && arrB) {
67 if (a.length != b.length) return false;
68 for (i = 0; i < a.length; i++)
69 if (!objectIncludes(a[i], b[i])) return false;
70 return true;
71 }
72
73 if (arrA != arrB) return false;
74
75 if (a && b && typeof a === 'object' && typeof b === 'object') {
76 const dateA = a instanceof Date, dateB = b instanceof Date;
77 if (dateA && dateB) return a.getTime() == b.getTime();
78 if (dateA != dateB) return false;
79
80 const regexpA = a instanceof RegExp, regexpB = b instanceof RegExp;
81 if (regexpA && regexpB) return a.toString() == b.toString();
82 if (regexpA != regexpB) return false;
83
84 const keys = Object.keys(a);
85 // if (keys.length !== Object.keys(b).length) return false;
86
87 for (i = 0; i < keys.length; i++)
88 if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
89
90 for (i = 0; i < keys.length; i++)
91 if(!objectIncludes(b[keys[i]], a[keys[i]])) return false;
92
93 return true;
94 } else if (a && b && typeof a === 'function' && typeof b === 'function') {
95 return a.toString() === b.toString()
96 }
97
98 return false;
99}
100
101/** Selection range */
102export

Callers 2

optionsIsChangedFunction · 0.90
maskEqualsMethod · 0.90

Calls 1

toStringMethod · 0.65

Tested by

no test coverage detected