@observ33r/object-equals
Version:
A fast, flexible and robust utility for deep equality comparison with type-specific logic and engine-aware design.
3 lines (2 loc) • 4.61 kB
JavaScript
const{getOwnPropertySymbols:t,keys:e,prototype:{hasOwnProperty:r,toString:n}}=Object,o=Array.prototype.splice,f=ArrayBuffer.isView,i=Symbol.for("react.transitional.element"),c=("object"==typeof window||"object"==typeof self)&&"object"==typeof navigator&&"string"==typeof navigator.userAgent,u="object"===globalThis.chrome||c&&navigator.userAgent.search(/chrome/i)>-1,a=void 0!==globalThis.$?.IsHTMLDDA||c&&null!==navigator.userAgent.match(/^(?!.*(chrome|crios)).*safari/i);function l(c,s,g,y,p,b,h,v){if("object"==typeof c&&"object"==typeof s){if(!y){if(null===c||null===s)return c===s;var j=c.constructor;if(j!==s.constructor){if(!r.call(c,"constructor")&&!r.call(s,"constructor"))return!1;j=void 0}}if(p&&c.$$typeof===i&&s.$$typeof===i)return c.type===s.type&&c.key===s.key&&c.ref===s.ref&&l(c.props,s.props,g,y,p,b,h,v);if(g){let t=v.get(c);if(void 0!==t)return t===s;if(t=v.get(s),void 0!==t)return t===c;v.set(c,s).set(s,c)}for(;;){if(void 0!==j){if(j===Object){const n=e(c),o=n.length;if(o!==e(s).length)return!1;if(u&&o>1&&o<20||a&&o<66)for(const t in c){if(!r.call(c,t))continue;const e=s[t];if(void 0===e&&!r.call(s,t))return!1;const n=c[t];if(n!==e&&!l(n,e,g,y,p,b,h,v))return!1}else for(let t=o-1;t>=0;t--){const e=n[t],o=s[e];if(void 0===o&&!r.call(s,e))return!1;const f=c[e];if(f!==o&&!l(f,o,g,y,p,b,h,v))return!1}if(b){const e=t(c),n=e.length;if(n!==t(s).length)return!1;for(let t=n-1;t>=0;t--){const n=e[t],o=s[n];if(void 0===o&&!r.call(s,n))return!1;const f=c[n];if(f!==o&&!l(f,o,g,y,p,b,h,v))return!1}}return!0}if(j===Array){const t=c.length;if(t!==s.length)return!1;for(let e=t-1;e>=0;e--)if(c[e]!==s[e]&&!l(c[e],s[e],g,y,p,b,h,v))return!1;return!0}if(j===DataView){const t=c.byteLength;if(t!==s.byteLength)return!1;const e=-4&t;if(e)for(let t=e-4;t>=0;t-=4)if(c.getInt32(t)!==s.getInt32(t))return!1;for(let r=t-1;r>=e;r--)if(c.getInt8(r)!==s.getInt8(r))return!1;return!0}if(j!==ArrayBuffer&&j!==SharedArrayBuffer||(c=new Uint8Array(c),s=new Uint8Array(s),j=Uint8Array),j===Uint8Array||f(c)){const t=c.length;if(t!==s.length)return!1;const e=c.byteOffset,r=s.byteOffset,n=t>64&&e%4==0&&r%4==0?-4&t:0;if(n){const n=t/4|0,o=new Int32Array(c.buffer,e,n),f=new Int32Array(s.buffer,r,n);for(let t=n-1;t>=0;t--)if(o[t]!==f[t])return!1}for(let e=t-1;e>=n;e--)if(c[e]!==s[e])return!1;return!0}if(j===Map){if(c.size!==s.size)return!1;for(const{0:t,1:e}of c.entries()){const r=s.get(t);if(void 0===r&&!s.has(t))return!1;if(e!==r&&!l(e,r,g,y,p,b,h,v))return!1}return!0}if(j===Set){if(c.size!==s.size)return!1;const t=[];for(const e of c.values())if(!s.has(e)){if("object"!=typeof e)return!1;t.push(e)}if(0===t.length)return!0;const e=[];for(const t of s.values())null!==t&&"object"==typeof t&&e.push(t);if(t.length!==e.length)return!1;if(1===t.length)return l(t[0],e[0],g,y,p,b,h,v);t:for(let r=t.length-1;r>=0;r--){for(let n=e.length-1;n>=0;n--)if(l(t[r],e[n],g,y,p,b,h,v)){o.call(e,n,1);continue t}return!1}return!0}if(j===Date){const t=c.getTime(),e=s.getTime();return t===e||t!=t&&e!=e}if(j===RegExp)return c.source===s.source&&c.flags===s.flags&&c.lastIndex===s.lastIndex;if(j===Boolean||j===String)return c.valueOf()===s.valueOf();if(j===Number||j===BigInt){const t=c.valueOf(),e=s.valueOf();return t===e||t!=t&&e!=e}if(j===Error)return c.name===s.name&&c.message===s.message&&c.cause===s.cause}if(void 0===A){var A=n.call(c);if(A!==n.call(s))return!1;if(void 0!==(j="[object Object]"===A?Object:"[object Array]"===A?Array:"[object DataView]"===A?DataView:"[object ArrayBuffer]"===A?ArrayBuffer:"[object SharedArrayBuffer]"===A?SharedArrayBuffer:"[object Map]"===A?Map:"[object Set]"===A?Set:"[object Date]"===A?Date:"[object RegExp]"===A?RegExp:"[object Boolean]"===A?Boolean:"[object String]"===A?String:"[object Number]"===A?Number:"[object BigInt]"===A?BigInt:"[object Error]"===A?Error:f(c)?Uint8Array:void 0))continue}if(h){if("function"==typeof c.valueOf&&"function"==typeof s.valueOf){const t=c.valueOf(),e=s.valueOf();if(t!==c&&e!==s)return t===e||l(t,e,g,y,p,b,h,v)}if("function"==typeof c.toString&&"function"==typeof s.toString){const t=c.toString(),e=s.toString();if(t!==c&&e!==s)return t===e}}throw TypeError(`Unsupported object type: ${A}`)}}return p&&"function"==typeof c&&"function"==typeof s?c.toString()===s.toString():c===s||c!=c&&s!=s}function s(t,e,r){if(t===e)return!0;if(null==r&&"object"!=typeof r)return l(t,e,!1,!1,!1,!1,!1,void 0);const n=!0===r.circular;return l(t,e,n,!0===r.crossrealm,!0===r.react,!0===r.symbols,!0===r.fallback,n?null!=r.cache?r.cache:new Map:void 0)}export{s as objectEquals,l as objectEqualsCore};
//# sourceMappingURL=object-equals.esm.js.map