0.1.2 ā¢ Published 10 months ago
object-identity v0.1.2
object-identity
npm add object-identity
hashes objects
ā” 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 ~ 53,216,325 ops/sec Ā± 0.34%
ā object-hash ~ 110,440 ops/sec Ā± 0.01%
ā object-identity :: hashed ~ 45,415,100 ops/sec Ā± 0.05%
ā object-hash :: hashed ~ 51,365 ops/sec Ā± 0.01%
^
object-identity
is not as feature-full it's alternatives, specifically aroundfunction
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