Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/janeklb/get-id
Keep track of your JS objects (and functions) via a unique id.
https://github.com/janeklb/get-id
Last synced: about 1 month ago
JSON representation
Keep track of your JS objects (and functions) via a unique id.
- Host: GitHub
- URL: https://github.com/janeklb/get-id
- Owner: janeklb
- Created: 2016-09-23T09:11:09.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-09-23T09:42:25.000Z (over 8 years ago)
- Last Synced: 2024-11-04T09:37:49.641Z (about 2 months ago)
- Language: JavaScript
- Homepage:
- Size: 3.91 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# get-id
[![Build Status](https://travis-ci.org/janeklb/get-id.svg?branch=master)](https://travis-ci.org/janeklb/get-id)
Keep track of your JS objects (and functions) via a unique id.
Install:
```bash
npm install --save get-id
```Usage:
```javascript
import getid from 'get-id'
// or:
// var getid = require('get-id');var object = {},
object2 = {};var objid = getid(object);
var obj2id = getid(object2);objid === getid(object);
obj2id === getid(object2);```
### What's happening?
`getid` assigns an id (int) to a non-enumerable, non-writable property on the
passed object or function under the key `__object_id__`, and then returns it.### Using a custom id property name
If for whatever reason you don't want to use the `__object_id__` key, you can
generate a custom `getid` function using the exported `create` function:
```javascript
import { create as create_getid } from 'get-id';const customgetid = create_getid('__this_is_a_custom_key');
const object = {};
const objectid = customgetid(object);objectid === object['__this_is_a_custom_key'];
```