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

give-promise

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

give-promise

A simple wrapper around `Promise` providing a more human-friendly interface

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

give-promise

A simple wrapper around Promise providing a more human-friendly interface

  • What it does
  • Raison d'être

What it does

Wraps this:

	let resolve
	let reject
	const promise = new Promise((innerResolve, innerReject) => {
		 resolve = innerResolve;
		 reject = innerReject;
	});

So that you can do this:

	const givePromise = require('give-promise')

	const [promise, resolve, reject] = givePromise()

But ESM

Here you go:

	import givePromise from 'give-promise/index.mjs'

If you use a module bundler like webpack or rollup, you can point 'give-promise' to 'give-promise/index.mjs' and then do this:

	import givePromise from 'give-promise'

See your bundler's docs for how to setup that redirect, should be simple.

Raison d'être

Personally, I don't like the default interface of Promise. Needing to wrap my code inside a constructor just seems bad to me. I found myself doing the above extraction quite frequently and therefore decided to put that into a neat little helper.

With this, you can pass around the promise and its related resolve and reject functions quite easily and intuitively.

Keywords

FAQs

Package last updated on 04 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