From cdfa70147071f4c3dbe491608c4feb4aa50b0aa0 Mon Sep 17 00:00:00 2001 From: Muthu Kumar Date: Sat, 12 May 2018 18:37:19 +0530 Subject: [PATCH] [iseq] unhandleable input falls back to strict equality --- README.md | 12 +++++++----- isEq.js | 3 ++- package.json | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 5909ce8..29db85b 100644 --- a/README.md +++ b/README.md @@ -13,13 +13,15 @@ Although its intention is deep comparison, `isEq` can compare several datatypes. | Number | ✅ | | String | ✅ | | Boolean | ✅ | -| Regexp | ✅ | | Object | ✅ | | Array | ✅ | -| Cyclic Object/Array | ❌ | -| Function | ❌ | -| Symbol | ❌ | -| Blob | ❌ | +| Cyclic Object/Array | ✅ | +| Regexp | ✅ | +| Function | ✅ | +| Symbol | ✅ | + +> Note: functions and symbols are compared by identity. Regexp is stringified before comparison. +> Unhandleable inputs fall back to strict equality (`===`) ## Installation diff --git a/isEq.js b/isEq.js index c5861b9..e5916fb 100644 --- a/isEq.js +++ b/isEq.js @@ -47,8 +47,9 @@ const isEq = (item1, item2, compareKeys) => { if (item1 instanceof RegExp) return String(item1) === String(item2); // If none of the above conditions returned, then check if inputs are handlable + // If they're not, fall back to strict equality if (typeof (item1) !== 'object' || typeof (item2) !== 'object') - throw new Error('[isEq] Unhandleable input!'); + return (item1 === item2); const item1Keys = Object.keys(item1); const item2Keys = Object.keys(item2); diff --git a/package.json b/package.json index 38c521e..0e83fa1 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "test": "jasmine", "build": "jasmine && ./build.sh", "prepublishOnly": "jasmine && ./build.sh", - "release": "npm test && npm run build && npm publish" + "release": "npm run build && npm publish" }, "repository": { "type": "git",