p-from-callback
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

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).

Readme

Keywords

Package Sidebar

Install

npm i p-from-callback

Weekly Downloads

9,991

Version

2.0.0

License

SEE LICENSE IN LICENSE.md

Unpacked Size

4.82 kB

Total Files

5

Last publish

Collaborators

  • perrin4869