psfy

1.0.0-pre.1 • Public • Published

P(romi)s(i)fy

Drop-in replacement of the node standard library with pre-promisified callback functions.

Node 8 introduced the promisify utility function, which wraps nodeback functions to return promises. Unfortunately, the standard library remains unchanged, which is why it's not uncommon to write:

const { promisify } = require('util');
const fs = require('fs');
const readdir = promisify(fs.readdir);
const rename = promisify(fs.rename);
const stat = promisify(fs.stat);

...when what you really want is:

const { readdir, rename, stat } = require('psfy/fs');

FAQ

This must be slow

It promisifies functions on-demand using a Proxy, and remembers the result.

This must be incomplete

It is complete to the extent that node authors follow the callback naming convention in the official documentation, which is used to generate this library. See _make.js.

NOTE: Currently only top-level functions are promisified.

TODO: Monkey-patch class methods that expect callbacks.

This will be incomplete as soon as there's a new node release

TODO: Git hook, autobuild on new node release

Readme

Keywords

none

Package Sidebar

Install

npm i psfy

Weekly Downloads

1

Version

1.0.0-pre.1

License

MIT

Last publish

Collaborators

  • qwtel