Browse Source

[iseq] unhandleable input falls back to strict equality

master
Muthu Kumar 6 years ago
parent
commit
cdfa701470
  1. 12
      README.md
  2. 3
      isEq.js
  3. 2
      package.json

12
README.md

@ -13,13 +13,15 @@ Although its intention is deep comparison, `isEq` can compare several datatypes.
| Number | ✅ | | Number | ✅ |
| String | ✅ | | String | ✅ |
| Boolean | ✅ | | Boolean | ✅ |
| Regexp | ✅ |
| Object | ✅ | | Object | ✅ |
| Array | ✅ | | Array | ✅ |
| Cyclic Object/Array | ❌ | | Cyclic Object/Array | ✅ |
| Function | ❌ | | Regexp | ✅ |
| Symbol | ❌ | | Function | ✅ |
| Blob | ❌ | | Symbol | ✅ |
> Note: functions and symbols are compared by identity. Regexp is stringified before comparison.
> Unhandleable inputs fall back to strict equality (`===`)
## Installation ## Installation

3
isEq.js

@ -47,8 +47,9 @@ const isEq = (item1, item2, compareKeys) => {
if (item1 instanceof RegExp) return String(item1) === String(item2); if (item1 instanceof RegExp) return String(item1) === String(item2);
// If none of the above conditions returned, then check if inputs are handlable // 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') if (typeof (item1) !== 'object' || typeof (item2) !== 'object')
throw new Error('[isEq] Unhandleable input!'); return (item1 === item2);
const item1Keys = Object.keys(item1); const item1Keys = Object.keys(item1);
const item2Keys = Object.keys(item2); const item2Keys = Object.keys(item2);

2
package.json

@ -7,7 +7,7 @@
"test": "jasmine", "test": "jasmine",
"build": "jasmine && ./build.sh", "build": "jasmine && ./build.sh",
"prepublishOnly": "jasmine && ./build.sh", "prepublishOnly": "jasmine && ./build.sh",
"release": "npm test && npm run build && npm publish" "release": "npm run build && npm publish"
}, },
"repository": { "repository": {
"type": "git", "type": "git",

Loading…
Cancel
Save