Registry / http-networking / standard-as-callback

standard-as-callback

JSON →
library2.1.0jsnpmunverified

standard-as-callback is a performant JavaScript library designed to register a Node.js-style error-first callback on a Promise. It provides functionality similar to the `.nodeify()` method popularized by the Bluebird Promise library, allowing for seamless integration of promise-based asynchronous operations into environments or APIs that expect callback conventions. The current stable version is 2.1.0, with its last update occurring in 2018, indicating a maintenance status rather than active development. Its key differentiator is providing a standardized, Bluebird-inspired approach to callback conversion, particularly useful in legacy Node.js projects or when bridging modern async/await patterns with older callback-expecting interfaces. The package ships with TypeScript type definitions.

npm install standard-as-callback
INSTALL
IMPORT
SIG · STANDARD-AS-CALLBA
S
standard-as-callback
http-networkingjavascriptv2.1.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

asCallback
import asCallback from 'standard-as-callback';
import { asCallback } from 'standard-as-callback';
The library primarily offers a default export for the asCallback function, common for single-function CommonJS modules.
asCallback
const asCallback = require('standard-as-callback');
const { asCallback } = require('standard-as-callback');
This is the standard CommonJS `require` pattern for modules with a default export, as shown in the original documentation.
AsCallbackFunction
import type { AsCallbackFunction } from 'standard-as-callback';
When using TypeScript, you can import the type definition for the asCallback function signature to ensure type safety, assuming the package exports this type directly.

This code demonstrates how to use `standard-as-callback` to attach a Node.js-style error-first callback to both a successfully resolving promise and a rejecting promise. It showcases basic error handling within the callback and the expected output for each scenario.

import asCallback from 'standard-as-callback'; // Example 1: A simple resolving promise const resolvingPromise = new Promise<string>((resolve) => { setTimeout(() => { resolve('Operation successful!'); }, 500); }); asCallback(resolvingPromise, (err, res) => { if (err) { console.error('Callback error (resolvingPromise):', err); return; } console.log('Callback result (resolvingPromise):', res); // null, 'Operation successful!' }); // Example 2: A promise that rejects const rejectingPromise = new Promise<string>((_resolve, reject) => { setTimeout(() => { reject(new Error('Something went wrong!')); }, 1000); }); asCallback(rejectingPromise, (err, res) => { if (err) { console.error('Callback error (rejectingPromise):', (err as Error).message); // 'Something went wrong!' return; } console.log('Callback result (rejectingPromise):', res); });
Debug
Known issues
gotchaThe package has not seen active development since 2018 (version 2.1.0). While stable, consider its long-term maintenance status when adopting for new projects or relying on modern JavaScript features.
fix
Review the source code for potential vulnerabilities or compatibility issues with newer Node.js versions. Consider alternatives like direct Promise consumption or explicit conversion utilities if more active maintenance is desired.
affects: >=2.1.0
gotchaIf the provided Promise rejects and no error-handling logic is included in the callback, the rejection might still become an unhandled promise rejection if not caught elsewhere in the Promise chain.
fix
Always ensure your callback function properly handles the `err` argument, even if just logging it, to prevent unhandled promise rejections. Example: `(err, res) => { if (err) { console.error(err); return; } /* handle success */ }`
affects: >=1.0.0
gotcha`standard-as-callback` is designed to convert Promises into callback-style APIs. It is not intended for converting callback-based APIs into Promises (a process often called 'promisification').
fix
For converting callback-based APIs to Promises, use `util.promisify` (Node.js built-in), a dedicated promisification library, or manual Promise wrapping.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: callback must be a function
The second argument passed to `asCallback` was not a function.
fix
Ensure the second argument to `asCallback` is a valid Node.js-style callback function with `(err, result)` signature.
UnhandledPromiseRejectionWarning: Unhandled promise rejection.
A Promise passed to `asCallback` rejected, but the provided callback did not handle the `err` argument, or no callback was provided, leading to the rejection not being consumed.
fix
Always provide a callback that handles errors, e.g., `asCallback(promise, (err, res) => { if (err) { console.error(err); return; } /* success */ })`. Also ensure the promise chain itself handles rejections if `asCallback` is not the final error handler.
Cannot find module 'standard-as-callback'
The package is not installed, or there's a misconfiguration in your module resolution (e.g., incorrect CJS/ESM import in the wrong environment).
fix
Run `npm install standard-as-callback` or `yarn add standard-as-callback`. Verify your import statement matches your module system (e.g., `require` for CommonJS, `import` for ESM).
Upgrade
Version history
2.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
12 hits · last 30 days
node
10
OpenAI (training)
1
Resources
standard-as-callback — npm install standard-as-callback · libregistry