Pushing changes
This commit is contained in:
292
node_modules/pinkie/index.js
generated
vendored
Normal file
292
node_modules/pinkie/index.js
generated
vendored
Normal file
@ -0,0 +1,292 @@
|
||||
'use strict';
|
||||
|
||||
var PENDING = 'pending';
|
||||
var SETTLED = 'settled';
|
||||
var FULFILLED = 'fulfilled';
|
||||
var REJECTED = 'rejected';
|
||||
var NOOP = function () {};
|
||||
var isNode = typeof global !== 'undefined' && typeof global.process !== 'undefined' && typeof global.process.emit === 'function';
|
||||
|
||||
var asyncSetTimer = typeof setImmediate === 'undefined' ? setTimeout : setImmediate;
|
||||
var asyncQueue = [];
|
||||
var asyncTimer;
|
||||
|
||||
function asyncFlush() {
|
||||
// run promise callbacks
|
||||
for (var i = 0; i < asyncQueue.length; i++) {
|
||||
asyncQueue[i][0](asyncQueue[i][1]);
|
||||
}
|
||||
|
||||
// reset async asyncQueue
|
||||
asyncQueue = [];
|
||||
asyncTimer = false;
|
||||
}
|
||||
|
||||
function asyncCall(callback, arg) {
|
||||
asyncQueue.push([callback, arg]);
|
||||
|
||||
if (!asyncTimer) {
|
||||
asyncTimer = true;
|
||||
asyncSetTimer(asyncFlush, 0);
|
||||
}
|
||||
}
|
||||
|
||||
function invokeResolver(resolver, promise) {
|
||||
function resolvePromise(value) {
|
||||
resolve(promise, value);
|
||||
}
|
||||
|
||||
function rejectPromise(reason) {
|
||||
reject(promise, reason);
|
||||
}
|
||||
|
||||
try {
|
||||
resolver(resolvePromise, rejectPromise);
|
||||
} catch (e) {
|
||||
rejectPromise(e);
|
||||
}
|
||||
}
|
||||
|
||||
function invokeCallback(subscriber) {
|
||||
var owner = subscriber.owner;
|
||||
var settled = owner._state;
|
||||
var value = owner._data;
|
||||
var callback = subscriber[settled];
|
||||
var promise = subscriber.then;
|
||||
|
||||
if (typeof callback === 'function') {
|
||||
settled = FULFILLED;
|
||||
try {
|
||||
value = callback(value);
|
||||
} catch (e) {
|
||||
reject(promise, e);
|
||||
}
|
||||
}
|
||||
|
||||
if (!handleThenable(promise, value)) {
|
||||
if (settled === FULFILLED) {
|
||||
resolve(promise, value);
|
||||
}
|
||||
|
||||
if (settled === REJECTED) {
|
||||
reject(promise, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function handleThenable(promise, value) {
|
||||
var resolved;
|
||||
|
||||
try {
|
||||
if (promise === value) {
|
||||
throw new TypeError('A promises callback cannot return that same promise.');
|
||||
}
|
||||
|
||||
if (value && (typeof value === 'function' || typeof value === 'object')) {
|
||||
// then should be retrieved only once
|
||||
var then = value.then;
|
||||
|
||||
if (typeof then === 'function') {
|
||||
then.call(value, function (val) {
|
||||
if (!resolved) {
|
||||
resolved = true;
|
||||
|
||||
if (value === val) {
|
||||
fulfill(promise, val);
|
||||
} else {
|
||||
resolve(promise, val);
|
||||
}
|
||||
}
|
||||
}, function (reason) {
|
||||
if (!resolved) {
|
||||
resolved = true;
|
||||
|
||||
reject(promise, reason);
|
||||
}
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
if (!resolved) {
|
||||
reject(promise, e);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function resolve(promise, value) {
|
||||
if (promise === value || !handleThenable(promise, value)) {
|
||||
fulfill(promise, value);
|
||||
}
|
||||
}
|
||||
|
||||
function fulfill(promise, value) {
|
||||
if (promise._state === PENDING) {
|
||||
promise._state = SETTLED;
|
||||
promise._data = value;
|
||||
|
||||
asyncCall(publishFulfillment, promise);
|
||||
}
|
||||
}
|
||||
|
||||
function reject(promise, reason) {
|
||||
if (promise._state === PENDING) {
|
||||
promise._state = SETTLED;
|
||||
promise._data = reason;
|
||||
|
||||
asyncCall(publishRejection, promise);
|
||||
}
|
||||
}
|
||||
|
||||
function publish(promise) {
|
||||
promise._then = promise._then.forEach(invokeCallback);
|
||||
}
|
||||
|
||||
function publishFulfillment(promise) {
|
||||
promise._state = FULFILLED;
|
||||
publish(promise);
|
||||
}
|
||||
|
||||
function publishRejection(promise) {
|
||||
promise._state = REJECTED;
|
||||
publish(promise);
|
||||
if (!promise._handled && isNode) {
|
||||
global.process.emit('unhandledRejection', promise._data, promise);
|
||||
}
|
||||
}
|
||||
|
||||
function notifyRejectionHandled(promise) {
|
||||
global.process.emit('rejectionHandled', promise);
|
||||
}
|
||||
|
||||
/**
|
||||
* @class
|
||||
*/
|
||||
function Promise(resolver) {
|
||||
if (typeof resolver !== 'function') {
|
||||
throw new TypeError('Promise resolver ' + resolver + ' is not a function');
|
||||
}
|
||||
|
||||
if (this instanceof Promise === false) {
|
||||
throw new TypeError('Failed to construct \'Promise\': Please use the \'new\' operator, this object constructor cannot be called as a function.');
|
||||
}
|
||||
|
||||
this._then = [];
|
||||
|
||||
invokeResolver(resolver, this);
|
||||
}
|
||||
|
||||
Promise.prototype = {
|
||||
constructor: Promise,
|
||||
|
||||
_state: PENDING,
|
||||
_then: null,
|
||||
_data: undefined,
|
||||
_handled: false,
|
||||
|
||||
then: function (onFulfillment, onRejection) {
|
||||
var subscriber = {
|
||||
owner: this,
|
||||
then: new this.constructor(NOOP),
|
||||
fulfilled: onFulfillment,
|
||||
rejected: onRejection
|
||||
};
|
||||
|
||||
if ((onRejection || onFulfillment) && !this._handled) {
|
||||
this._handled = true;
|
||||
if (this._state === REJECTED && isNode) {
|
||||
asyncCall(notifyRejectionHandled, this);
|
||||
}
|
||||
}
|
||||
|
||||
if (this._state === FULFILLED || this._state === REJECTED) {
|
||||
// already resolved, call callback async
|
||||
asyncCall(invokeCallback, subscriber);
|
||||
} else {
|
||||
// subscribe
|
||||
this._then.push(subscriber);
|
||||
}
|
||||
|
||||
return subscriber.then;
|
||||
},
|
||||
|
||||
catch: function (onRejection) {
|
||||
return this.then(null, onRejection);
|
||||
}
|
||||
};
|
||||
|
||||
Promise.all = function (promises) {
|
||||
if (!Array.isArray(promises)) {
|
||||
throw new TypeError('You must pass an array to Promise.all().');
|
||||
}
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
var results = [];
|
||||
var remaining = 0;
|
||||
|
||||
function resolver(index) {
|
||||
remaining++;
|
||||
return function (value) {
|
||||
results[index] = value;
|
||||
if (!--remaining) {
|
||||
resolve(results);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
for (var i = 0, promise; i < promises.length; i++) {
|
||||
promise = promises[i];
|
||||
|
||||
if (promise && typeof promise.then === 'function') {
|
||||
promise.then(resolver(i), reject);
|
||||
} else {
|
||||
results[i] = promise;
|
||||
}
|
||||
}
|
||||
|
||||
if (!remaining) {
|
||||
resolve(results);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Promise.race = function (promises) {
|
||||
if (!Array.isArray(promises)) {
|
||||
throw new TypeError('You must pass an array to Promise.race().');
|
||||
}
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
for (var i = 0, promise; i < promises.length; i++) {
|
||||
promise = promises[i];
|
||||
|
||||
if (promise && typeof promise.then === 'function') {
|
||||
promise.then(resolve, reject);
|
||||
} else {
|
||||
resolve(promise);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Promise.resolve = function (value) {
|
||||
if (value && typeof value === 'object' && value.constructor === Promise) {
|
||||
return value;
|
||||
}
|
||||
|
||||
return new Promise(function (resolve) {
|
||||
resolve(value);
|
||||
});
|
||||
};
|
||||
|
||||
Promise.reject = function (reason) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
reject(reason);
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = Promise;
|
21
node_modules/pinkie/license
generated
vendored
Normal file
21
node_modules/pinkie/license
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) Vsevolod Strukchinsky <floatdrop@gmail.com> (github.com/floatdrop)
|
||||
|
||||
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.
|
100
node_modules/pinkie/package.json
generated
vendored
Normal file
100
node_modules/pinkie/package.json
generated
vendored
Normal file
@ -0,0 +1,100 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
{
|
||||
"raw": "pinkie@^2.0.0",
|
||||
"scope": null,
|
||||
"escapedName": "pinkie",
|
||||
"name": "pinkie",
|
||||
"rawSpec": "^2.0.0",
|
||||
"spec": ">=2.0.0 <3.0.0",
|
||||
"type": "range"
|
||||
},
|
||||
"/home/burchettm/statsbot/node_modules/pinkie-promise"
|
||||
]
|
||||
],
|
||||
"_from": "pinkie@>=2.0.0 <3.0.0",
|
||||
"_id": "pinkie@2.0.4",
|
||||
"_inCache": true,
|
||||
"_location": "/pinkie",
|
||||
"_nodeVersion": "4.2.4",
|
||||
"_npmUser": {
|
||||
"name": "floatdrop",
|
||||
"email": "floatdrop@gmail.com"
|
||||
},
|
||||
"_npmVersion": "2.14.12",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"raw": "pinkie@^2.0.0",
|
||||
"scope": null,
|
||||
"escapedName": "pinkie",
|
||||
"name": "pinkie",
|
||||
"rawSpec": "^2.0.0",
|
||||
"spec": ">=2.0.0 <3.0.0",
|
||||
"type": "range"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/pinkie-promise"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/pinkie/-/pinkie-2.0.4.tgz",
|
||||
"_shasum": "72556b80cfa0d48a974e80e77248e80ed4f7f870",
|
||||
"_shrinkwrap": null,
|
||||
"_spec": "pinkie@^2.0.0",
|
||||
"_where": "/home/burchettm/statsbot/node_modules/pinkie-promise",
|
||||
"author": {
|
||||
"name": "Vsevolod Strukchinsky",
|
||||
"email": "floatdrop@gmail.com",
|
||||
"url": "github.com/floatdrop"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/floatdrop/pinkie/issues"
|
||||
},
|
||||
"dependencies": {},
|
||||
"description": "Itty bitty little widdle twinkie pinkie ES2015 Promise implementation",
|
||||
"devDependencies": {
|
||||
"core-assert": "^0.1.1",
|
||||
"coveralls": "^2.11.4",
|
||||
"mocha": "*",
|
||||
"nyc": "^3.2.2",
|
||||
"promises-aplus-tests": "*",
|
||||
"xo": "^0.10.1"
|
||||
},
|
||||
"directories": {},
|
||||
"dist": {
|
||||
"shasum": "72556b80cfa0d48a974e80e77248e80ed4f7f870",
|
||||
"tarball": "https://registry.npmjs.org/pinkie/-/pinkie-2.0.4.tgz"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
},
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"gitHead": "8d4a92447a5c62bff9f89756caeb4c9c8770579b",
|
||||
"homepage": "https://github.com/floatdrop/pinkie",
|
||||
"keywords": [
|
||||
"promise",
|
||||
"promises",
|
||||
"es2015",
|
||||
"es6"
|
||||
],
|
||||
"license": "MIT",
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "floatdrop",
|
||||
"email": "floatdrop@gmail.com"
|
||||
}
|
||||
],
|
||||
"name": "pinkie",
|
||||
"optionalDependencies": {},
|
||||
"readme": "ERROR: No README data found!",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/floatdrop/pinkie.git"
|
||||
},
|
||||
"scripts": {
|
||||
"coverage": "nyc report --reporter=text-lcov | coveralls",
|
||||
"test": "xo && nyc mocha"
|
||||
},
|
||||
"version": "2.0.4"
|
||||
}
|
83
node_modules/pinkie/readme.md
generated
vendored
Normal file
83
node_modules/pinkie/readme.md
generated
vendored
Normal file
@ -0,0 +1,83 @@
|
||||
<h1 align="center">
|
||||
<br>
|
||||
<img width="256" src="media/logo.png" alt="pinkie">
|
||||
<br>
|
||||
<br>
|
||||
</h1>
|
||||
|
||||
> Itty bitty little widdle twinkie pinkie [ES2015 Promise](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-promise-objects) implementation
|
||||
|
||||
[](https://travis-ci.org/floatdrop/pinkie) [](https://coveralls.io/github/floatdrop/pinkie?branch=master)
|
||||
|
||||
There are [tons of Promise implementations](https://github.com/promises-aplus/promises-spec/blob/master/implementations.md#standalone) out there, but all of them focus on browser compatibility and are often bloated with functionality.
|
||||
|
||||
This module is an exact Promise specification polyfill (like [native-promise-only](https://github.com/getify/native-promise-only)), but in Node.js land (it should be browserify-able though).
|
||||
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install --save pinkie
|
||||
```
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
var fs = require('fs');
|
||||
var Promise = require('pinkie');
|
||||
|
||||
new Promise(function (resolve, reject) {
|
||||
fs.readFile('foo.json', 'utf8', function (err, data) {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
|
||||
resolve(data);
|
||||
});
|
||||
});
|
||||
//=> Promise
|
||||
```
|
||||
|
||||
|
||||
### API
|
||||
|
||||
`pinkie` exports bare [ES2015 Promise](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-promise-objects) implementation and polyfills [Node.js rejection events](https://nodejs.org/api/process.html#process_event_unhandledrejection). In case you forgot:
|
||||
|
||||
#### new Promise(executor)
|
||||
|
||||
Returns new instance of `Promise`.
|
||||
|
||||
##### executor
|
||||
|
||||
*Required*
|
||||
Type: `function`
|
||||
|
||||
Function with two arguments `resolve` and `reject`. The first argument fulfills the promise, the second argument rejects it.
|
||||
|
||||
#### pinkie.all(promises)
|
||||
|
||||
Returns a promise that resolves when all of the promises in the `promises` Array argument have resolved.
|
||||
|
||||
#### pinkie.race(promises)
|
||||
|
||||
Returns a promise that resolves or rejects as soon as one of the promises in the `promises` Array resolves or rejects, with the value or reason from that promise.
|
||||
|
||||
#### pinkie.reject(reason)
|
||||
|
||||
Returns a Promise object that is rejected with the given `reason`.
|
||||
|
||||
#### pinkie.resolve(value)
|
||||
|
||||
Returns a Promise object that is resolved with the given `value`. If the `value` is a thenable (i.e. has a then method), the returned promise will "follow" that thenable, adopting its eventual state; otherwise the returned promise will be fulfilled with the `value`.
|
||||
|
||||
|
||||
## Related
|
||||
|
||||
- [pinkie-promise](https://github.com/floatdrop/pinkie-promise) - Returns the native Promise or this module
|
||||
|
||||
|
||||
## License
|
||||
|
||||
MIT © [Vsevolod Strukchinsky](http://github.com/floatdrop)
|
Reference in New Issue
Block a user