A tiny JavaScript library to test if an object looks like a Promises/A+ compliant promise.
is-promise is a small JavaScript library that tests whether an object looks like a Promises/A+ compliant promise. It solves the problem of reliably identifying promise-like objects in code, helping prevent errors when handling asynchronous operations. The library returns true for objects with a `then` method that is a function, following the Promises/A+ specification.
JavaScript and TypeScript developers working with asynchronous code, library authors who need to handle promise detection, and teams building applications that interact with mixed promise implementations.
Developers choose is-promise for its strict adherence to the Promises/A+ standard, minimal footprint, and reliability in detecting promise-like objects across different environments without false positives.
Test whether an object looks like a promises-a+ promise
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Accurately identifies any object with a `then` method that is a function, adhering to the official standard, as shown in the API examples with non-native promises like {then:function () {...}}.
Has no dependencies and a single function, adding negligible overhead, which aligns with its philosophy of being a no-frills solution for promise detection.
Works consistently in Node.js and browsers via npm, ensuring promise detection behaves the same across different JavaScript runtimes, as mentioned in the installation notes.
Includes built-in TypeScript definitions, providing type safety and better developer experience, as indicated in the key features and API example with TypeScript import.
Only performs basic promise detection; it doesn't offer utilities for promise handling, error management, or other async patterns, which may require additional libraries for complex workflows.
For codebases using only native promises, built-in checks like `instanceof` or `Promise.resolve()` might be simpler and avoid introducing an external dependency.
While it follows Promises/A+, it doesn't address scenarios like promise subclassing or custom thenables that might behave unexpectedly, relying on developers to understand the specification.