UNPKG

@dossierhq/core

Version:

The core Dossier library used by clients and server alike, used to interact with schema and entities directly, as well as remotely through a client.

42 lines 1.43 kB
/// <reference types="./isFieldValueEqual.d.ts" /> // TODO not sure about this one. Change to isEqual()? Or at least split if we want null and undefined to be equal? export function isFieldValueEqual(a, b) { if (a === b) return true; if (a === null || a === undefined || b === null || b === undefined) { return false; // if a or be are not defined they can't be equal } if (Array.isArray(a)) { if (!Array.isArray(b)) return false; if (a.length !== b.length) return false; for (let i = 0; i < a.length; i += 1) { if (!isFieldValueEqual(a[i], b[i])) { return false; } } return true; } if (typeof a === 'object') { if (typeof b !== 'object' || a === null || b === null) return false; if (a instanceof Date || b instanceof Date) { if (!(a instanceof Date && b instanceof Date)) return false; return a.getTime() === b.getTime(); } const aKeys = Object.keys(a); const bKeys = Object.keys(b); if (aKeys.length !== bKeys.length) return false; for (const key of aKeys) { if (!isFieldValueEqual(a[key], b[key])) { return false; } } return true; } return false; } //# sourceMappingURL=isFieldValueEqual.js.map