@greensight/gds
Version:
Greensight Design System
41 lines (33 loc) • 1.22 kB
JavaScript
import { f as _typeof } from './_rollupPluginBabelHelpers-D0Wa2C7U.js';
function fastEquals(a, b) {
// If both are the same object/reference or same primitive value
if (a === b) return true;
// If they are not the same type
if (_typeof(a) !== _typeof(b)) return false;
// If they are objects
if (_typeof(a) === 'object') {
// If they are not the same class (Array, Object)
if (Object.getPrototypeOf(a) !== Object.getPrototypeOf(b)) return false;
// If they are arrays, compare each element
if (Array.isArray(a)) {
if (a.length !== b.length) return false;
for (var i = 0; i < a.length; i++) {
if (!fastEquals(a[i], b[i])) return false;
}
return true;
}
// If they are objects, compare each key
var keys = Object.keys(a);
if (keys.length !== Object.keys(b).length) return false;
for (var _i = 0, _keys = keys; _i < _keys.length; _i++) {
var key = _keys[_i];
// eslint-disable-next-line no-prototype-builtins
if (!b.hasOwnProperty(key)) return false;
if (!fastEquals(a[key], b[key])) return false;
}
return true;
}
// If they are not the same primitive value
return false;
}
export { fastEquals };