# `object-identity`

`npm add object-identity` hashes objects downloads size size

## ⚡ Features - ✅ **Intuitive** - 🌪 **Recursive/Circular support** - 🏎 **Performant** — check the [benchmarks](#-benchmark). - 🪶 **Lightweight** — a mere 387B and no [dependencies](https://npm.anvaka.com/#/view/2d/object-identity/). ## 🚀 Usage ```ts 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 [`/bench`](/bench) directory with Node v17.9.1 (Apple M1 Pro) ``` benchmark :: hashed object-hash x 56,899 ops/sec ±0.28% (99 runs sampled) object-identity^ x 500,733 ops/sec ±0.30% (98 runs sampled) benchmark :: passed through object-hash x 123,748 ops/sec ±0.22% (94 runs sampled) object-identity^ x 1,027,478 ops/sec ±0.18% (99 runs sampled) ``` > ^ `object-identity` is not as feature-full it's alternatives, specifically around `function` values 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](https://marais.io)