maraisr/object-identityPublic

readme.md

object-identity

A utility that provides a stable identity of an object

js downloads licenses gzip size brotli size

This is free to use software, but if you do like it, consisder supporting me ❤️

sponsor me buy me a coffee

⚡ Features

  • ✅ Intuitive
  • 🌪 Recursive/Circular support
  • 🏎 Performant — check the benchmarks.
  • 🪶 Lightweight — a mere 387B and no dependencies.

🚀 Usage

import { identify } from 'object-identity';

// ~> identity the object
const id1 = identify({ a: new Set(['b', 'c', new Map([['d', 'e']])]) });
// ~> an entirely different object, but structurally the same
const id2 = identify({ a: new Set(['b', 'c', new Map([['e', 'e']])]) });

// they should equal
assert.toEqual(hashA, hashB);

💨 Benchmark

via the /bench directory with Node v18.16.1 (Apple M1 Pro)

✔ object-identity       ~ 55,252,648 ops/sec ± 0.11%
✔ object-hash           ~     96,936 ops/sec ± 0.01%
✔ json-stable-stringify ~    605,425 ops/sec ± 0.02%

^ 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