# identifiable

> Generate unique ids for things and look them up on hashes

Latest version **0.15.0** (published 2018-11-02) · 0 weekly downloads

## Install

```sh
npm install identifiable
pnpm add identifiable
yarn add identifiable
bun add identifiable
```

## Health

**Score 10/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; low quality score; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.15.0 |
| Published | 2018-11-02 |
| First published | 2017-02-05 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | erikpukinskis |

## Links

- npm: https://www.npmjs.com/package/identifiable
- Repository: https://github.com/erikpukinskis/identifiable
- Homepage: https://github.com/erikpukinskis/identifiable#readme
- Issues: https://github.com/erikpukinskis/identifiable/issues
- npm.io page: https://npm.io/package/identifiable

## Dependencies (1)

- [module-library](https://npm.io/package/module-library.md) *

## Recent versions

- 0.15.0 (latest) — 2018-11-02
- 0.14.0 — 2018-11-02
- 0.13.0 — 2018-11-02
- 0.12.0 — 2018-01-09
- 0.11.0 — 2017-08-29
- 0.10.0 — 2017-08-03
- 0.9.0 — 2017-08-03
- 0.8.0 — 2017-08-01
- 0.7.0 — 2017-07-25
- 0.6.0 — 2017-07-23
- 0.5.0 — 2017-07-23
- 0.4.0 — 2017-02-18
- 0.3.0 — 2017-02-07
- 0.2.0 — 2017-02-05
- 0.1.0 — 2017-02-05

## README

If you don't need a query engine or persistence, **identifiable** can help you store a set of objects referenced by unique IDs:

```javascript
var identifiable = require("identifiable")
var expect = require("chai").expect

var erik = {
  name: "Erik",
  likes: ["rollerblading", "cooking from scratch", "chickens"]
}

var people = {}

var get = identifiable.getFrom(people, "person")

var id = identifiable.assignId(people)
people[id] = erik
var result = get(id)

expect(result).to.equal(erik)
```

It does almost nothing. It generates unique IDs. It throws an error when it can't find an item with that id.

### Allowing getters to return undefined

If you pass `true` to a getter, it will just return undefined if the record isn't found. Otherwise an error gets thrown.

```javascript
var maybeErik = get(id, true)
```

### Providing a pre-existing ID

Sometimes, if you're maybe reseeding a store of items that already have IDs assigned and being used in the wild, you want to make sure you can keep using those same ids.

This works just fine, assignId will take an id:

```javascript
var id = identifiable.assignId(people, "gfa0")
```

This will throw an error if the ID is already in use, but otherwise it will use the provided ID. If you pass something `null`-like, it will assign a new, unused ID.


### Giving IDs a prefix

It can be nice to be able to tell different IDs for different purposes apart at a glance. The third parameter to assignId can be a prefix:

```javascript
var id = identifiable.assignId(people, null, "ppl")
// id is ppl-fjst
```

### Why

A database is overkill if you just need a hash of items. Not everything needs a persistence AI backing it up.

This module is basically boilerplate, but it's boilerplate that you pretty much always need when you're indexing something by ID. So it's kind of not worth copy/pasting.

IDs are kind of always a security concern. In the future, perhaps this module can provide some assurances about the entropy in an ID.

---
_Source: https://npm.io/package/identifiable · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
