CoolFace
Datasetpublic

basant307/AI_Governance_Project

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes48downloads
index.js103 linesDownload Raw Back to deep-is
1var pSlice = Array.prototype.slice;2var Object_keys = typeof Object.keys === 'function'3    ? Object.keys4    : function (obj) {5        var keys = [];6        for (var key in obj) keys.push(key);7        return keys;8    }9;10 11var deepEqual = module.exports = function (actual, expected) {12  // enforce Object.is +0 !== -013  if (actual === 0 && expected === 0) {14    return areZerosEqual(actual, expected);15 16  // 7.1. All identical values are equivalent, as determined by ===.17  } else if (actual === expected) {18    return true;19 20  } else if (actual instanceof Date && expected instanceof Date) {21    return actual.getTime() === expected.getTime();22 23  } else if (isNumberNaN(actual)) {24    return isNumberNaN(expected);25 26  // 7.3. Other pairs that do not both pass typeof value == 'object',27  // equivalence is determined by ==.28  } else if (typeof actual != 'object' && typeof expected != 'object') {29    return actual == expected;30 31  // 7.4. For all other Object pairs, including Array objects, equivalence is32  // determined by having the same number of owned properties (as verified33  // with Object.prototype.hasOwnProperty.call), the same set of keys34  // (although not necessarily the same order), equivalent values for every35  // corresponding key, and an identical 'prototype' property. Note: this36  // accounts for both named and indexed properties on Arrays.37  } else {38    return objEquiv(actual, expected);39  }40};41 42function isUndefinedOrNull(value) {43  return value === null || value === undefined;44}45 46function isArguments(object) {47  return Object.prototype.toString.call(object) == '[object Arguments]';48}49 50function isNumberNaN(value) {51  // NaN === NaN -> false52  return typeof value == 'number' && value !== value;53}54 55function areZerosEqual(zeroA, zeroB) {56  // (1 / +0|0) -> Infinity, but (1 / -0) -> -Infinity and (Infinity !== -Infinity)57  return (1 / zeroA) === (1 / zeroB);58}59 60function objEquiv(a, b) {61  if (isUndefinedOrNull(a) || isUndefinedOrNull(b))62    return false;63 64  // an identical 'prototype' property.65  if (a.prototype !== b.prototype) return false;66  //~~~I've managed to break Object.keys through screwy arguments passing.67  //   Converting to array solves the problem.68  if (isArguments(a)) {69    if (!isArguments(b)) {70      return false;71    }72    a = pSlice.call(a);73    b = pSlice.call(b);74    return deepEqual(a, b);75  }76  try {77    var ka = Object_keys(a),78        kb = Object_keys(b),79        key, i;80  } catch (e) {//happens when one is a string literal and the other isn't81    return false;82  }83  // having the same number of owned properties (keys incorporates84  // hasOwnProperty)85  if (ka.length != kb.length)86    return false;87  //the same set of keys (although not necessarily the same order),88  ka.sort();89  kb.sort();90  //~~~cheap key test91  for (i = ka.length - 1; i >= 0; i--) {92    if (ka[i] != kb[i])93      return false;94  }95  //equivalent values for every corresponding key, and96  //~~~possibly expensive deep test97  for (i = ka.length - 1; i >= 0; i--) {98    key = ka[i];99    if (!deepEqual(a[key], b[key])) return false;100  }101  return true;102}103 
basant307/AI_Governance_Project · CoolFace