UNPKG

bootstrap-vue

Version:

Quickly integrate Bootstrap 4 components with Vue.js

50 lines (46 loc) 1.28 kB
import { isArray} from './array'; import { keys} from './object'; /** * Quick object check - this is primarily used to tell * Objects from primitive values when we know the value * is a JSON-compliant type. */ function isObject(obj) { return obj !== null && typeof obj === 'object'; } /** * Check if two values are loosely equal - that is, * if they are plain objects, do they have the same shape? * Returns boolean true or false */ function looseEqual(a, b) { if (a === b) return true; const isObjectA = isObject(a); const isObjectB = isObject(b); if (isObjectA && isObjectB) { try { const isArrayA = isArray(a); const isArrayB = isArray(b); if (isArrayA && isArrayB) { return a.length === b.length && a.every((e, i) => { return looseEqual(e, b[i]); }); } else if (!isArrayA && !isArrayB) { const keysA = keys(a); const keysB = keys(b); return keysA.length === keysB.length && keysA.every(key => { return looseEqual(a[key], b[key]); }); } else { return false; } } catch (e) { return false; } } else if (!isObjectA && !isObjectB) { return String(a) === String(b); } else { return false; } } export default looseEqual;