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 - npm Package Compare versions

Comparing version 1.1.3 to 1.1.4

16

package.json
{
"name": "polygoat",
"version": "1.1.3",
"description": "Make a JavaScript function support both promise and callback styles.",
"version": "1.1.4",
"description": "Make JavaScript functions that support both promise and callback styles.",
"homepage": "https://github.com/sonnyp/polygoat",

@@ -12,5 +12,10 @@ "bugs": "https://github.com/sonnyp/polygoat/issues",

"promise",
"callback"
"callback",
"hybrid",
"hybridify",
"promisify",
"thenify"
],
"scripts": {
"benchmark": "node benchmark/benchmark.js",
"preversion": "npm test",

@@ -23,4 +28,7 @@ "lint": "standard",

"devDependencies": {
"bluebird": "^3.3.4"
"benchmark": "^2.1.0",
"bluebird": "^3.3.4",
"lodash": "^4.11.1",
"platform": "^1.3.1"
}
}
polygoat
========
[![Build Status](https://img.shields.io/travis/sonnyp/polygoat/master.svg?style=flat-square)](https://travis-ci.org/sonnyp/polygoat/branches)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](http://standardjs.com/)
![logo](./logo.png)
Make a JavaScript function support both promise and callback styles.
polygoat is a tool to make functions support both callback and promise style.
[![Build Status](https://img.shields.io/travis/sonnyp/polygoat/master.svg?style=flat-square)](https://travis-ci.org/sonnyp/polygoat/branches)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](http://standardjs.com/)
* very small, < 30 lines of code
* no promise support/polyfill required
* simple, hack-free
* Node.js and browsers
* fast, see [benchmark](#benchmark)
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

@@ -36,25 +40,25 @@

```js
// wrap and expose your asynchronous function with polygoat
function myFunction (some, arg, callback) {
// wrap an asynchronous function with polygoat
function hybridFunction (path, callback) {
return pg(function (done) {
doSomethingAsync(some, arg, done)
fs.readdir(path, done)
}, callback)
}
// myFunction can now be used with promise style
myFunction('foo', 'bar').then(console.log)
// hybridFunction can be used with promise style
hybridFunction('/').then(console.log)
// or callback style
myFunction('foo', 'bar', console.log)
hybridFunction('/', console.log)
// you can also pass the Promise implementation you wish polygoat to use
// you can also pass the Promise implementation of your choice
var bluebird = require('bluebird')
function myFunction (callback) {
function hybridFunction (path, callback) {
return pg(function (done) {
doSomethingAsync(done)
fs.readdir(path, done)
}, callback, bluebird)
}
myFunction() instanceof bluebird // true
hybridFunction() instanceof bluebird // true
```

@@ -66,2 +70,6 @@

# Benchmark
See [benchmark](https://github.com/sonnyp/polygoat/tree/master/benchmark)
# Test

@@ -68,0 +76,0 @@

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