UNPKG

@greensight/gds

Version:
41 lines (33 loc) 1.32 kB
var _rollupPluginBabelHelpers = require('./_rollupPluginBabelHelpers-mkWCC7yp.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 (_rollupPluginBabelHelpers._typeof(a) !== _rollupPluginBabelHelpers._typeof(b)) return false; // If they are objects if (_rollupPluginBabelHelpers._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; } exports.fastEquals = fastEquals;