Skip to main content

@mel/core@0.1.2

latest

core utilities

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
88%
Published
4 months ago (0.1.2)
function promisify
promisify<
T,
A,
>
(fn: (
args: T,
cb: (
err: Error | null,
result?: A,
) => void
,
) => void
): ((args: T) => Promise<A>)

Converts a callback-based function to a Promise-based function.

Examples

const callbackFunction = (arg, cb) => { if (arg > 10) { cb(null, 'Success'); } else { cb(new Error('Value too low')); } };

const promiseFunction = promisify(callbackFunction); promiseFunction(5) .then(result => console.log(result)) .catch(error => console.error(error));

Type Parameters

  • The type of the arguments passed to the original function.
  • The type of the result returned by the original function.

Parameters

fn: (
args: T,
cb: (
err: Error | null,
result?: A,
) => void
,
) => void
  • The original function that uses a callback.

Return Type

((args: T) => Promise<A>)
  • A function that returns a Promise resolving with the result or rejecting with an error.

Add Package

deno add jsr:@mel/core

Import symbol

import { promisify } from "@mel/core";

---- OR ----

Import directly with a jsr specifier

import { promisify } from "jsr:@mel/core";

Add Package

npx jsr add @mel/core

Import symbol

import { promisify } from "@mel/core";

Add Package

yarn dlx jsr add @mel/core

Import symbol

import { promisify } from "@mel/core";

Add Package

pnpm dlx jsr add @mel/core

Import symbol

import { promisify } from "@mel/core";

Add Package

bunx jsr add @mel/core

Import symbol

import { promisify } from "@mel/core";