@thi.ng/equiv
Advanced tools
Comparing version 2.1.36 to 2.1.37
# Change Log | ||
- **Last updated**: 2023-12-09T19:12:03Z | ||
- **Last updated**: 2023-12-11T10:07:09Z | ||
- **Generator**: [thi.ng/monopub](https://thi.ng/monopub) | ||
@@ -5,0 +5,0 @@ |
128
index.js
const OBJP = Object.getPrototypeOf({}); | ||
const FN = "function"; | ||
const STR = "string"; | ||
export const equiv = (a, b) => { | ||
let proto; | ||
if (a === b) { | ||
return true; | ||
const equiv = (a, b) => { | ||
let proto; | ||
if (a === b) { | ||
return true; | ||
} | ||
if (a != null) { | ||
if (typeof a.equiv === FN) { | ||
return a.equiv(b); | ||
} | ||
if (a != null) { | ||
if (typeof a.equiv === FN) { | ||
return a.equiv(b); | ||
} | ||
} else { | ||
return a == b; | ||
} | ||
if (b != null) { | ||
if (typeof b.equiv === FN) { | ||
return b.equiv(a); | ||
} | ||
else { | ||
return a == b; | ||
} | ||
if (b != null) { | ||
if (typeof b.equiv === FN) { | ||
return b.equiv(a); | ||
} | ||
} | ||
else { | ||
return a == b; | ||
} | ||
if (typeof a === STR || typeof b === STR) { | ||
return false; | ||
} | ||
if (((proto = Object.getPrototypeOf(a)), proto == null || proto === OBJP) && | ||
((proto = Object.getPrototypeOf(b)), proto == null || proto === OBJP)) { | ||
return equivObject(a, b); | ||
} | ||
if (typeof a !== FN && | ||
a.length !== undefined && | ||
typeof b !== FN && | ||
b.length !== undefined) { | ||
return equivArrayLike(a, b); | ||
} | ||
if (a instanceof Set && b instanceof Set) { | ||
return equivSet(a, b); | ||
} | ||
if (a instanceof Map && b instanceof Map) { | ||
return equivMap(a, b); | ||
} | ||
if (a instanceof Date && b instanceof Date) { | ||
return a.getTime() === b.getTime(); | ||
} | ||
if (a instanceof RegExp && b instanceof RegExp) { | ||
return a.toString() === b.toString(); | ||
} | ||
// NaN | ||
return a !== a && b !== b; | ||
} else { | ||
return a == b; | ||
} | ||
if (typeof a === STR || typeof b === STR) { | ||
return false; | ||
} | ||
if ((proto = Object.getPrototypeOf(a), proto == null || proto === OBJP) && (proto = Object.getPrototypeOf(b), proto == null || proto === OBJP)) { | ||
return equivObject(a, b); | ||
} | ||
if (typeof a !== FN && a.length !== void 0 && typeof b !== FN && b.length !== void 0) { | ||
return equivArrayLike(a, b); | ||
} | ||
if (a instanceof Set && b instanceof Set) { | ||
return equivSet(a, b); | ||
} | ||
if (a instanceof Map && b instanceof Map) { | ||
return equivMap(a, b); | ||
} | ||
if (a instanceof Date && b instanceof Date) { | ||
return a.getTime() === b.getTime(); | ||
} | ||
if (a instanceof RegExp && b instanceof RegExp) { | ||
return a.toString() === b.toString(); | ||
} | ||
return a !== a && b !== b; | ||
}; | ||
export const equivArrayLike = (a, b, _equiv = equiv) => { | ||
let l = a.length; | ||
if (l === b.length) { | ||
while (l-- > 0 && _equiv(a[l], b[l])) | ||
; | ||
} | ||
return l < 0; | ||
const equivArrayLike = (a, b, _equiv = equiv) => { | ||
let l = a.length; | ||
if (l === b.length) { | ||
while (l-- > 0 && _equiv(a[l], b[l])) | ||
; | ||
} | ||
return l < 0; | ||
}; | ||
export const equivSet = (a, b, _equiv = equiv) => a.size === b.size && _equiv([...a.keys()].sort(), [...b.keys()].sort()); | ||
export const equivMap = (a, b, _equiv = equiv) => a.size === b.size && _equiv([...a].sort(), [...b].sort()); | ||
export const equivObject = (a, b, _equiv = equiv) => { | ||
if (Object.keys(a).length !== Object.keys(b).length) { | ||
return false; | ||
const equivSet = (a, b, _equiv = equiv) => a.size === b.size && _equiv([...a.keys()].sort(), [...b.keys()].sort()); | ||
const equivMap = (a, b, _equiv = equiv) => a.size === b.size && _equiv([...a].sort(), [...b].sort()); | ||
const equivObject = (a, b, _equiv = equiv) => { | ||
if (Object.keys(a).length !== Object.keys(b).length) { | ||
return false; | ||
} | ||
for (let k in a) { | ||
if (!b.hasOwnProperty(k) || !_equiv(a[k], b[k])) { | ||
return false; | ||
} | ||
for (let k in a) { | ||
if (!b.hasOwnProperty(k) || !_equiv(a[k], b[k])) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
return true; | ||
}; | ||
export { | ||
equiv, | ||
equivArrayLike, | ||
equivMap, | ||
equivObject, | ||
equivSet | ||
}; |
{ | ||
"name": "@thi.ng/equiv", | ||
"version": "2.1.36", | ||
"version": "2.1.37", | ||
"description": "Extensible deep value equivalence checking for any data types", | ||
@@ -27,3 +27,5 @@ "type": "module", | ||
"scripts": { | ||
"build": "yarn clean && tsc --declaration", | ||
"build": "yarn build:esbuild && yarn build:decl", | ||
"build:decl": "tsc --declaration --emitDeclarationOnly", | ||
"build:esbuild": "esbuild --format=esm --platform=neutral --target=es2022 --tsconfig=tsconfig.json --outdir=. src/**/*.ts", | ||
"clean": "rimraf --glob '*.js' '*.d.ts' '*.map' doc", | ||
@@ -38,2 +40,3 @@ "doc": "typedoc --excludePrivate --excludeInternal --out doc src/index.ts", | ||
"@microsoft/api-extractor": "^7.38.3", | ||
"esbuild": "^0.19.8", | ||
"rimraf": "^5.0.5", | ||
@@ -71,3 +74,3 @@ "tools": "^0.0.1", | ||
}, | ||
"gitHead": "25f2ac8ff795a432a930119661b364d4d93b59a0\n" | ||
"gitHead": "5e7bafedfc3d53bc131469a28de31dd8e5b4a3ff\n" | ||
} |
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
22678
6