{"library":"standard-as-callback","title":"Standard asCallback","type":"library","description":"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.","language":"javascript","status":"maintenance","last_verified":"Tue Apr 21","install":{"commands":["npm install standard-as-callback"],"cli":null},"imports":["import asCallback from 'standard-as-callback';","const asCallback = require('standard-as-callback');","import type { AsCallbackFunction } from 'standard-as-callback';"],"auth":{"required":false,"env_vars":[]},"links":{"homepage":null,"github":"https://github.com/luin/asCallback","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/standard-as-callback","openapi_spec":null,"status_page":null,"smithery":null},"quickstart":{"code":"import asCallback from 'standard-as-callback';\n\n// Example 1: A simple resolving promise\nconst resolvingPromise = new Promise<string>((resolve) => {\n  setTimeout(() => {\n    resolve('Operation successful!');\n  }, 500);\n});\n\nasCallback(resolvingPromise, (err, res) => {\n  if (err) {\n    console.error('Callback error (resolvingPromise):', err);\n    return;\n  }\n  console.log('Callback result (resolvingPromise):', res); // null, 'Operation successful!'\n});\n\n// Example 2: A promise that rejects\nconst rejectingPromise = new Promise<string>((_resolve, reject) => {\n  setTimeout(() => {\n    reject(new Error('Something went wrong!'));\n  }, 1000);\n});\n\nasCallback(rejectingPromise, (err, res) => {\n  if (err) {\n    console.error('Callback error (rejectingPromise):', (err as Error).message); // 'Something went wrong!'\n    return;\n  }\n  console.log('Callback result (rejectingPromise):', res);\n});","lang":"typescript","description":"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}