# single-batch

> Low level utility to handle single or batch methods.

Latest version **1.1.3** (published 2018-07-31) · MIT license · 0 weekly downloads

## Install

```sh
npm install single-batch
pnpm add single-batch
yarn add single-batch
bun add single-batch
```

## 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.3 |
| Published | 2018-07-31 |
| First published | 2017-09-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=4 |
| Dependencies | 0 |
| Unpacked size | 4.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | kaelzhang |
| Maintainers | kael |
| Keywords | single-batch, promise, async, single, batch |

## Links

- npm: https://www.npmjs.com/package/single-batch
- Repository: https://github.com/kaelzhang/node-single-batch
- Homepage: https://github.com/kaelzhang/node-single-batch#readme
- Issues: https://github.com/kaelzhang/node-single-batch/issues
- npm.io page: https://npm.io/package/single-batch

## Alternatives

- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads
- [fa](https://npm.io/package/fa.md) — 185 weekly downloads

## Recent versions

- 1.1.3 (latest) — 2018-07-31
- 1.1.2 — 2017-12-08
- 1.1.1 — 2017-11-30
- 1.1.0 — 2017-09-18
- 1.0.3 — 2017-09-18
- 1.0.2 — 2017-09-18
- 1.0.1 — 2017-09-18
- 1.0.0 — 2017-09-18
- 0.0.0 — 2017-09-18

## README

[![Build Status](https://travis-ci.org/kaelzhang/node-single-batch.svg?branch=master)](https://travis-ci.org/kaelzhang/node-single-batch)
[![Coverage](https://codecov.io/gh/kaelzhang/node-single-batch/branch/master/graph/badge.svg)](https://codecov.io/gh/kaelzhang/node-single-batch)
<!-- optional appveyor tst
[![Windows Build Status](https://ci.appveyor.com/api/projects/status/github/kaelzhang/node-single-batch?branch=master&svg=true)](https://ci.appveyor.com/project/kaelzhang/node-single-batch)
-->
<!-- optional npm version
[![NPM version](https://badge.fury.io/js/single-batch.svg)](http://badge.fury.io/js/single-batch)
-->
<!-- optional npm downloads
[![npm module downloads per month](http://img.shields.io/npm/dm/single-batch.svg)](https://www.npmjs.org/package/single-batch)
-->
<!-- optional dependency status
[![Dependency Status](https://david-dm.org/kaelzhang/node-single-batch.svg)](https://david-dm.org/kaelzhang/node-single-batch)
-->

# single-batch

Low level utility to handle single or batch methods.

## Install

```sh
$ npm install single-batch
```

## Usage

```js
import wrap from 'single-batch'

const obj = {
  add: (a, b) => Promise.resolve(a + b)
}

const wrapped = wrap('add', null, obj)

wrapped.single(1, 2).then(console.log)            // 3
wrapped.batch([1, 2], [2, 3]).then(console.log)   // [3, 4]
```

## wrap(single, batch, context, singleArg)

- **single** `function()`
- **batch** `function()`
- **context** `Object=`
- **singleArg** `Boolean=false`

Returns

- `null` if single and batch methods are both unavailable
- `{single: function, batch: function}`

### singleArg

If true, then `wrapped.single` only accept one argument, and each argument of `wrapped.batch` corresponds to the argument of `wrapped.single`

```js
// singleArg: true
wrapped.single(1)
wrapped.batch(1, 2, 3)

wrapped.single([1, 2])
wrapped.batch([1, 2], [2, 3])
```

If false, `wrapped.single` accept multiple arguments, and each argument of `wrapped.batch` must be an array which represents the arguments of `wrapped.single`

```js
wrapped.single(1, 2)
wrapped.batch([1, 2], [2, 3])

wrapped.single([1, 2])
wrapped.batch([[1, 2]], [[2, 3]])
```

## License

MIT

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