Template Upload
This commit is contained in:
22
node_modules/thenify/LICENSE
generated
vendored
Normal file
22
node_modules/thenify/LICENSE
generated
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014-2016 Jonathan Ong me@jongleberry.com and contributors
|
||||
|
||||
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.
|
65
node_modules/thenify/README.md
generated
vendored
Normal file
65
node_modules/thenify/README.md
generated
vendored
Normal file
@ -0,0 +1,65 @@
|
||||
|
||||
# thenify
|
||||
|
||||
[![NPM version][npm-image]][npm-url]
|
||||
[![Build status][travis-image]][travis-url]
|
||||
[![Test coverage][coveralls-image]][coveralls-url]
|
||||
[![Dependency Status][david-image]][david-url]
|
||||
[![License][license-image]][license-url]
|
||||
[![Downloads][downloads-image]][downloads-url]
|
||||
|
||||
Promisify a callback-based function using [`any-promise`](https://github.com/kevinbeaty/any-promise).
|
||||
|
||||
- Preserves function names
|
||||
- Uses a native promise implementation if available and tries to fall back to a promise implementation such as `bluebird`
|
||||
- Converts multiple arguments from the callback into an `Array`
|
||||
- Resulting function never deoptimizes
|
||||
- Supports both callback and promise style
|
||||
|
||||
An added benefit is that `throw`n errors in that async function will be caught by the promise!
|
||||
|
||||
## API
|
||||
|
||||
- Turn async functions into promises
|
||||
|
||||
```js
|
||||
var thenify = require('thenify');
|
||||
|
||||
var somethingAsync = thenify(function somethingAsync(a, b, c, callback) {
|
||||
callback(null, a, b, c);
|
||||
});
|
||||
```
|
||||
|
||||
- Backward compatible with callback
|
||||
|
||||
```js
|
||||
var thenify = require('thenify').withCallback;
|
||||
|
||||
var somethingAsync = thenify(function somethingAsync(a, b, c, callback) {
|
||||
callback(null, a, b, c);
|
||||
});
|
||||
|
||||
// somethingAsync(a, b, c).then(onFulfilled).catch(onRejected);
|
||||
// somethingAsync(a, b, c, function () {});
|
||||
```
|
||||
|
||||
### var fn = thenify(fn)
|
||||
|
||||
Promisifies a function.
|
||||
|
||||
[gitter-image]: https://badges.gitter.im/thenables/thenify.png
|
||||
[gitter-url]: https://gitter.im/thenables/thenify
|
||||
[npm-image]: https://img.shields.io/npm/v/thenify.svg?style=flat-square
|
||||
[npm-url]: https://npmjs.org/package/thenify
|
||||
[github-tag]: http://img.shields.io/github/tag/thenables/thenify.svg?style=flat-square
|
||||
[github-url]: https://github.com/thenables/thenify/tags
|
||||
[travis-image]: https://img.shields.io/travis/thenables/thenify.svg?style=flat-square
|
||||
[travis-url]: https://travis-ci.org/thenables/thenify
|
||||
[coveralls-image]: https://img.shields.io/coveralls/thenables/thenify.svg?style=flat-square
|
||||
[coveralls-url]: https://coveralls.io/r/thenables/thenify
|
||||
[david-image]: http://img.shields.io/david/thenables/thenify.svg?style=flat-square
|
||||
[david-url]: https://david-dm.org/thenables/thenify
|
||||
[license-image]: http://img.shields.io/npm/l/thenify.svg?style=flat-square
|
||||
[license-url]: LICENSE
|
||||
[downloads-image]: http://img.shields.io/npm/dm/thenify.svg?style=flat-square
|
||||
[downloads-url]: https://npmjs.org/package/thenify
|
63
node_modules/thenify/index.js
generated
vendored
Normal file
63
node_modules/thenify/index.js
generated
vendored
Normal file
@ -0,0 +1,63 @@
|
||||
|
||||
var Promise = require('any-promise')
|
||||
var assert = require('assert')
|
||||
|
||||
module.exports = thenify
|
||||
|
||||
/**
|
||||
* Turn async functions into promises
|
||||
*
|
||||
* @param {Function} $$__fn__$$
|
||||
* @return {Function}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
function thenify($$__fn__$$) {
|
||||
assert(typeof $$__fn__$$ === 'function')
|
||||
return eval(createWrapper($$__fn__$$.name))
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn async functions into promises and backward compatible with callback
|
||||
*
|
||||
* @param {Function} $$__fn__$$
|
||||
* @return {Function}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
thenify.withCallback = function ($$__fn__$$) {
|
||||
assert(typeof $$__fn__$$ === 'function')
|
||||
return eval(createWrapper($$__fn__$$.name, true))
|
||||
}
|
||||
|
||||
function createCallback(resolve, reject) {
|
||||
return function(err, value) {
|
||||
if (err) return reject(err)
|
||||
var length = arguments.length
|
||||
if (length <= 2) return resolve(value)
|
||||
var values = new Array(length - 1)
|
||||
for (var i = 1; i < length; ++i) values[i - 1] = arguments[i]
|
||||
resolve(values)
|
||||
}
|
||||
}
|
||||
|
||||
function createWrapper(name, withCallback) {
|
||||
name = (name || '').replace(/\s|bound(?!$)/g, '')
|
||||
withCallback = withCallback ?
|
||||
'var lastType = typeof arguments[len - 1]\n'
|
||||
+ 'if (lastType === "function") return $$__fn__$$.apply(self, arguments)\n'
|
||||
: ''
|
||||
|
||||
return '(function ' + name + '() {\n'
|
||||
+ 'var self = this\n'
|
||||
+ 'var len = arguments.length\n'
|
||||
+ withCallback
|
||||
+ 'var args = new Array(len + 1)\n'
|
||||
+ 'for (var i = 0; i < len; ++i) args[i] = arguments[i]\n'
|
||||
+ 'var lastIndex = i\n'
|
||||
+ 'return new Promise(function (resolve, reject) {\n'
|
||||
+ 'args[lastIndex] = createCallback(resolve, reject)\n'
|
||||
+ '$$__fn__$$.apply(self, args)\n'
|
||||
+ '})\n'
|
||||
+ '})'
|
||||
}
|
101
node_modules/thenify/package.json
generated
vendored
Normal file
101
node_modules/thenify/package.json
generated
vendored
Normal file
@ -0,0 +1,101 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"thenify@^3.1.0",
|
||||
"C:\\Users\\x2mjbyrn\\Source\\Repos\\Skeleton\\node_modules\\typings-core"
|
||||
]
|
||||
],
|
||||
"_from": "thenify@>=3.1.0-0 <4.0.0-0",
|
||||
"_id": "thenify@3.2.1",
|
||||
"_inCache": true,
|
||||
"_location": "/thenify",
|
||||
"_nodeVersion": "4.4.7",
|
||||
"_npmOperationalInternal": {
|
||||
"host": "packages-12-west.internal.npmjs.com",
|
||||
"tmp": "tmp/thenify-3.2.1.tgz_1476096494606_0.22121428861282766"
|
||||
},
|
||||
"_npmUser": {
|
||||
"email": "dead_horse@qq.com",
|
||||
"name": "dead_horse"
|
||||
},
|
||||
"_npmVersion": "3.10.3",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"name": "thenify",
|
||||
"raw": "thenify@^3.1.0",
|
||||
"rawSpec": "^3.1.0",
|
||||
"scope": null,
|
||||
"spec": ">=3.1.0-0 <4.0.0-0",
|
||||
"type": "range"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/typings-core"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/thenify/-/thenify-3.2.1.tgz",
|
||||
"_shasum": "251fd1c80aff6e5cf57cb179ab1fcb724269bd11",
|
||||
"_shrinkwrap": null,
|
||||
"_spec": "thenify@^3.1.0",
|
||||
"_where": "C:\\Users\\x2mjbyrn\\Source\\Repos\\Skeleton\\node_modules\\typings-core",
|
||||
"author": {
|
||||
"email": "me@jongleberry.com",
|
||||
"name": "Jonathan Ong",
|
||||
"url": "http://jongleberry.com"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/thenables/thenify/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"any-promise": "^1.0.0"
|
||||
},
|
||||
"description": "Promisify a callback-based function",
|
||||
"devDependencies": {
|
||||
"bluebird": "^3.1.1",
|
||||
"istanbul": "^0.4.0",
|
||||
"mocha": "^3.0.2"
|
||||
},
|
||||
"directories": {},
|
||||
"dist": {
|
||||
"shasum": "251fd1c80aff6e5cf57cb179ab1fcb724269bd11",
|
||||
"tarball": "https://registry.npmjs.org/thenify/-/thenify-3.2.1.tgz"
|
||||
},
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"gitHead": "42e93a084347eed9ad34cd3f77728e7fe9b2c1c5",
|
||||
"homepage": "https://github.com/thenables/thenify#readme",
|
||||
"installable": true,
|
||||
"keywords": [
|
||||
"es6",
|
||||
"promise",
|
||||
"promisify",
|
||||
"then",
|
||||
"thenify"
|
||||
],
|
||||
"license": "MIT",
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "jongleberry",
|
||||
"email": "jonathanrichardong@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "dead-horse",
|
||||
"email": "dead_horse@qq.com"
|
||||
},
|
||||
{
|
||||
"name": "dead_horse",
|
||||
"email": "dead_horse@qq.com"
|
||||
}
|
||||
],
|
||||
"name": "thenify",
|
||||
"optionalDependencies": {},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/thenables/thenify.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "mocha --reporter spec",
|
||||
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot",
|
||||
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter dot"
|
||||
},
|
||||
"version": "3.2.1"
|
||||
}
|
Reference in New Issue
Block a user