Skip to content
Tiny Array utility for merging an array of objects by a given key
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
.babelrc
.gitignore
.npmignore
.nvmrc
.travis.yml
README.md
index.test.js
package-lock.json
package.json
rollup.config.js

README.md

MOBIK

Mobik

Fast 273 bytes Array utility for merging an array of objects by a given key.

📦 Installation

npm install mobik --save

🚀 Load

// using es modules
import mobik from 'mobik'

// common.js
const mobik = require('mobik')

Or use script tags and globals.

<script src="https://unpkg.com/mobik"></script>

And then grab it off the global like so:

const mobik = mobik.default;

💡 Usage

Let's assume you want to group a set of objects in an array by key

const newArray = mobik('a', [{a: 1, b: 2}, {c: 3, a: 1}]);

/*
[
  {
    a: 1,
    b: 2,
    c: 3
  }
]
*/

It works with nested objects too!

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.

You can’t perform that action at this time.