Skip to content

asmartbear/objectid

Repository files navigation

objectId

Extremely tiny package (253 bytes uncompressed) for no-side-effect attaching unique IDs to Javascript objects.

IDs are stored in a WeakMap, so there's no alteration of the object in question (therefore cannot affect other code), but also without affecting GC.

Supports IDs only for objects (including functions and arrays). IDs are based on the object "pointer," not based on the data inside the object. If you need to hash other data structures, you'll need to use a different hashing library.

Usage

const a = {};
const b = {};
console.log(objectId(a));     // 1
console.log(objectId(b));     // 2
console.log(objectId(a));     // 1
console.log(objectId(null));  // 0

Development

Build:

npm run build

Unit tests:

npm run test

Unit tests, refreshed live:

npm run watch

Prepare for release (e.g. run tests and bump version number):

npm run release

Publish to npm:

npm publish

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published