i-promise

Returns an available ES6 Promise implementation, browserify friendly.

Usage no npm install needed!

<script type="module">
  import iPromise from 'https://cdn.skypack.dev/i-promise';
</script>

README

i-promise

When calling this module a Promise library will be returned if one is available.

This module will not declare any dependencies, you should install a fallback library downstream if needed.

Install

npm install --save i-promise

Use

var Promise = require('i-promise');
if (!Promise) throw new Error('No ES6 Promise Library Available.');

return Promise.resolve('success')

Notes

In a browser (via browserify), it will return either window.Promise, window.Q.Promise or window.Q.promise in that order, you should have an es6-promise shim or the Q library loaded globally in the browser if you need promises in older browsers.

In node, attempts to use the following will be made.

Preferring user implementation over native

Default behavior is to always favor native implementation if found. You can still favor the implementation of your choice without overriding global Promise:

require('i-promise/config').use(MyPromiseImplementation);

You must run this code before any call to require('i-promise').