|
| 1 | +<a href="http://promises-aplus.github.com/promises-spec"><img src="http://promises-aplus.github.com/promises-spec/assets/logo-small.png" align="right" alt="Promises/A+ logo" /></a> |
| 2 | +# NUO |
| 3 | + |
| 4 | +> :two_hearts: Lightweight ES6 Promise polyfill for the browser and node. Adheres closely to the spec. It is a perfect polyfill IE, Firefox or any other browser that does not support native promises. |
| 5 | +
|
| 6 | +[](https://travis-ci.org/crossjs/nuo) |
| 7 | +[](https://coveralls.io/github/crossjs/nuo) |
| 8 | +[](https://david-dm.org/crossjs/nuo) |
| 9 | +[](https://david-dm.org/crossjs/nuo#info=devDependencies) |
| 10 | +[](https://npmjs.org/package/nuo) |
| 11 | + |
| 12 | +This implementation is based on [taylorhakes/promise-polyfill](https://github.com/taylorhakes/promise-polyfill) and [then/promise](https://github.com/then/promise). It has been changed to use the prototype for performance and memory reasons. |
| 13 | + |
| 14 | +For API information about Promises, please check out this article [HTML5Rocks article](http://www.html5rocks.com/en/tutorials/es6/promises/). |
| 15 | + |
| 16 | +## Browser Support |
| 17 | + |
| 18 | +IE8+, Chrome, Firefox, IOS 4+, Safari 5+, Opera |
| 19 | + |
| 20 | +## Usage |
| 21 | + |
| 22 | +```js |
| 23 | +new Nuo(function(resolve, reject, notify) { |
| 24 | + // resolve, reject, notify |
| 25 | +}).then(function(value) { |
| 26 | + // do something |
| 27 | +}).catch(function(error) { |
| 28 | + // do something |
| 29 | +}).progress(function(value) { |
| 30 | + // do something |
| 31 | +}).finally(function() { |
| 32 | + // do something |
| 33 | +}) |
| 34 | +``` |
| 35 | + |
| 36 | +### cjs |
| 37 | + |
| 38 | +``` bash |
| 39 | +$ npm install nuo |
| 40 | +``` |
| 41 | + |
| 42 | +### iife |
| 43 | + |
| 44 | +- [nuo](index.js) [minified](index.min.js) |
| 45 | + |
| 46 | +## Example |
| 47 | + |
| 48 | +```js |
| 49 | +const nuo = new Nuo(function(resolve, reject) { |
| 50 | + // do a thing, possibly async, then… |
| 51 | + |
| 52 | + if (/* everything turned out fine */) { |
| 53 | + resolve("Stuff worked!"); |
| 54 | + } else { |
| 55 | + reject(new Error("It broke")); |
| 56 | + } |
| 57 | +}); |
| 58 | + |
| 59 | +// Do something when async done |
| 60 | +nuo.then(function() { |
| 61 | + ... |
| 62 | +}); |
| 63 | +``` |
| 64 | + |
| 65 | +## Testing |
| 66 | + |
| 67 | +```bash |
| 68 | +npm install |
| 69 | +npm test |
| 70 | +``` |
| 71 | + |
| 72 | +## License |
| 73 | + |
| 74 | +MIT |
0 commit comments