Convert callback-style functions to promises with flexible options for modules, methods, and edge cases.
Pify is a Node.js and browser utility that converts callback-style functions into promise-based functions, enabling cleaner async/await code. It solves the problem of working with legacy or callback-heavy APIs by wrapping them in a consistent promise interface. Unlike Node.js's `util.promisify`, it supports promisifying entire modules, handling multiple callback arguments, and offers fine-grained control over which methods are transformed.
JavaScript developers working with callback-based libraries (e.g., `fs`, `request`) who want to modernize their code with async/await, and library authors needing flexible promisification for diverse APIs.
Developers choose Pify for its greater flexibility and control compared to `util.promisify`, including module-wide promisification, multi-argument support, and customizable filtering. It's faster for many use cases and avoids unpredictable Node.js-specific behaviors.
Promisify a callback-style function
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Can convert all methods in an object or module at once, as shown with `pify(fs)` in the README, eliminating the need for individual function wrappers.
With the `multiArgs: true` option, it handles APIs like `request` that return multiple arguments, providing all callback values in an array for flexibility.
Options like `include`, `exclude`, and `excludeMain` allow selective promisification, such as skipping methods ending in 'Sync' by default.
Supports non-error-first callbacks via `errorFirst: false`, essential for APIs like `fs.exists` and browser APIs, as noted in the README.
As per the FAQ, Pify only chooses the last function overload in TypeScript, requiring manual type assertions for correct typing, which adds complexity.
For simple promisification tasks, the numerous configuration options can be overkill compared to the straightforward `util.promisify` in Node.js.
Avoids Node.js's custom promisification behaviors, which might necessitate extra work for handling certain built-in modules without automatic adaptations.