# lodash-unwind

> A very simple lodash extension that provide MongoDB $unwind feature

Latest version **1.2.3** (published 2019-01-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install lodash-unwind
pnpm add lodash-unwind
yarn add lodash-unwind
bun add lodash-unwind
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.3 |
| Published | 2019-01-17 |
| First published | 2019-01-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 12.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | Edwin Cen |
| Maintainers | edwincen |
| Keywords | unwind, lodash, extension |

## Links

- npm: https://www.npmjs.com/package/lodash-unwind
- Repository: https://github.com/edwincen/unwind
- Homepage: https://github.com/edwincen/unwind#readme
- Issues: https://github.com/edwincen/unwind/issues
- npm.io page: https://npm.io/package/lodash-unwind

## Dependencies (1)

- [lodash](https://npm.io/package/lodash.md) ^4.17.11

## Alternatives

- [lodash.assign](https://npm.io/package/lodash.assign.md) — 2.3M weekly downloads
- [lodash.chunk](https://npm.io/package/lodash.chunk.md) — 1.8M weekly downloads
- [react-native-ios-utilities](https://npm.io/package/react-native-ios-utilities.md) — 138.5K weekly downloads
- [@technically/lodash](https://npm.io/package/@technically/lodash.md) — 50.9K weekly downloads
- [@fluid-topics/ft-icon](https://npm.io/package/@fluid-topics/ft-icon.md) — 20.6K weekly downloads

## Recent versions

- 1.2.3 (latest) — 2019-01-17
- 1.2.2 — 2019-01-17
- 1.2.1 — 2019-01-10
- 1.2.0 — 2019-01-09
- 1.1.2 — 2019-01-09
- 1.1.1 — 2019-01-09

## README

# lodash-unwind

[![Build Status](https://travis-ci.com/edwincen/unwind.svg?branch=master)](https://travis-ci.com/edwincen/unwind) [![Greenkeeper badge](https://badges.greenkeeper.io/edwincen/unwind.svg)](https://greenkeeper.io/)
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)

Very simple unwind extension for lodash. And it's compatible with mongoose doc.

# Install

```javascript
npm install --save lodash-unwind
```
# Usage

```javascript
unwind(collection, path, [options={}])
```
### Arguments
- ```collection(Array|Object)``` - The collection or object to process.
- ```path(string)``` - The property path to unwind.
- ```[options={}](object)``` - The option object.
- ```[options.ignoreNonArray=true](boolean)``` - Specify whether ignore non-array element/property, default=true.
- ```[options.wrapAsArray=false]``` - Specify whether wrap unwinded value in array.

### Returns
```(Array)``` - Returns new unwinded collection.

### Sample

#### Unwind normal collection

```javascript
const unwind = require('lodash-unwind')()
const data = [
  {
    a: [ 1, 2 ],
    id: 'a1'
  },
  {
    a: [ 3, 4 ],
    id: 'a2'
  }
]
const output = unwind(data, 'a')
// [
//   {
//     a: 1,
//     id: 'a1'
//   },
//   {
//     a: 2,
//     id: 'a1'
//   },
//   {
//     a: 3,
//     id: 'a2'
//   },
//   {
//     a: 4,
//     id: 'a2'
//   }
// ]
```
#### Unwind collection with nested property

```javascript
const unwind = require('lodash-unwind')()
const data = [
  {
    a: {
        inner: [ 1, 2 ]
    },
    id: 'a1'
  },
  {
    a: {
        inner: [ 3, 4 ]
    },
    id: 'a2'
  }
]
const output = unwind(data, 'a')
// [
//   {
//     a: { inner: 1 },
//     id: 'a1'
//   },
//   {
//     a: { inner: 2 },
//     id: 'a1'
//   },
//   {
//     a: { inner: 3 },
//     id: 'a2'
//   },
//   {
//     a: { inner: 4 },
//     id: 'a2'
//   }
// ]
```

#### Unwind object
```javascript
const unwind = require('lodash-unwind')()
const data = {
  a: [ 1, 2 ],
  id: 'a1'
}
const output = unwind(data, 'a')
// [
//   {
//     a: 1,
//     id: 'a1'
//   },
//   {
//     a: 2,
//     id: 'a1'
//   }
// ]
```

#### Unwind with wrapAsArray=true
```javascript
const unwind = require('lodash-unwind')()
const data = {
  a: [ 1, 2 ],
  id: 'a1'
}
const output = unwind(data, 'a', { wrapAsArray: true })
// [
//   {
//     a: [1],
//     id: 'a1'
//   },
//   {
//     a: [2],
//     id: 'a1'
//   }
// ]
```

## Use unwind as module of lodash
```javascript
const _ = require('lodash')
require('lodash-unwind')({ injected: true })
const data = [
  {
    a: [ 1, 2 ],
    id: 'a1'
  },
  {
    a: [ 3, 4 ],
    id: 'a2'
  }
]
// Use unwind as part of lodash
const output = _.unwind(data, 'a')
```

---
_Source: https://npm.io/package/lodash-unwind · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
