Make JavaScript functions that support both promise and callback styles.
npm install polygoatpolygoat
========


!logo
polygoat is a tool to make functions support both callback and promise style.
* very small, < 30 lines of code
* no promise support/polyfill required
* simple, hack-free
* Node.js and browsers
* fast, see benchmark
npm install polygoat
----
``javascript`
var pg = require('polygoat');
or
`xml``javascript`
var pg = window.polygoat
`js
// wrap an asynchronous function with polygoat
function hybridFunction (path, callback) {
return pg(function (done) {
fs.readdir(path, done)
}, callback)
}
// hybridFunction can be used with promise style
hybridFunction('/').then(console.log)
// or callback style
hybridFunction('/', console.log)
// you can also pass the Promise implementation of your choice
var bluebird = require('bluebird')
function hybridFunction (path, callback) {
return pg(function (done) {
fs.readdir(path, done)
}, callback, bluebird)
}
hybridFunction() instanceof bluebird // true
`
See example.js
See benchmark
```
npm install standard
npm test
Goat icon by Agne Alesiute from the Noun Project