{"library":"putil-promisify","title":"putil-promisify","description":"putil-promisify is a lightweight utility designed for transforming traditional Node.js callback-style functions into Promise-based equivalents. Its current stable version is 1.10.1, indicating a mature and likely infrequently updated library, suggesting a maintenance release cadence. This package provides a straightforward API, primarily through `fromCallback`, to convert functions adhering to the `(err, data)` callback signature into Promise-returning functions. It serves as an alternative to Node.js's built-in `util.promisify` for scenarios requiring a minimal dependency or compatibility with Node.js versions older than 8.0.0 (though its `package.json` specifies Node.js >= 14.0), or for specific custom promisification needs where `util.promisify`'s behavior might not be ideal.","language":"javascript","status":"maintenance","last_verified":"Sun Apr 19","install":{"commands":["npm install putil-promisify"],"cli":null},"imports":["import { fromCallback } from 'putil-promisify';","const Promisify = require('putil-promisify');\nconst promisifiedFunction = Promisify.fromCallback(callbackStyleFunction);","import type { Promisify } from 'putil-promisify';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { fromCallback } from 'putil-promisify';\nimport * as fs from 'fs';\n\n// A simple example of a callback-style function\nfunction asyncOperation(value: string, callback: (err: Error | null, result?: string) => void) {\n  setTimeout(() => {\n    if (value === 'error') {\n      return callback(new Error('Simulated error for: ' + value));\n    }\n    callback(null, 'Processed: ' + value.toUpperCase());\n  }, 100);\n}\n\n// Promisify the callback-style function\nconst promisifiedAsyncOperation = fromCallback(asyncOperation);\n\n// Use the promisified function with async/await\nasync function runExample() {\n  try {\n    const result1 = await promisifiedAsyncOperation('hello');\n    console.log(result1);\n\n    // Promisify a Node.js built-in function like fs.readFile\n    const readFilePromise = fromCallback(fs.readFile);\n    const fileContent = await readFilePromise('./package.json', 'utf8');\n    console.log('\\nContent of package.json (first 100 chars):\\n', fileContent.substring(0, 100) + '...');\n\n    const result2 = await promisifiedAsyncOperation('world');\n    console.log(result2);\n\n    // Demonstrate error handling\n    await promisifiedAsyncOperation('error');\n  } catch (error: any) {\n    console.error('\\nCaught an error:', error.message);\n  }\n}\n\nrunExample();","lang":"typescript","description":"This quickstart demonstrates how to use `fromCallback` to convert both a custom callback-style function and a Node.js built-in function (like `fs.readFile`) into Promise-based equivalents, then utilizes them with `async/await` for cleaner asynchronous code, including error handling.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}