# unwrapper

> unwrap an array from a function that receives `err, result`

Latest version **1.1.0** (published 2016-06-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install unwrapper
pnpm add unwrapper
yarn add unwrapper
bun add unwrapper
```

## 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.1.0 |
| Published | 2016-06-24 |
| First published | 2015-11-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Jarrett Cruger |
| Maintainers | jcrugzz |
| Keywords | unwrap, api, arguments, array |

## Links

- npm: https://www.npmjs.com/package/unwrapper
- Repository: https://github.com/jcrugzz/unwrapper
- Homepage: https://github.com/jcrugzz/unwrapper#readme
- Issues: https://github.com/jcrugzz/unwrapper/issues
- npm.io page: https://npm.io/package/unwrapper

## Recent versions

- 1.1.0 (latest) — 2016-06-24
- 1.0.0 — 2015-11-10

## README

# unwrapper

[![build
status](https://secure.travis-ci.org/jcrugzz/unwrapper.svg)](http://travis-ci.org/jcrugzz/unwrapper)

A simple module that unwraps an array when deemed necessary for the result
passed to a given function. The threshold in which it is deemed necessary is
determined by the length of the array returned. A length of 1 is assumed to be
something you want unwrapped.

## install

```sh
npm i unwrapper --save
```

## Example

```js
var unwrap = require('unwrapper');
var api = require('./api');

//
// Pretend this API returns an [] even when you expect it to be a single entity
//
api.get('/books-by', 'barney rubble', unwrap(function (err, result) {
  // expect `result` to be a single object.
}));
```

## API

``` js
unwrap(fn, def, pred)
unwrap(fn, pred)
unwrap(fn);
```

* `fn`: Function to execute
* `def`: **Optional** Default value to use if no results returned
* `pred`: Predicate function for more advanced decisions than an Array of length `1`

#### Advanced usage

In some scenarios you may want to only unwrap certain Arrays of length one (e.g. listing directories of a length 1). In this case you can pass a `pred` argument to `unwrapper`:

``` js
unwrap(fn, function (err, result) {
  //
  // Result will always be the first element in the Array
  // - return true to unwrap
  // - return false to NOT unwrap
  //
  return result.expected === 'some-expected-value';
});
```

##### Author: [Jarrett Cruger](https://github.com/jcrugzz)

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