export const compareDates = (a, b) => a.getTime() === b.getTime(); export const compareRegexps = (a, b) => a.source === b.source && a.flags === b.flags; export const compareArrays = (a, b, equal) => { let l = a.length; if (l !== b.length) return false; while (l-- && equal(a[l], b[l])) ; return l === -1; }; export const compareMaps = (a, b, equal) => { if (a.size !== b.size) return false; const it = a.entries(); let i; while (!(i = it.next()).done) { if (!b.has(i.value[0]) || !equal(i.value[1], b.get(i.value[0]))) return false; } return true; }; export const compareSets = (a, b) => { if (a.size !== b.size) return false; const it = a.values(); let i; while (!(i = it.next()).done) { if (!b.has(i.value)) return false; } return true; }; export const compareDataViews = (a, b) => { let l = a.byteLength; if (l !== b.byteLength) return false; while (l-- && a.getInt8(l) === b.getInt8(l)) ; return l === -1; }; export const compareArrayBuffers = (a, b) => { let l = a.length; if (l !== b.length) return false; while (l-- && a[l] === b[l]) ; return l === -1; }; const { hasOwnProperty } = Object.prototype; const oKeys = Object.keys; export const compareObjects = (a, b, equal) => { let i; let len = 0; for (i in a) { if (hasOwnProperty.call(a, i)) { len++; if (!hasOwnProperty.call(b, i)) return false; if (!equal(a[i], b[i])) return false; } } return oKeys(b).length === len; }; export const compareObjectsReact = (a, b, equal) => { let i; let len = 0; for (i in a) { if (hasOwnProperty.call(a, i)) { len++; if (a.$$typeof && (i === '_owner' || i === '__v' || i === '__o')) { // in React and Preact these properties contain circular references // .$$typeof is just reasonable marker of element continue; } if (!hasOwnProperty.call(b, i)) return false; if (!equal(a[i], b[i])) return false; } } return oKeys(b).length === len; };