Skip to content

herber/minp

Repository files navigation

minp Codestyle fyi Build Status Windows Build Status Coverage Status

A minimal promise polyfill.

If you cannot rely on native promises and you can't use a huge promise polyfill then minp has got you covered!

About

Minp is a barebones promise polyfill it does not nearly cover the whole promise specification but it is really tiny(<30 loc). Minp is meant to be used in libraries that want to offer promise goodness to everyone without having to ship huge polyfills.

Install

Node.js

$ npm install --save minp

Browsers

<script src="https://unpkg.com/minp"></script>

Usage

const P = require('minp');

const promiseFunction = (args) => new P ((resolve, reject) => {
  if (args === 'awesome') {
    resolve('yes', 'it', 'is');
  } else {
    reject(new Error('Nope!'));
  }
});

promiseFunction('awesome').then((arg1, arg2, arg3) => {
  console.log(arg1, arg2, arg3);
  // => 'yes it is'
}).catch((err) => {
  console.error(err);
});

API

P(resolvable)

resolvable(resolve, reject)

Type: function

Whatever you want - it's just a function.

resolve

Type: function

You should call resolve if everything worked. You can pass whichever arguments you want, they will be handed over to .then. If you resolve the promise .then will be executed.

reject

Type: function

You should call reject if an error occurred. Just pass the error as an argument. If you reject the promise .catch will be executed.

License

MIT © Tobias Herber

Releases

No releases published

Packages

No packages published