SkillAgentSearch skills...

Polygoat

Make JavaScript functions that support both promise and callback styles.

Install / Use

/learn @sonnyp/Polygoat
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

polygoat

Build Status

logo

polygoat is a library to make functions support both callback and promise styles.

  • no dependencies
  • very small, < 30 lines of code
  • no promise support/polyfill required
  • simple, hack-free
  • Node.js and browsers
  • fast, see benchmark

Getting started

npm install polygoat


var pg = require("polygoat");

or

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

Usage

// wrap an asynchronous function with polygoat
function hybridReaddir(path, callback) {
  return pg(done => {
    fs.readdir(path, done);
  }, callback);
}

// hybridReaddir can be used as a promise
hybridReaddir("/").then(console.log);

// or with a callback
hybridReaddir("/", console.log);

// or with async/await
(async () => {
  console.log("listing...");
  console.log(await hybridReaddir("/"));
  console.log("done");
})();

// you can also pass the Promise implementation of your choice
var bluebird = require("bluebird");

function hybridReaddir(path, callback) {
  return pg(
    function(done) {
      fs.readdir(path, done);
    },
    callback,
    bluebird
  );
}

hybridReaddir() instanceof bluebird; // true

Example

See example.js

Benchmark

npm run benchmark

Test

npm test

Goat icon by Agne Alesiute from the Noun Project

Related Skills

View on GitHub
GitHub Stars154
CategoryCustomer
Updated9mo ago
Forks7

Languages

JavaScript

Security Score

87/100

Audited on Jun 9, 2025

No findings