.. | ||
.jshintrc | ||
.npmignore | ||
any-promise-shim.js | ||
any-promise.js | ||
LICENSE | ||
package.json | ||
README.md |
Any Promise
Let your library support any ES6 compatible Promise library or polyfill and leave the choice to the end user. The end user can install a polyfill or npm install
their preference before using this library and the installed library will be automatically detected.
Attempts to load libraries in the following order. The first successful require
will be exported.
If no library is installed, attempts to export the global Promise
(native or polyfill). The browserify
version will always export the the global Promise
, so polyfill as necessary.
If you have multiple libraries installed (e.g. for testing), and would like to specify one you can use the PROMISE_IMPL
env variable.
var Promise = require('any-promise');
return Promise
.all([xf, f, init, coll])
.then(fn);
return new Promise(function(resolve, reject){
try {
resolve(item);
} catch(e){
reject(e);
}
});