https://github.com/pakastin/lookup
create lookup tables easily
https://github.com/pakastin/lookup
javascript lookup-table
Last synced: 3 months ago
JSON representation
create lookup tables easily
- Host: GitHub
- URL: https://github.com/pakastin/lookup
- Owner: pakastin
- Created: 2016-07-06T13:05:36.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-01-19T09:18:56.000Z (over 8 years ago)
- Last Synced: 2025-04-07T13:41:13.029Z (6 months ago)
- Topics: javascript, lookup-table
- Language: JavaScript
- Size: 10.7 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# lookup
create lookup tables easily## install
```
npm install @pakastin/lookup
```- production (UMD): https://pakastin.github.io/lookup/lookup.min.js
- ES2015 module: https://pakastin.github.io/lookup/lookup.es.js
- development (UMD): https://pakastin.github.io/lookup/lookup.js## lookup(items, key, [reverse])
- items(Array): items to iterate
- key(String): which key value to use for lookup
- reverse(Boolean): is there multiple items / key value?## usage (ES2015 module)
```js
import lookup from '@pakastin/lookup';const users = [ { _id: 1, level: 1, name: 'A' }, { _id: 2, level: 1, name: 'B' }, { _id: 3, name: 'C' } ];
const userLookup = lookup(users, '_id');
const userLevelLookup = lookup(users, 'level', true); // reverse lookupconsole.log(userLookup[1]) // --> { _id: 1, name: 'A' }
console.log(userLevelLookup[1]) // --> [ {_id: 1, level: 1, name: 'A' }, { _id: 2, level: 1, name: 'B' } ]
```## with commonjs:
```js
const lookup = require('@pakastin/lookup');
...
```## oldskool:
```html...
const userLookup = lookup(users, '_id');
...```