≡ isEq.js -- deep compare objects and arrays in JavaScript
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2 lines
2.5 KiB

7 years ago
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.isEq=f()}})(function(){var define,module,exports;return function(){function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}return e}()({1:[function(require,module,exports){"use strict";var _typeof=typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"?function(obj){return typeof obj}:function(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj};var isEq=function isEq(item1,item2,compareKeys){if(item1===item2)return true;if((typeof item1==="undefined"?"undefined":_typeof(item1))!==(typeof item2==="undefined"?"undefined":_typeof(item2)))return false;if(Array.isArray(item1)&&!Array.isArray(item2)||Array.isArray(item2)&&!Array.isArray(item1))return false;if(typeof item1==="number"){if(isNaN(item1)&&isNaN(item2))return false;else return item1===item2}if(typeof item1==="string"||typeof item1==="boolean"||item1===null||item1===undefined){return item1===item2}if(item1 instanceof RegExp)return String(item1)===String(item2);if((typeof item1==="undefined"?"undefined":_typeof(item1))!=="object"||(typeof item2==="undefined"?"undefined":_typeof(item2))!=="object")throw new Error("[isEq] Unhandleable input!");var item1Keys=Object.keys(item1);var item2Keys=Object.keys(item2);if(!compareKeys){compareKeys=item1Keys;if(item1Keys.length!==item2Keys.length){return false}}if(!Array.isArray(compareKeys))throw new Error("[isEq] third parameter should be an array of keys!");if(compareKeys.length===0)return true;for(var KeyIndex in compareKeys){var Key=compareKeys[KeyIndex];if(Array.isArray(item1[Key])&&Array.isArray(item2[Key])){Key=KeyIndex}if(item1[Key]!==item2[Key]){if(_typeof(item1[Key]==="object")&&_typeof(item2[Key]==="object")||Array.isArray(item1[Key])&&Array.isArray(item2[Key])){if(!isEq(item1[Key],item2[Key])){return false}}else{return false}}}return true};module.exports=isEq},{}]},{},[1])(1)});