@glyph-cat/equality
Version:
General purpose equality-checking presets.
2 lines (1 loc) • 949 B
JavaScript
;function t(t,r){if(Array.isArray(t)&&Array.isArray(r)){if(t.length!==r.length)return!1;for(let e=0;e<t.length;e++)if(!Object.is(t[e],r[e]))return!1;return!0}return Object.is(t,r)}const r=t;function e(t){return"object"==typeof t&&!function(t){return Object.is(t,null)}(t)}function n(t,r){if(e(t)&&e(r)){const e=Object.keys(t),n=Object.keys(r);if(e.length!==n.length)return!1;for(let o=0;o<e.length;o++){const c=e[o],u=n[o];if(c!==u)return!1;if(!Object.is(t[c],r[u]))return!1}return!0}return Object.is(t,r)}const o=n;function c(r,e){const o=Array.isArray(r),c=Array.isArray(e);return o===c&&(o&&c?t(r,e):n(r,e))}const u=c;function s(t,r){return JSON.stringify(t)===JSON.stringify(r)}const f=s;exports.arrayOrObjectShallowEqual=c,exports.arrayShallowEqual=t,exports.objectShallowEqual=n,exports.shallowCompareArray=r,exports.shallowCompareArrayOrObject=u,exports.shallowCompareObject=o,exports.stringifyCompare=f,exports.stringifyEqual=s;