Browse Source

Minor bugfixes

master
Muthu Kumar 7 years ago
parent
commit
471313ab2c
  1. 2
      dist/isEq.min.js
  2. 18
      isEq.js

2
dist/isEq.min.js

@ -7,4 +7,4 @@
* *
* Usage: isEq(<*>, <*>, [compareKeys, ...]); * Usage: isEq(<*>, <*>, [compareKeys, ...]);
*/ */
'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((typeof item1==='undefined'?'undefined':_typeof(item1))!==(typeof item2==='undefined'?'undefined':_typeof(item2))){return false}if(Array.isArray(item1)){if(!Array.isArray(item2)){return false}}if(Array.isArray(item2)){if(!Array.isArray(item1)){return false}}if(typeof item1==='number'||typeof item1==='string'||typeof item1==='boolean'||item1===null||item1===undefined){if(item1===item2){return true}else{return false}};if(item1===NaN&&item2===NaN){return true}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])){var _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;break}}else{return false;break}}};return true};module.exports=isEq; (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})()({},{},[])

18
isEq.js

@ -18,12 +18,11 @@ const isEq = (item1, item2, compareKeys) => {
// Arrays are of type object, hence let's go one further step // Arrays are of type object, hence let's go one further step
// to prove type inequality // to prove type inequality
if (Array.isArray(item1)) if ((Array.isArray(item1)
if (!Array.isArray(item2)) && !Array.isArray(item2))
return false; || ((Array.isArray(item2)
if (Array.isArray(item2)) && !Array.isArray(item1))))
if (!Array.isArray(item1)) return false;
return false;
// Since types are already equal, let's find if items are equal. // Since types are already equal, let's find if items are equal.
if ((typeof item1 === 'number') || if ((typeof item1 === 'number') ||
@ -31,12 +30,11 @@ const isEq = (item1, item2, compareKeys) => {
(typeof item1 === 'boolean') || (typeof item1 === 'boolean') ||
(item1 === null) || (item1 === null) ||
(item1 === undefined)) { (item1 === undefined)) {
if (item1 === item2) return true; return (item1 === item2);
else return false;
}; };
// 'NaN's are special. They aren't equal to each other. // 'NaN's are special. They aren't equal to each other.
if (item1 === NaN && item2 === NaN) return true; if (Number.isNaN(item1) && Number.isNaN(item2)) return true;
// Regexp needs to be Stringified first before comparing equality // Regexp needs to be Stringified first before comparing equality
if (item1 instanceof RegExp) return String(item1) === String(item2); if (item1 instanceof RegExp) return String(item1) === String(item2);
@ -68,7 +66,7 @@ const isEq = (item1, item2, compareKeys) => {
let Key = compareKeys[KeyIndex]; let Key = compareKeys[KeyIndex];
if (Array.isArray(item1[Key]) && Array.isArray(item2[Key])) { if (Array.isArray(item1[Key]) && Array.isArray(item2[Key])) {
const Key = KeyIndex; Key = KeyIndex;
}; };
// Inequality at this point can be because it's just comparing // Inequality at this point can be because it's just comparing

Loading…
Cancel
Save