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

make-thenable

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

make-thenable

Make any object thenable without a fuss

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

make-thenable

Make an object thenable without a fuss

What it does

const makeThenable = require('make-thenable')

const promiseLike = {}

const [resolve, reject] = makeThenable(promiseLike)

Now, the given object behaves exactly like a good little Promise: you can add callbacks through promiseLike.then and promiseLike.catch, and resolve/reject through the return values. That is because it is now linked to a real Promise. Consequently, in Internet Explorer, you need a polyfill.

Also resolvable

const makeThenable = require('make-thenable/resolvable')

const promiseLike = makeThenable({})

This gives you the same functionality as above, plus promiseLike.resolve and promiseLike.reject.

Why it exists

Sometimes, you need an arbitrary object to behave like a Promise. In times like these, just make it thenable and be happy.

After writing the original version, I came across an article by Lea Verou, and thought I'd cover her use-case as well. That's why there's make-thenable/resolvable

Keywords

FAQs

Package last updated on 13 Feb 2019

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