Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

is-actual-promise

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

is-actual-promise

Verify if something is a Promise

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
87K
decreased by-28.2%
Maintainers
1
Weekly downloads
 
Created
Source

is-actual-promise

Similar to p-is-promise and is-promise, which are also both fine alternatives to this.

Differences (ie, "why this thing then?")

  • This module is hybrid, so it can be used in either commonjs or esm. is-promise is hybrid, but p-is-promise is ESM-only.
  • This module asserts that the tested value supplies the full actual Promise interface, not just PromiseLike (ie, it also asserts .catch() and .finally(). (p-is-promise tests for .catch(), neither tests for .finally().)
  • This module provides a named export rather than a default export, which is a bit less of a hassle in some scenarios.
  • This module does not verify the resolution type of the Promise, since that cannot be determined or verified, only that it's a Promise<any | void>.

(Note that this module does not verify that the .catch(), .then(), and .finally() methods return Promises, because that is impossible at run-time without actually calling them. No duck-typing method should ever be considered fully authoritative.)

USAGE

import { isPromise } from 'is-actual-promise'

console.log(isPromise(new Promise(() => {}))) // true
console.log(isPromise((async () => true)())) // true
console.log(isPromise(Promise.resolve(true))) // true
console.log(isPromise({
  then: async () => 5,
  finally: async () => {},
  catch: () => {},
})) // true, but not accurate, limitation of duck typing

Keywords

FAQs

Package last updated on 14 May 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc