@thi.ng/equiv
Advanced tools
Comparing version 0.1.8 to 0.1.9
export declare const equiv: (a: any, b: any) => boolean; | ||
export declare const equivArrayLike: (a: ArrayLike<any>, b: ArrayLike<any>, _equiv?: (a: any, b: any) => boolean) => boolean; | ||
export declare const equivSet: (a: Set<any>, b: Set<any>, _equiv?: (a: any, b: any) => boolean) => boolean; | ||
export declare const equivMap: (a: Map<any, any>, b: Map<any, any>, _equiv?: (a: any, b: any) => boolean) => boolean; | ||
export declare const equivObject: (a: any, b: any, _equiv?: (a: any, b: any) => boolean) => boolean; |
55
index.js
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const is_arraylike_1 = require("@thi.ng/checks/is-arraylike"); | ||
const is_date_1 = require("@thi.ng/checks/is-date"); | ||
const is_map_1 = require("@thi.ng/checks/is-map"); | ||
const is_plain_object_1 = require("@thi.ng/checks/is-plain-object"); | ||
const is_regexp_1 = require("@thi.ng/checks/is-regexp"); | ||
const is_set_1 = require("@thi.ng/checks/is-set"); | ||
const OBJP = Object.getPrototypeOf({}); | ||
exports.equiv = (a, b) => { | ||
let proto; | ||
if (a === b) { | ||
@@ -32,18 +28,20 @@ return true; | ||
} | ||
if (is_plain_object_1.isPlainObject(a) && is_plain_object_1.isPlainObject(b)) { | ||
return equivObject(a, b); | ||
if ((proto = Object.getPrototypeOf(a), proto == null || proto === OBJP) && | ||
(proto = Object.getPrototypeOf(b), proto == null || proto === OBJP)) { | ||
return exports.equivObject(a, b); | ||
} | ||
if (is_arraylike_1.isArrayLike(a) && is_arraylike_1.isArrayLike(b)) { | ||
return equivArrayLike(a, b); | ||
if (typeof a !== "function" && a.length !== undefined && | ||
typeof b !== "function" && b.length !== undefined) { | ||
return exports.equivArrayLike(a, b); | ||
} | ||
if (is_set_1.isSet(a) && is_set_1.isSet(b)) { | ||
return equivSet(a, b); | ||
if (a instanceof Set && b instanceof Set) { | ||
return exports.equivSet(a, b); | ||
} | ||
if (is_map_1.isMap(a) && is_map_1.isMap(b)) { | ||
return equivMap(a, b); | ||
if (a instanceof Map && b instanceof Map) { | ||
return exports.equivMap(a, b); | ||
} | ||
if (is_date_1.isDate(a) && is_date_1.isDate(b)) { | ||
if (a instanceof Date && b instanceof Date) { | ||
return a.getTime() === b.getTime(); | ||
} | ||
if (is_regexp_1.isRegExp(a) && is_regexp_1.isRegExp(b)) { | ||
if (a instanceof RegExp && b instanceof RegExp) { | ||
return a.toString() === b.toString(); | ||
@@ -54,6 +52,6 @@ } | ||
}; | ||
const equivArrayLike = (a, b) => { | ||
exports.equivArrayLike = (a, b, _equiv = exports.equiv) => { | ||
let l = a.length; | ||
if (b.length === l) { | ||
while (--l >= 0 && exports.equiv(a[l], b[l])) | ||
if (l === b.length) { | ||
while (--l >= 0 && _equiv(a[l], b[l])) | ||
; | ||
@@ -63,13 +61,12 @@ } | ||
}; | ||
const equivSet = (a, b) => (a.size === b.size) && | ||
exports.equiv([...a.keys()].sort(), [...b.keys()].sort()); | ||
const equivMap = (a, b) => (a.size === b.size) && | ||
exports.equiv([...a].sort(), [...b].sort()); | ||
const equivObject = (a, b) => { | ||
const ka = Object.keys(a); | ||
if (ka.length !== Object.keys(b).length) | ||
exports.equivSet = (a, b, _equiv = exports.equiv) => (a.size === b.size) && | ||
_equiv([...a.keys()].sort(), [...b.keys()].sort()); | ||
exports.equivMap = (a, b, _equiv = exports.equiv) => (a.size === b.size) && | ||
_equiv([...a].sort(), [...b].sort()); | ||
exports.equivObject = (a, b, _equiv = exports.equiv) => { | ||
if (Object.keys(a).length !== Object.keys(b).length) { | ||
return false; | ||
for (let i = ka.length, k; --i >= 0;) { | ||
k = ka[i]; | ||
if (!b.hasOwnProperty(k) || !exports.equiv(a[k], b[k])) { | ||
} | ||
for (let k in a) { | ||
if (!b.hasOwnProperty(k) || !_equiv(a[k], b[k])) { | ||
return false; | ||
@@ -76,0 +73,0 @@ } |
{ | ||
"name": "@thi.ng/equiv", | ||
"version": "0.1.8", | ||
"version": "0.1.9", | ||
"description": "Extensible deep equivalence checking for any data types", | ||
@@ -25,2 +25,3 @@ "main": "./index.js", | ||
"@types/node": "^10.5.5", | ||
"benchmark": "^2.1.4", | ||
"mocha": "^5.2.0", | ||
@@ -31,5 +32,3 @@ "nyc": "^12.0.2", | ||
}, | ||
"dependencies": { | ||
"@thi.ng/checks": "^1.5.8" | ||
}, | ||
"dependencies": {}, | ||
"keywords": [ | ||
@@ -36,0 +35,0 @@ "deep", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22028
0
7
178
7
- Removed@thi.ng/checks@^1.5.8
- Removed@thi.ng/checks@1.5.14(transitive)