• Stars
    star
    154
  • Rank 242,095 (Top 5 %)
  • Language
    JavaScript
  • License
    ISC License
  • Created over 8 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Make JavaScript functions that support both promise and callback styles.

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

More Repositories

1

Tangram

Browser for your pinned tabs
JavaScript
905
star
2

aria2.js

JavaScript library for aria2, "The next generation download utility."
JavaScript
608
star
3

Workbench

Code playground for GNOME 🛠️
JavaScript
524
star
4

Junction

Application/browser chooser
JavaScript
467
star
5

Playhouse

Playground for HTML/CSS/JavaScript
JavaScript
146
star
6

Commit

Commit message editor
JavaScript
133
star
7

JSON8

JSON toolkit for JavaScript.
JavaScript
104
star
8

OhMySVG

Reduce the size of SVGs
JavaScript
92
star
9

linux-minibook-x

Linux for the Chuwi MiniBook X 2023 / N100
46
star
10

troll

Libraries for GNOME JavaScript (GJS)
JavaScript
45
star
11

Retro

A customizable retro digital segment clock
JavaScript
17
star
12

lightstring

XMPP client library for browsers.
JavaScript
17
star
13

remoteStorage

Playing around with remoteStorage, eventually releasing a lightweight library
TypeScript
5
star
14

mermaid-webkitgtk

JavaScript
5
star
15

owi-535

Applications and libraries for OWI-535 aka. Robotic Arm Edge
JavaScript
4
star
16

Disappear

Free your desktop from cumbersome apps.
JavaScript
4
star
17

broadcaster.js

Server-less cross-tabs messaging
HTML
3
star
18

proctor

Node.js module to lookup CPU and memory usage of a process.
JavaScript
3
star
19

icns.js

Apple Icon Image format (icns) for JavaScript
JavaScript
3
star
20

pya

CLI application to manage and monitor devices
JavaScript
2
star
21

node-bosh

BOSH client implementation library for nodejs.
JavaScript
2
star
22

netflix-desktop-entry

A simple (Linux) desktop entry that will open Netflix with Google Chrome
Makefile
2
star
23

ubiquitous-pancake

JavaScript
2
star
24

readplist

Tiny Node.js module to read any plist file.
JavaScript
2
star
25

outofsoya

Out of soya
TypeScript
1
star
26

gjs-embed

C
1
star
27

HTMLIncludes

JavaScript
1
star
28

sliders

HTML WYSIWYG slides editor
JavaScript
1
star
29

server-stop

Closes all connections and stop the server. Node.js
JavaScript
1
star
30

HTTPClient.js

JavaScript HTTP client library for browsers and Node.js
JavaScript
1
star
31

media-loop

Firefox addon that adds a menu item to control HTML5 audio/video loop.
JavaScript
1
star
32

dezorse

Like dezalgo but let you choose your "asap" function.
JavaScript
1
star