* @ngdoc function * @name angular.equals * @module ng * @kind function * * @description * Determines if two objects or two values are equivalent. Supports value types, regular * expressions, arrays and objects. * * Two objects or values are considered equivalent if at least one of the follo
(o1, o2)
| 1221 | </example> |
| 1222 | */ |
| 1223 | function equals(o1, o2) { |
| 1224 | if (o1 === o2) return true; |
| 1225 | if (o1 === null || o2 === null) return false; |
| 1226 | // eslint-disable-next-line no-self-compare |
| 1227 | if (o1 !== o1 && o2 !== o2) return true; // NaN === NaN |
| 1228 | var t1 = typeof o1, t2 = typeof o2, length, key, keySet; |
| 1229 | if (t1 === t2 && t1 === 'object') { |
| 1230 | if (isArray(o1)) { |
| 1231 | if (!isArray(o2)) return false; |
| 1232 | if ((length = o1.length) === o2.length) { |
| 1233 | for (key = 0; key < length; key++) { |
| 1234 | if (!equals(o1[key], o2[key])) return false; |
| 1235 | } |
| 1236 | return true; |
| 1237 | } |
| 1238 | } else if (isDate(o1)) { |
| 1239 | if (!isDate(o2)) return false; |
| 1240 | return simpleCompare(o1.getTime(), o2.getTime()); |
| 1241 | } else if (isRegExp(o1)) { |
| 1242 | if (!isRegExp(o2)) return false; |
| 1243 | return o1.toString() === o2.toString(); |
| 1244 | } else { |
| 1245 | if (isScope(o1) || isScope(o2) || isWindow(o1) || isWindow(o2) || |
| 1246 | isArray(o2) || isDate(o2) || isRegExp(o2)) return false; |
| 1247 | keySet = createMap(); |
| 1248 | for (key in o1) { |
| 1249 | if (key.charAt(0) === '$' || isFunction(o1[key])) continue; |
| 1250 | if (!equals(o1[key], o2[key])) return false; |
| 1251 | keySet[key] = true; |
| 1252 | } |
| 1253 | for (key in o2) { |
| 1254 | if (!(key in keySet) && |
| 1255 | key.charAt(0) !== '$' && |
| 1256 | isDefined(o2[key]) && |
| 1257 | !isFunction(o2[key])) return false; |
| 1258 | } |
| 1259 | return true; |
| 1260 | } |
| 1261 | } |
| 1262 | return false; |
| 1263 | } |
| 1264 | |
| 1265 | var csp = function() { |
| 1266 | if (!isDefined(csp.rules)) { |
no test coverage detected