This repository has been archived by the owner on Sep 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
crossjs
committed
Oct 15, 2016
0 parents
commit b45c52f
Showing
21 changed files
with
1,359 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"env": { | ||
"development": { | ||
"presets": ["es2015", "stage-0"], | ||
"plugins": [ | ||
"add-module-exports", | ||
["__coverage__", { "ignore": "test/" }], | ||
"transform-runtime" | ||
] | ||
}, | ||
"production": { | ||
"presets": ["es2015-rollup", "stage-0"] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
coverage | ||
dist | ||
node_modules | ||
|
||
index.js | ||
index.min.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"root": true, | ||
"extends": [ | ||
"plato" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.DS_STORE | ||
*.bak | ||
*.log | ||
*.old | ||
*.out | ||
|
||
coverage | ||
dist | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
.DS_STORE | ||
*.bak | ||
*.log | ||
*.old | ||
*.out | ||
|
||
.tools | ||
coverage | ||
node_modules | ||
test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
process.env.BABEL_ENV = 'production' | ||
|
||
var fs = require('fs') | ||
var rollup = require('rollup') | ||
var uglify = require('uglify-js') | ||
var nodeResolve = require('rollup-plugin-node-resolve') | ||
var buble = require('rollup-plugin-buble') | ||
var version = process.env.VERSION || require('../package.json').version | ||
|
||
var banner = | ||
'/*!\n' + | ||
' * NUO v' + version + '\n' + | ||
' * (c) ' + new Date().getFullYear() + ' crossjs\n' + | ||
' * Released under the MIT License.\n' + | ||
' */' | ||
|
||
// cjs | ||
rollup.rollup({ | ||
entry: 'src/index.js', | ||
plugins: [ | ||
buble() | ||
] | ||
}) | ||
.then(function (bundle) { | ||
var code = bundle.generate({ | ||
format: 'cjs', | ||
banner | ||
}).code | ||
return write('dist/index.js', code).then(function () { | ||
return code | ||
}) | ||
}) | ||
.then(function (code) { | ||
var minified = banner + '\n' + uglify.minify(code, { | ||
fromString: true, | ||
output: { | ||
ascii_only: true | ||
} | ||
}).code | ||
return write('dist/index.min.js', minified) | ||
}) | ||
.catch(logError) | ||
|
||
// iife | ||
rollup.rollup({ | ||
entry: 'src/index.js', | ||
plugins: [ | ||
nodeResolve({ | ||
jsnext: true, | ||
browser: true | ||
}), | ||
buble() | ||
] | ||
}) | ||
.then(function (bundle) { | ||
var code = bundle.generate({ | ||
format: 'iife', | ||
moduleName: 'nuo', | ||
banner | ||
}).code | ||
return write('index.js', code).then(function () { | ||
return code | ||
}) | ||
}) | ||
.then(function (code) { | ||
var minified = banner + '\n' + uglify.minify(code, { | ||
fromString: true, | ||
output: { | ||
ascii_only: true | ||
} | ||
}).code | ||
return write('index.min.js', minified) | ||
}) | ||
.catch(logError) | ||
|
||
function write (dest, code) { | ||
return new Promise(function (resolve, reject) { | ||
fs.writeFile(dest, code, function (err) { | ||
if (err) return reject(err) | ||
console.log(blue(dest) + ' ' + getSize(code)) | ||
resolve() | ||
}) | ||
}) | ||
} | ||
|
||
function getSize (code) { | ||
return (code.length / 1024).toFixed(2) + 'kb' | ||
} | ||
|
||
function logError (e) { | ||
console.log(e) | ||
} | ||
|
||
function blue (str) { | ||
return '\x1b[1m\x1b[34m' + str + '\x1b[39m\x1b[22m' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
set -e | ||
echo "Enter release version: " | ||
read VERSION | ||
|
||
read -p "Releasing $VERSION - are you sure? (y/n)" -n 1 -r | ||
echo # (optional) move to a new line | ||
if [[ $REPLY =~ ^[Yy]$ ]] | ||
then | ||
echo "Releasing $VERSION ..." | ||
|
||
# test | ||
npm run lint | ||
|
||
# test | ||
npm run test | ||
|
||
# build | ||
rm -rf dist | ||
mkdir dist | ||
npm run build | ||
|
||
# commit | ||
git add -A | ||
git commit -m "* :tada: build $VERSION" | ||
npm version $VERSION --message "* :bookmark: bump $VERSION" | ||
|
||
# publish | ||
git push | ||
npm publish | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
language: node_js | ||
|
||
node_js: | ||
- "5" | ||
|
||
after_success: | ||
- npm run coverage | ||
- npm i coveralls | ||
- cat ./coverage/*/lcov.info | coveralls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
Copyright (c) 2016 crossjs | ||
Copyright (c) 2014 Taylor Hakes | ||
Copyright (c) 2014 Forbes Lindesay | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<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> | ||
# NUO | ||
|
||
> :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. | ||
[![Travis](https://img.shields.io/travis/crossjs/nuo.svg?style=flat-square)](https://travis-ci.org/crossjs/nuo) | ||
[![Coveralls](https://img.shields.io/coveralls/crossjs/nuo.svg?style=flat-square)](https://coveralls.io/github/crossjs/nuo) | ||
[![dependencies](https://david-dm.org/crossjs/nuo.svg?style=flat-square)](https://david-dm.org/crossjs/nuo) | ||
[![devDependency Status](https://david-dm.org/crossjs/nuo/dev-status.svg?style=flat-square)](https://david-dm.org/crossjs/nuo#info=devDependencies) | ||
[![NPM version](https://img.shields.io/npm/v/nuo.svg?style=flat-square)](https://npmjs.org/package/nuo) | ||
|
||
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. | ||
|
||
For API information about Promises, please check out this article [HTML5Rocks article](http://www.html5rocks.com/en/tutorials/es6/promises/). | ||
|
||
## Browser Support | ||
|
||
IE8+, Chrome, Firefox, IOS 4+, Safari 5+, Opera | ||
|
||
## Usage | ||
|
||
```js | ||
new Nuo(function(resolve, reject, notify) { | ||
// resolve, reject, notify | ||
}).then(function(value) { | ||
// do something | ||
}).catch(function(error) { | ||
// do something | ||
}).progress(function(value) { | ||
// do something | ||
}).finally(function() { | ||
// do something | ||
}) | ||
``` | ||
|
||
### cjs | ||
|
||
``` bash | ||
$ npm install nuo | ||
``` | ||
|
||
### iife | ||
|
||
- [nuo](index.js) [minified](index.min.js) | ||
|
||
## Example | ||
|
||
```js | ||
const nuo = new Nuo(function(resolve, reject) { | ||
// do a thing, possibly async, then… | ||
|
||
if (/* everything turned out fine */) { | ||
resolve("Stuff worked!"); | ||
} else { | ||
reject(new Error("It broke")); | ||
} | ||
}); | ||
|
||
// Do something when async done | ||
nuo.then(function() { | ||
... | ||
}); | ||
``` | ||
|
||
## Testing | ||
|
||
```bash | ||
npm install | ||
npm test | ||
``` | ||
|
||
## License | ||
|
||
MIT |
Oops, something went wrong.