- .github
- bench
- .editorconfig145 B
- .gitignore139 B
- index.spec.ts3.4 KB
- index.ts1.2 KB
- licence1.1 KB
- package.json636 B
- pnpm-lock.yaml12 KB
- readme.md2.1 KB
- rollup.config.js1.1 KB
- tsconfig.json218 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');
// Lets hash the object
const hashA = identify({ a: "b" }, hasher);
const hashB = identify({ a: "b" }, hasher);
expect(hashA).toEqual(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