react / wstein / node_modules / browserify / node_modules / module-deps / node_modules / detective / node_modules / escodegen / node_modules / optionator / node_modules / deep-is / index.js
80642 viewsvar pSlice = Array.prototype.slice;1var Object_keys = typeof Object.keys === 'function'2? Object.keys3: function (obj) {4var keys = [];5for (var key in obj) keys.push(key);6return keys;7}8;910var deepEqual = module.exports = function (actual, expected) {11// enforce Object.is +0 !== -012if (actual === 0 && expected === 0) {13return areZerosEqual(actual, expected);1415// 7.1. All identical values are equivalent, as determined by ===.16} else if (actual === expected) {17return true;1819} else if (actual instanceof Date && expected instanceof Date) {20return actual.getTime() === expected.getTime();2122} else if (isNumberNaN(actual)) {23return isNumberNaN(expected);2425// 7.3. Other pairs that do not both pass typeof value == 'object',26// equivalence is determined by ==.27} else if (typeof actual != 'object' && typeof expected != 'object') {28return actual == expected;2930// 7.4. For all other Object pairs, including Array objects, equivalence is31// determined by having the same number of owned properties (as verified32// with Object.prototype.hasOwnProperty.call), the same set of keys33// (although not necessarily the same order), equivalent values for every34// corresponding key, and an identical 'prototype' property. Note: this35// accounts for both named and indexed properties on Arrays.36} else {37return objEquiv(actual, expected);38}39};4041function isUndefinedOrNull(value) {42return value === null || value === undefined;43}4445function isArguments(object) {46return Object.prototype.toString.call(object) == '[object Arguments]';47}4849function isNumberNaN(value) {50// NaN === NaN -> false51return typeof value == 'number' && value !== value;52}5354function areZerosEqual(zeroA, zeroB) {55// (1 / +0|0) -> Infinity, but (1 / -0) -> -Infinity and (Infinity !== -Infinity)56return (1 / zeroA) === (1 / zeroB);57}5859function objEquiv(a, b) {60if (isUndefinedOrNull(a) || isUndefinedOrNull(b))61return false;6263// an identical 'prototype' property.64if (a.prototype !== b.prototype) return false;65//~~~I've managed to break Object.keys through screwy arguments passing.66// Converting to array solves the problem.67if (isArguments(a)) {68if (!isArguments(b)) {69return false;70}71a = pSlice.call(a);72b = pSlice.call(b);73return deepEqual(a, b);74}75try {76var ka = Object_keys(a),77kb = Object_keys(b),78key, i;79} catch (e) {//happens when one is a string literal and the other isn't80return false;81}82// having the same number of owned properties (keys incorporates83// hasOwnProperty)84if (ka.length != kb.length)85return false;86//the same set of keys (although not necessarily the same order),87ka.sort();88kb.sort();89//~~~cheap key test90for (i = ka.length - 1; i >= 0; i--) {91if (ka[i] != kb[i])92return false;93}94//equivalent values for every corresponding key, and95//~~~possibly expensive deep test96for (i = ka.length - 1; i >= 0; i--) {97key = ka[i];98if (!deepEqual(a[key], b[key])) return false;99}100return true;101}102103104