mirror: A fast canonicalisation utility for stable object equality
0

Configure Feed

Select the types of activity you want to include in your feed.

75 1 9

Clone this repository

https://tangled.org/mr.cv/object-identity https://tangled.org/did:plc:doulxtjknvg7e5ngws5scb4y
git@git.local.to:mr.cv/object-identity git@git.local.to:did:plc:doulxtjknvg7e5ngws5scb4y

For self-hosted knots, clone URLs may differ based on your setup.



readme.md

object-identity licenses#

A utility that provides a stable identity of an object



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

sponsor me buy me a coffee

⚡ Features#

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

⚙️ Install#

🚀 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#

| benchmark               | time/iter (avg) |        iter/s |      (min … max)      |      p75 |      p99 |     p995 |
| ----------------------- | --------------- | ------------- | --------------------- | -------- | -------- | -------- |
| object-identity         |        573.0 ns |     1,745,000 | (540.1 ns … 607.1 ns) | 585.2 ns | 607.1 ns | 607.1 ns |
| object-hash             |          6.7 µs |       149,000 | (  6.2 µs … 164.9 µs) |   6.5 µs |   8.0 µs |  21.2 µs |
| json-stable-stringify   |          1.7 µs |       588,400 | (  1.6 µs …   2.9 µs) |   1.6 µs |   2.9 µs |   2.9 µs |
| tiny-stable-stringify   |          1.6 µs |       639,600 | (  1.5 µs …   1.6 µs) |   1.6 µs |   1.6 µs |   1.6 µs |

summary
  object-identity
     2.73x faster than tiny-stable-stringify
     2.97x faster than json-stable-stringify
    11.71x faster than object-hash

^ object-identity only handles JSON-like data by design. It won't fingerprint functions or every Node builtin the way some alternatives do, so these numbers only reflect the payloads it targets.

License#

MIT © Marais Rossouw