New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

smear

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

smear

Spread an array parameter to a function

latest
Source
npmnpm
Version
1.1.0
Version published
Maintainers
1
Created
Source

smear

Build Status

js-semistandard-style

smears (or spreads) a single array parameter across a function's arguments.

Note: if you're using an es6 runtime or compiler (such as babel), check out destructuring of parameters. It's a faster and prettier approach to the problem smear solves.

Smear turns a function that would normally take comma-separated parameters and turns it into one that takes a single parameter -- an array. Technically it unspreads the function.

This is particularly useful with promises, which must resolve to a single value (much like a synchronous return value). Some Promise implementations will add a .spread() function to the Promise prototype, but this is a non-standard interface and is incompatible with native promises.

Example

Turns this:

Promise.resolve([1, 2, 3]).then(function (args) {
  var one = args[0];
  var two = args[1];
  var three = args[2];
})

into this:

Promise.resolve([1, 2, 3]).then(spread(function (one, two, three) {
  console.log('much better!');
}));

API

function smear(fn)

fn - a function accepting a comma-separated list of parameters.

Smear returns a new function that accepts a single parameter of an array, and spreads it out to fn.

Keywords

promise

FAQs

Package last updated on 20 Oct 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts