# ts-promisify-callback

> Turns any function ending with the standard "Error, Result" callback format into a promise (type-safe)

Latest version **0.1.2** (published 2020-08-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install ts-promisify-callback
pnpm add ts-promisify-callback
yarn add ts-promisify-callback
bun add ts-promisify-callback
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.2 |
| Published | 2020-08-07 |
| First published | 2020-08-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 10.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | charlie jonas |
| Maintainers | cjonas |
| Keywords | typescript, callback, promise |

## Links

- npm: https://www.npmjs.com/package/ts-promisify-callback
- Repository: https://github.com/ChuckJonas/ts-promisify-callback
- Homepage: https://github.com/ChuckJonas/ts-promisify-callback#readme
- Issues: https://github.com/ChuckJonas/ts-promisify-callback/issues
- npm.io page: https://npm.io/package/ts-promisify-callback

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 0.1.2 (latest) — 2020-08-07
- 0.1.1 — 2020-08-07
- 0.1.0 — 2020-08-07

## README

# ts-promisify-callback

![npm](https://img.shields.io/npm/v/ts-promisify-callback)

Turns any function ending with the "popular" `(Error, Result)` callback format into a `Promise`. Type-safe!

## Install

> npm install ts-promisify-callback

## Usage

**IMPORTANT:** This library requires `typescript@^4.0` (currently in beta)!

```ts
import { promisifyCallback } from "ts-promisify-callback";

function helloWithCallback(
  name: string,
  age: number,
  cb: (err: Error | null, result: string) => void
) {
  cb(null, `I'm ${name}, age ${age}`);
}

let helloAsPromise = promisifyCallback(helloWithCallback);
// let helloAsPromise: (name: string, age: number) => Promise<string>

(async () => {
  let greeting = await helloAsPromise("hello", 31);
  alert(greeting);
})();
```

## Contributing

This is a very simple library, but I'm sure there are many ways to improve it to be more flexible...

Pull Requests Welcome!

---
_Source: https://npm.io/package/ts-promisify-callback · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
