- .github
- bench
- src
- test
- .editorconfig145 B
- .gitignore139 B
- licence1.1 KB
- package.json600 B
- pnpm-lock.yaml16 KB
- readme.md2.2 KB
- tsconfig.json323 B
readme.md
⚡ Features
- ✅ Intuitive
- 🌪 Recursive/Circular support
- 🏎 Performant — check the benchmarks.
- 🪶 Lightweight — a mere 503B and no dependencies.
🚀 Usage
import { createHash } from 'node:crypto';
import { identify } from 'object-identity';
// ~> Some user defined hasher
const hasher = (value) => createHash('sha1').update(value).digest('hex');
// ~> identity the object
const hashA = identify({ a: new Set(['b', 'c', new Map([['d', 'e']])]) }, hasher);
// ~> an entirely different object, but structurally the same
const hashB = identify({ a: new Set(['b', 'c', new Map([['e', 'e']])]) }, hasher);
// they should equal
assert.toEqual(hashA, hashB);
💨 Benchmark
via the
/benchdirectory with Node v17.4.0
benchmark :: hashed
object-hash x 25,773 ops/sec ±2.49% (89 runs sampled)
object-identity^ x 270,940 ops/sec ±1.28% (92 runs sampled)
benchmark :: passed through
object-hash x 65,894 ops/sec ±0.81% (89 runs sampled)
object-identity^ x 775,302 ops/sec ±0.29% (95 runs sampled)
^
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