1.0.0 • Published 6 years ago

give-promise v1.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

give-promise

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

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.