1.1.0 • Published 5 years ago

mobik v1.1.0

Weekly downloads
7
License
MIT
Repository
github
Last release
5 years ago

Mobik

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

:package: Installation

npm install mobik --save

:rocket: 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;

:bulb: 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.

1.1.0

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago