2.0.0 • Published 7 days ago

p-from-callback v2.0.0

Weekly downloads
-
License
SEE LICENSE IN LI...
Repository
github
Last release
7 days ago

p-from-callback

Build Status npm package Coverage Status

Map node-style callback to a promise

Install

$ npm install p-from-callback

Features

  • pure esm module
  • typescript types
  • supports multiple return values
  • 100% test coverage

Usage

import { readFile } from 'node:fs';
import fromCallback from 'p-from-callback';

fromCallback(cb => readFile("foo.txt", cb)).then(buf => buf.toString('utf8'));
fromCallback(cb => cb(undefined, "foo", "bar"), true)
    .then([foo, bar] => foo === "foo" && bar === "bar");

API

fromCallback\<R>((cb: (err: any, res: R)): any): Promise\<R>

fromCallback\<R>((cb: (err: any, ...res: R[])): any, true): Promise\<R[]>

Takes a callback resolver and returns a promise to the resolved value, or array of values when multi = true.

License

See the LICENSE file for license rights and limitations (MIT).