Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zanonnicola/mobik
Tiny Array utility for merging an array of objects by a given key
https://github.com/zanonnicola/mobik
array-manipulations es6 js library nodejs
Last synced: about 1 month ago
JSON representation
Tiny Array utility for merging an array of objects by a given key
- Host: GitHub
- URL: https://github.com/zanonnicola/mobik
- Owner: zanonnicola
- Created: 2018-12-05T22:00:23.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2018-12-06T17:19:21.000Z (about 6 years ago)
- Last Synced: 2024-10-28T10:51:45.662Z (about 2 months ago)
- Topics: array-manipulations, es6, js, library, nodejs
- Language: JavaScript
- Size: 377 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Mobik
Fast **273 bytes** `Array` utility for merging an array of objects by a given key.
## :package: Installation
```bash
npm install mobik --save
```## :rocket: Load
```js
// using es modules
import mobik from 'mobik'// common.js
const mobik = require('mobik')```
Or use script tags and globals.
```html
```
And then grab it off the global like so:
```js
const mobik = mobik.default;
```## :bulb: Usage
Let's assume you want to group a set of objects in an array by key
```javascript
const newArray = mobik('a', [{a: 1, b: 2}, {c: 3, a: 1}]);/*
[
{
a: 1,
b: 2,
c: 3
}
]
*/
```> It works with nested objects too!
```javascript
const newArray = mobik('a', [{a: 1, b: 2}, {c: {d: 4}, a: 1}]);/*
[
{
a: 1,
b: 2,
c: {
d: 4
}
}
]
*/
```## API
#### `mobik(key: String, array: Array)` [required]
Returns an `Array` with a merged `Object`
OR `[]` when no key is found.
## Tests
`npm test`
## Legal
Released under MIT license.