single-batch

1.1.3 • Public • Published

Build Status Coverage

single-batch

Low level utility to handle single or batch methods.

Install

$ npm install single-batch

Usage

import wrap from 'single-batch'
 
const obj = {
  add: (a, b) => Promise.resolve(+ 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

// 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

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

License

MIT

Package Sidebar

Install

npm i single-batch

Weekly Downloads

96

Version

1.1.3

License

MIT

Unpacked Size

4.6 kB

Total Files

4

Last publish

Collaborators

  • kael