Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

polygoat

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

polygoat

Make a JavaScript function support both promise and callback styles.

  • 1.1.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
718
decreased by-5.15%
Maintainers
1
Weekly downloads
 
Created
Source

polygoat

logo

Make a JavaScript function support both promise and callback styles.

Build Status js-standard-style

This is great if you want to offer your users the choice between the two. It is also an elegant way to support older platforms without Promise support and let the users decide if they want to add a Promise polyfill.

Getting started

npm install polygoat


var pg = require('polygoat');

or

<script src="node_modules/polygoat/index.js"></script>
var pg = window.polygoat

Usage

// wrap and expose your asynchronous function with polygoat
function myFunction (some, arg, callback) {
  return pg(function (done) {
    doSomethingAsync(some, arg, done)
  }, callback)
}

// myFunction can now be used with promise style
myFunction('foo', 'bar').then(console.log)

// or callback style
myFunction('foo', 'bar', console.log)

// you can also pass the Promise implementation you wish polygoat to use
var bluebird = require('bluebird')

function myFunction (callback) {
  return pg(function (done) {
    doSomethingAsync(done)
  }, callback, bluebird)
}

myFunction() instanceof bluebird // true

Example

See example.js

Test

npm install standard
npm test

Goat icon by Agne Alesiute from the Noun Project

Keywords

FAQs

Package last updated on 14 Apr 2016

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc