@glyph-cat/equality
Version:
Common equality-checking presets for general purpose.
3 lines (2 loc) • 1 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).Equality={})}(this,(function(t){"use strict";function e(t,e){if(Array.isArray(t)&&Array.isArray(e)){if(t.length!==e.length)return!1;for(let n=0;n<t.length;n++)if(!Object.is(t[n],e[n]))return!1;return!0}return Object.is(t,e)}function n(t){return"object"==typeof t&&!Object.is(t,null)}function r(t,e){if(n(t)&&n(e)){const n=Object.keys(t),r=Object.keys(e);if(n.length!==r.length)return!1;for(let f=0;f<n.length;f++){const o=n[f],u=r[f];if(o!==u)return!1;if(!Object.is(t[o],e[u]))return!1}return!0}return Object.is(t,e)}t.shallowCompareArray=e,t.shallowCompareArrayOrObject=function(t,n){const f=Array.isArray(t),o=Array.isArray(n);return f===o&&(f&&o?e(t,n):r(t,n))},t.shallowCompareObject=r,t.stringifyCompare=function(t,e){return JSON.stringify(t)===JSON.stringify(e)}}));
//# sourceMappingURL=index.js.map