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.
npm install putil-promisifyVerified import paths — ran on the pinned version, not inferred.
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.
For Node.js v8.0.0 and above, use `import { promisify } from 'node:util';` or `const { promisify } = require('node:util');`. Consider `putil-promisify` only if targeting older Node.js versions or if its specific implementation is required.Always defer to the `engines` field in `package.json` and ensure your Node.js environment is v14.0 or newer to guarantee compatibility and stability. Using older versions might lead to unexpected issues.
Thoroughly test promisified functions, especially those with complex or non-standard callback patterns. For such cases, a custom wrapper function might be more appropriate, or `util.promisify.custom` if using the native Node.js utility.
For CommonJS, ensure you import the whole module first: `const Promisify = require('putil-promisify');`, then access `Promisify.fromCallback`. For ESM, use `import { fromCallback } from 'putil-promisify';` to directly import the named export.Verify that the function you are attempting to promisify accepts a `(error, result)` callback as its final argument. If it does not, you may need to wrap it in an adapter function that conforms to this signature before passing it to `fromCallback`.
No dependency data recorded yet.