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

node-callback-adapter

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

node-callback-adapter

Adapt Promise returning functions to optionally accept Node-style callbacks as last argument

latest
Source
npmnpm
Version
1.0.1
Version published
Maintainers
1
Created
Source

node callback adapter decorator

This is a function/method decorator which is when applied to a function which returns a promise makes it to handle optionally passed Node-style callback as last argument.

As decorators are a part of future ES7 standard they can only be used with transpilers such as Babel.

Installation:

% npm install node-callback-adapter

Example usage as a method decorator:

import adapt from 'node-callback-adapter'

class Component {

  @adapt
  add(x, y) {
    return Promise.resolve(x + y)
  }
}

let component = new Component()

// call without callback and get a promise back
component.add(2, 2).then(four => console.log(four))

// call with a callback
component.add(2, 2, function(err, four) {
  console.log(four)
})

Example usage as a function decorator:

import {adaptFunction} from 'node-callback-adapter'

let add = adaptFunction(function add(x, y) {
  return Promise.resolve(x + y)
})

// call without callback and get a promise back
add(2, 2).then(four => console.log(four))

// call with a callback
add(2, 2, function(err, four) {
  console.log(four)
})

Keywords

decorator

FAQs

Package last updated on 12 Apr 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