npm package: @novigi/array
Description: Extending the Javascript Array operations to make objects handling a lot simpler 🔗
Author: Novigi
Latest version: 1.0.0-2

![npm (scoped)](https://img.shields.io/npm/v/@novigi/array) ![NPM](https://img.shields.io/npm/l/@novigi/array) ![Statements](https://img.shields.io/badge/statements-100%25-brightgreen.svg?style=flat) ![Branches](https://img.shields.io/badge/branches-100%25-brightgreen.svg?style=flat) ![Functions](https://img.shields.io/badge/functions-100%25-brightgreen.svg?style=flat) ![Lines](https://img.shields.io/badge/lines-100%25-brightgreen.svg?style=flat)
# @novigi/array

Extending the Javascript Array operations to make objects handling a lot simpler 🔗

## 🐿 Features

- Modify object arrays to contain only the given keys
- Modify object arrays to remove the keys provided
- Convert object arrays to JSON String
- Modify object arrays to filter elements with unique keys

## 📦 Getting Started

1. Install the dependency
```
npm install @novigi/array
```

2. Import the library
```
const lib = require('@novigi/array');
```

## 📖 Documentation

<a name="module_array"></a>

## array
Extending the Javascript Array operations to make objects handling a lot simpler 🔗

```js
require('@novigi/array');
[{id: 1, name: 'UserA', age: 33}, {id: 2, name: 'UserB', age: 32}].include(['id', 'name']) // [{"id": 1, "name": "UserA"}, {"id": 2, "name": "UserB"}]
[{id: 1, name: 'UserA', age: 33}, {id: 2, name: 'UserB', age: 32}].exclude(['age']) // [{"id": 1, "name": "UserA"}, {"id": 2, "name": "UserB"}]
```

Chainable + immutable methods! ☝


* [array](#module_array)
    * [~Array](#external_Array)
        * [.include(inclusions)](#external_Array+include) ⇒ <code>Array</code>
        * [.exclude(exclusions)](#external_Array+exclude) ⇒ <code>Array</code>
        * [.flatten()](#external_Array+flatten) ⇒ <code>Array</code>
        * [.toJson()](#external_Array+toJson) ⇒ <code>String</code>
        * [.unique(property)](#external_Array+unique) ⇒ <code>Array</code>

<a name="external_Array"></a>

### array~Array
Extension methods for built in Array object. Most of these methods are returning a new Array object so the API is
immutable and chainable.

**Kind**: inner external of [<code>array</code>](#module_array)  
**Example**  
```js
new Array().include(['key1', 'key2'])
new Array().exclude(['key1', 'key2'])
```

* [~Array](#external_Array)
    * [.include(inclusions)](#external_Array+include) ⇒ <code>Array</code>
    * [.exclude(exclusions)](#external_Array+exclude) ⇒ <code>Array</code>
    * [.flatten()](#external_Array+flatten) ⇒ <code>Array</code>
    * [.toJson()](#external_Array+toJson) ⇒ <code>String</code>
    * [.unique(property)](#external_Array+unique) ⇒ <code>Array</code>

<a name="external_Array+include"></a>

#### array.include(inclusions) ⇒ <code>Array</code>
Extension method for Array of objects to preserve only given keys

**Kind**: instance method of [<code>Array</code>](#external_Array)  
**Returns**: <code>Array</code> - an array of objects after filtering inclusions  

| Param | Type | Description |
| --- | --- | --- |
| inclusions | <code>Array</code> | an array of strings indicating the keys to preserve |

**Example**  
```js
[{id: 1, name: 'UserA', age: 33}, {id: 2, name: 'UserB', age: 32}].include(['id', 'name']) // [{"id": 1, "name": "UserA"}, {"id": 2, "name": "UserB"}]
```
<a name="external_Array+exclude"></a>

#### array.exclude(exclusions) ⇒ <code>Array</code>
Extension method for Array of objects to eliminate given keys

**Kind**: instance method of [<code>Array</code>](#external_Array)  
**Returns**: <code>Array</code> - an array of objects after filtering exclusions  

| Param | Type | Description |
| --- | --- | --- |
| exclusions | <code>Array</code> | an array of strings indicating the keys to remove |

**Example**  
```js
[{id: 1, name: 'UserA', age: 33}, {id: 2, name: 'UserB', age: 32}].exclude(['age']) // [{"id": 1, "name": "UserA"}, {"id": 2, "name": "UserB"}]
```
<a name="external_Array+flatten"></a>

#### array.flatten() ⇒ <code>Array</code>
Extension method for flattening the object array in to single−depth object array

**Kind**: instance method of [<code>Array</code>](#external_Array)  
**Returns**: <code>Array</code> - an array after flattening  
**Example**  
```js
[{ name: 'test', address: { personalId: 3, office: { buildingExists: true, street: 'some street' } } }].flatten() // [{ name: 'test', address_personalId: 3, address_office_buildingExists: true, address_office_street: 'some street' }]
[{ name: 'test', address: { street: ['some', 'street'] } }].flatten() // [{ name: 'test', address_street_0: 'some', address_street_1: 'street' }]
```
<a name="external_Array+toJson"></a>

#### array.toJson() ⇒ <code>String</code>
Extension method for return a JSON String version of an array object

**Kind**: instance method of [<code>Array</code>](#external_Array)  
**Returns**: <code>String</code> - JSON String after converting array object  
**Example**  
```js
[{id: 1, name: 'UserA', age: 33}, {id: 2, name: 'UserB', age: 32}].toJson() // '[{"id":1,"name":"UserA","age":33},{"id":2,"name":"UserB","age":32}]'
```
<a name="external_Array+unique"></a>

#### array.unique(property) ⇒ <code>Array</code>
Extension method for filter array elements with unique keys

**Kind**: instance method of [<code>Array</code>](#external_Array)  
**Returns**: <code>Array</code> - an array after filter elements with unique keys  

| Param | Type | Description |
| --- | --- | --- |
| property | <code>Array</code> | an array of strings indicating the keys to unique values |

**Example**  
```js
[ {id: 1, name: "UserA", age: 33}, {id: 2, name: "UserA", age: 32}, {id: 3, name: "UserC", age: 31} ].unique('name') // [ {id: 1, name: "UserA", age: 33}, {id: 3, name: "UserC", age: 31} ]
```

_This is an auto generated file. Please don't make changes manually_