- .github
- bench
- src
- test
- .editorconfig145 B
- .gitignore139 B
- license1.1 KB
- package.json756 B
- pnpm-lock.yaml19 KB
- readme.md2.2 KB
- tsconfig.json296 B
readme.md
⚡ Features
- ✅ Intuitive
- 🌪 Recursive/Circular support
- 🏎 Performant — check the benchmarks.
- 🪶 Lightweight — a mere 387B and no dependencies.
🚀 Usage
import { createHash } from "node:crypto";
import { identify } from "object-identity";
// ~> Some user defined hasher
const hash = (value) => {
const id = identify(value);
return createHash("sha1").update(id).digest("hex");
};
// ~> identity the object
const hashA = hash({ a: new Set(["b", "c", new Map([["d", "e"]])]) });
// ~> an entirely different object, but structurally the same
const hashB = hash({ a: new Set(["b", "c", new Map([["e", "e"]])]) });
// they should equal
assert.toEqual(hashA, hashB);
💨 Benchmark
via the
/benchdirectory with Node v16.20.0 (Apple M1 Pro)
★ object-identity ~ 40,170,767 ops/sec ± 0.46%
object-hash ~ 135,713 ops/sec ± 0.01%
object-identity :: hashed ~ 32,349,659 ops/sec ± 0.11%
object-hash :: hashed ~ 58,381 ops/sec ± 0.01%
^
object-identityis not as feature-full it's alternatives, specifically aroundfunctionvalues and other node builtins. So take this benchmark with a grain of salt, as it's only testing "json-like" payloads.
License
MIT © Marais Rossouw