catering is a lightweight utility designed to enable JavaScript modules to be consumed seamlessly using both traditional Node.js-style callbacks and modern Promises. It provides `fromCallback` to wrap internal callback-based logic for promise consumption and `fromPromise` to adapt promise-based logic for callback consumption. The package is currently at version 2.1.1 and appears to be in active maintenance, receiving updates as needed. Its primary differentiator is its focused approach to providing this dual-consumption pattern without imposing a heavy dependency footprint. It explicitly handles error propagation in `fromPromise` by calling the callback in a `queueMicrotask` to prevent errors from being caught by the promise chain, ensuring clear error reporting to the consumer. It is suitable for both Node.js (>=6) and browser environments, and ships with TypeScript types.
npm install cateringVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to create modules that internally use either callbacks or promises, and how `catering` enables them to be consumed with both `async/await` and traditional Node.js callbacks.
Ensure `return callback[kPromise]` is the last statement in your module's function when using `fromCallback`.
Handle errors delivered to the callback via the `(err, result)` signature. Do not rely on `.catch()` on the promise returned by `fromPromise` to handle errors for the callback path.
Upgrade to a current Node.js LTS version (e.g., Node.js 18 or 20) for optimal compatibility and security.
Ensure `return callback[kPromise]` is present at the end of the module's function when using `fromCallback` to expose the promise interface.
Ensure that if your module's function accepts a `callback` argument, you either pass a function or `undefined` (if the consumer intends to use promises). `catering` handles the `undefined` case for promise consumption.
No dependency data recorded yet.