UNPKG

@darwino/darwino

Version:

A set of Javascript classes and utilities

48 lines (42 loc) 1.5 kB
/*!COPYRIGHT HEADER! - CONFIDENTIAL * * Darwino Inc Confidential. * * (c) Copyright Darwino Inc. 2014-2016. * * Notice: The information contained in the source code for these files is the property * of Darwino Inc. which, with its licensors, if any, owns all the intellectual property * rights, including all copyright rights thereto. Such information may only be used * for debugging, troubleshooting and informational purposes. All other uses of this information, * including any production or commercial uses, are prohibited. */ // // Deep compare 2 JSON objects // Inspired from https://github.com/epoberezkin/fast-deep-equal // MIT license // export default function jsonEquals(a, b) { if (a === b) return true; if (a && b && typeof a === 'object' && typeof b === 'object') { if (Array.isArray(a)) { const length = a.length; if (length != b.length) return false; for (let i = length; i-- !== 0;) if (!jsonEquals(a[i], b[i])) return false; return true; } const keys = Object.keys(a); const length = keys.length; if (length !== Object.keys(b).length) return false; for (let i = length; i-- !== 0;) { if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false; } for (let i = length; i-- !== 0;) { const key = keys[i]; if (!jsonEquals(a[key], b[key])) return false; } return true; } // true if both NaN, false otherwise return a!==a && b!==b; };