Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/blakek/make-lookup
π Make a lookup object from an array of objects
https://github.com/blakek/make-lookup
functional-programming hash-lookup javascript lookup lookup-table map typescript
Last synced: 15 days ago
JSON representation
π Make a lookup object from an array of objects
- Host: GitHub
- URL: https://github.com/blakek/make-lookup
- Owner: blakek
- License: mit
- Created: 2020-06-02T16:41:32.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-03-04T21:52:16.000Z (almost 2 years ago)
- Last Synced: 2024-04-26T09:43:59.943Z (9 months ago)
- Topics: functional-programming, hash-lookup, javascript, lookup, lookup-table, map, typescript
- Language: JavaScript
- Homepage:
- Size: 1.98 MB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# make-lookup
> π Make a lookup object from an array of objects
Takes a list of items in an array an changes it to an object for fast access.
## Install
Using [Yarn]:
```bash
$ yarn add @blakek/make-lookup
```β¦or using [npm]:
```bash
$ npm i --save @blakek/make-lookup
```## Usage
```js
import { makeLookup } from '@blakek/make-lookup';const users = [
{ sites: { github: { username: 'blakek' } } },
{ sites: { github: { username: 'gsandf' } } },
{ sites: { github: { username: 'google' } } }
];const usersByUsername = makeLookup(users, 'sites.github.username');
console.log(usersByUsername.blakek);
// => { sites: { github: { username: 'blakek' } } }
```## API
### `makeLookup`
```ts
function makeLookup(
inputArray: any[],
lookupProperty: Array | string;
): Record;
```Creates a lookup object for a given array.
`lookupProperty` is a path to the property in either dot notation or an array of
path parts. See [blakek/deep] for details on this path.## Contributing
[Node.js] and [Yarn] are required to work with this project.
To install all dependencies, run:
```bash
yarn
```### Useful Commands
| | |
| ------------------- | ----------------------------------------------- |
| `yarn build` | Builds the project to `./dist` |
| `yarn format` | Format the source following the Prettier styles |
| `yarn test` | Run project tests |
| `yarn test --watch` | Run project tests, watching for file changes |## License
MIT
[blakek/deep]: https://github.com/blakek/deep
[node.js]: https://nodejs.org/
[npm]: https://npmjs.com/
[yarn]: https://yarnpkg.com/en/docs/