UNPKG

kr-observable

Version:
37 lines (36 loc) 1.09 kB
export class Utils { static AdmKey = Symbol.for('adm'); static IGNORED = 0; static ACCESSOR = 1; static SHALLOW = 2; static WRITABLE = 3; static isPlainObject(value) { const ctor = value?.constructor; return !ctor || ctor === Object; } static isPrimitive(val) { return val === null || (typeof val !== 'object' && typeof val !== 'function'); } static isDeepEqual(a, b) { if (a == null || b == null) return Object.is(a, b); const A = a.valueOf(); const B = b.valueOf(); if (typeof A === 'object') { if (typeof B !== 'object') return false; const keys = Object.keys(A); if (keys.length !== Object.keys(B).length) return false; for (const key of keys) { if (!Utils.isDeepEqual(A[key], B[key])) return false; } return true; } return Object.is(a, b); } static getAdm(value) { return value[Utils.AdmKey]; } }