Finished script
This commit is contained in:
1112
node_modules/ping/.eslintrc.json
generated
vendored
Normal file
1112
node_modules/ping/.eslintrc.json
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
17
node_modules/ping/.gitattributes
generated
vendored
Normal file
17
node_modules/ping/.gitattributes
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
# Auto detect text files and perform LF normalization
|
||||
* text eol=lf
|
||||
|
||||
# Custom for Visual Studio
|
||||
*.cs diff=csharp
|
||||
|
||||
# Standard to msysgit
|
||||
*.doc diff=astextplain
|
||||
*.DOC diff=astextplain
|
||||
*.docx diff=astextplain
|
||||
*.DOCX diff=astextplain
|
||||
*.dot diff=astextplain
|
||||
*.DOT diff=astextplain
|
||||
*.pdf diff=astextplain
|
||||
*.PDF diff=astextplain
|
||||
*.rtf diff=astextplain
|
||||
*.RTF diff=astextplain
|
||||
16
node_modules/ping/.npmignore
generated
vendored
Normal file
16
node_modules/ping/.npmignore
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
lib-cov
|
||||
*.seed
|
||||
*.log
|
||||
*.csv
|
||||
*.dat
|
||||
*.out
|
||||
*.pid
|
||||
*.gz
|
||||
*.tgz
|
||||
|
||||
pids
|
||||
logs
|
||||
results
|
||||
|
||||
node_modules
|
||||
npm-debug.log
|
||||
18
node_modules/ping/.travis.yml
generated
vendored
Normal file
18
node_modules/ping/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
language: node_js
|
||||
cache:
|
||||
directories:
|
||||
- node_modules
|
||||
node_js:
|
||||
- '6'
|
||||
- '5'
|
||||
- '4'
|
||||
- iojs-v3
|
||||
- iojs-v2
|
||||
- iojs-v1
|
||||
- '0.12'
|
||||
- '0.11'
|
||||
- '0.10'
|
||||
- '0.8'
|
||||
before_script:
|
||||
# This makes ping work in tests.
|
||||
- /bin/ping -n -w 1 -c 1 127.0.0.1
|
||||
57
node_modules/ping/CONTRIBUTING.md
generated
vendored
Normal file
57
node_modules/ping/CONTRIBUTING.md
generated
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
# Contributing
|
||||
|
||||
We welcome patches and features. There are however a few things that are
|
||||
required before your pull request can be merged.
|
||||
|
||||
# Tests
|
||||
|
||||
## How to write a new test case
|
||||
|
||||
As output from system ping varied on languages and OS, our parser may fail
|
||||
on new languages or OS. To improve the correctness and coverage for this
|
||||
module, we need to gather output from those system pings.
|
||||
|
||||
### Upload a fixture about system ping
|
||||
|
||||
Suppose you are using `macos` in language `en`, you have a problem for running
|
||||
our module. Please upload a capture of your system ping in folder
|
||||
`test/fixture/$OS/$LANGUAGE`. In this case, the name of folder will be
|
||||
`test/fixture/macos/en`
|
||||
|
||||
### Write expected answer in answer.json
|
||||
|
||||
NOTE: we recommend to use [this online editor][1] for editing the content for
|
||||
`answer.json`
|
||||
|
||||
To verify the correctness of our module on your new fixture, please provide
|
||||
the expected answer in `test/fixture/answer.json`.
|
||||
|
||||
Format of the key name is `$OS_$LANGUAGE_$FILENAME`. In our case, this is
|
||||
`macos_en_sample1`.
|
||||
|
||||
Value of that key should be the result from our command.
|
||||
|
||||
```
|
||||
{
|
||||
"host": "google.com",
|
||||
"numeric_host": "172.217.24.46",
|
||||
"alive": true,
|
||||
"output": "PING google.com (172.217.24.46): 56 data bytes\n64 bytes from 172.217.24.46: icmp_seq=0 ttl=54 time=5.371 ms\n64 bytes from 172.217.24.46: icmp_seq=1 ttl=54 time=4.269 ms\n64 bytes from 172.217.24.46: icmp_seq=2 ttl=54 time=4.970 ms\n64 bytes from 172.217.24.46: icmp_seq=3 ttl=54 time=5.228 ms\n\n--- google.com ping statistics ---\n4 packets transmitted, 4 packets received, 0.0% packet loss\nround-trip min/avg/max/stddev = 4.269/4.960/5.371/0.424 ms\n",
|
||||
"time": 5.371,
|
||||
"min": 4.269,
|
||||
"max": 4.96,
|
||||
"avg": 5.371,
|
||||
"stddev": 0.424
|
||||
}
|
||||
```
|
||||
|
||||
## Running test cases
|
||||
|
||||
We trust tesed codes. Please run below command for testing before sending
|
||||
a pull request
|
||||
|
||||
```
|
||||
$ grunt test
|
||||
```
|
||||
|
||||
[1]: http://www.jsoneditoronline.org/
|
||||
22
node_modules/ping/Gruntfile.js
generated
vendored
Normal file
22
node_modules/ping/Gruntfile.js
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function (grunt) {
|
||||
grunt.initConfig({
|
||||
eslint: {
|
||||
src: ['lib/*.js', 'lib/**/*.js'],
|
||||
options: {
|
||||
configFile: '.eslintrc.json',
|
||||
},
|
||||
},
|
||||
mochaTest: {
|
||||
src: ['test/test-*.js'],
|
||||
options: {
|
||||
reporter: 'dot',
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
grunt.loadNpmTasks('gruntify-eslint');
|
||||
grunt.loadNpmTasks('grunt-mocha-test');
|
||||
grunt.registerTask('test', ['eslint', 'mochaTest']);
|
||||
};
|
||||
8
node_modules/ping/LICENSE
generated
vendored
Normal file
8
node_modules/ping/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
MIT License
|
||||
Copyright (c) 2016 Daniel Zelisko
|
||||
|
||||
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.
|
||||
148
node_modules/ping/README.md
generated
vendored
Normal file
148
node_modules/ping/README.md
generated
vendored
Normal file
@@ -0,0 +1,148 @@
|
||||
#NODE-PING
|
||||
|
||||
a ping wrapper for nodejs
|
||||
|
||||
@last-modified: 2016-10-21 12:43
|
||||
|
||||
#LICENSE MIT
|
||||
|
||||
(C) Daniel Zelisko
|
||||
|
||||
http://github.com/danielzzz/node-ping
|
||||
|
||||
#DESCRIPTION
|
||||
|
||||
node-ping is a simple wrapper for the system ping utility
|
||||
|
||||
#INSTALLATION
|
||||
|
||||
npm install ping
|
||||
|
||||
#USAGE
|
||||
|
||||
Below are examples extracted from `examples`
|
||||
|
||||
##Tradition calls
|
||||
|
||||
```js
|
||||
var ping = require('ping');
|
||||
|
||||
var hosts = ['192.168.1.1', 'google.com', 'yahoo.com'];
|
||||
hosts.forEach(function(host){
|
||||
ping.sys.probe(host, function(isAlive){
|
||||
var msg = isAlive ? 'host ' + host + ' is alive' : 'host ' + host + ' is dead';
|
||||
console.log(msg);
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
##Tradition calls with configuration
|
||||
|
||||
```js
|
||||
var cfg = {
|
||||
timeout: 10,
|
||||
// WARNING: -i 2 may not work in other platform like window
|
||||
extra: ["-i 2"],
|
||||
};
|
||||
|
||||
hosts.forEach(function(host){
|
||||
ping.sys.probe(host, function(isAlive){
|
||||
var msg = isAlive ? 'host ' + host + ' is alive' : 'host ' + host + ' is dead';
|
||||
console.log(msg);
|
||||
}, cfg);
|
||||
});
|
||||
```
|
||||
|
||||
##Promise wrapper
|
||||
|
||||
```js
|
||||
var ping = require('ping');
|
||||
|
||||
var hosts = ['192.168.1.1', 'google.com', 'yahoo.com'];
|
||||
|
||||
hosts.forEach(function (host) {
|
||||
ping.promise.probe(host)
|
||||
.then(function (res) {
|
||||
console.log(res);
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
##Promise Wrapper with configable ping options
|
||||
|
||||
```js
|
||||
hosts.forEach(function (host) {
|
||||
// WARNING: -i 2 argument may not work in other platform like window
|
||||
ping.promise.probe(host, {
|
||||
timeout: 10,
|
||||
extra: ["-i 2"],
|
||||
}).then(function (res) {
|
||||
console.log(res);
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
### Support configuration
|
||||
|
||||
Below is the possible configuration
|
||||
|
||||
```js
|
||||
/**
|
||||
* Cross platform config representation
|
||||
* @typedef {Object} PingConfig
|
||||
* @property {boolean} numeric - Map IP address to hostname or not
|
||||
* @property {number} timeout - Time duration for ping command to exit
|
||||
* @property {number} min_reply - Exit after sending number of ECHO_REQUEST
|
||||
* @property {string[]} extra - Optional options does not provided
|
||||
*/
|
||||
```
|
||||
|
||||
### Output specification
|
||||
|
||||
* For callback based implementaiton:
|
||||
|
||||
```js
|
||||
/**
|
||||
* Callback after probing given host
|
||||
* @callback probeCallback
|
||||
* @param {boolean} isAlive - Whether target is alive or not
|
||||
* @param {Object} error - Null if no error occurs
|
||||
*/
|
||||
```
|
||||
|
||||
* For promise based implementation
|
||||
|
||||
```js
|
||||
/**
|
||||
* Parsed response
|
||||
* @typedef {object} PingResponse
|
||||
* @param {string} host - The input IP address or HOST
|
||||
* @param {string} numeric_host - Target IP address
|
||||
* @param {boolean} alive - True for existed host
|
||||
* @param {string} output - Raw stdout from system ping
|
||||
* @param {number} time - Time (float) in ms for first successful ping response
|
||||
* @param {string} min - Minimum time for collection records
|
||||
* @param {string} max - Maximum time for collection records
|
||||
* @param {string} avg - Average time for collection records
|
||||
* @param {string} stddev - Standard deviation time for collected records
|
||||
*/
|
||||
```
|
||||
|
||||
#### Note
|
||||
|
||||
* Since `ping` in this module relies on the `ping` from underlying platform,
|
||||
arguments in `PingConfig.extra` will definitely be varied across different
|
||||
platforms.
|
||||
|
||||
* However, `numeric`, `timeout` and `min_reply` have been abstracted. Values for
|
||||
them are expected to be cross platform.
|
||||
|
||||
* By setting `numeric`, `timeout` or `min_reply` to false, you can run `ping`
|
||||
without corresponding arguments.
|
||||
|
||||
# Contributing
|
||||
|
||||
Before opening a pull request please make sure your changes follow the
|
||||
[contribution guidelines][1].
|
||||
|
||||
[1]: https://github.com/danielzzz/node-ping/blob/master/CONTRIBUTING.md
|
||||
25
node_modules/ping/examples/example.js
generated
vendored
Normal file
25
node_modules/ping/examples/example.js
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
//-------- example -----------------------
|
||||
|
||||
var ping = require('../index');
|
||||
|
||||
var hosts = ['192.168.1.1', 'google.com', 'yahoo.com'];
|
||||
hosts.forEach(function(host){
|
||||
// Running with default config
|
||||
ping.sys.probe(host, function(isAlive){
|
||||
var msg = isAlive ? 'host ' + host + ' is alive' : 'host ' + host + ' is dead';
|
||||
console.log(msg);
|
||||
});
|
||||
|
||||
// Running with custom config
|
||||
ping.sys.probe(host, function(isAlive){
|
||||
var msg = isAlive ? 'host ' + host + ' is alive' : 'host ' + host + ' is dead';
|
||||
console.log(msg);
|
||||
}, {extra: ["-i 2"]});
|
||||
|
||||
// Running ping with some default argument gone
|
||||
ping.sys.probe(host, function(isAlive){
|
||||
var msg = isAlive ? 'host ' + host + ' is alive' : 'host ' + host + ' is dead';
|
||||
console.log(msg);
|
||||
}, {extra: ["-i 2"], timeout: false});
|
||||
});
|
||||
|
||||
39
node_modules/ping/examples/example2.js
generated
vendored
Normal file
39
node_modules/ping/examples/example2.js
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
var ping = require("../index");
|
||||
|
||||
var hosts = ['192.168.1.1', 'google.com', 'yahoo.com'];
|
||||
|
||||
// Running with default config
|
||||
hosts.forEach(function (host) {
|
||||
ping.promise.probe(host)
|
||||
.then(function (res) {
|
||||
console.log(res);
|
||||
})
|
||||
.done();
|
||||
});
|
||||
|
||||
// Running with custom config
|
||||
hosts.forEach(function (host) {
|
||||
// WARNING: -i 2 argument may not work in other platform like window
|
||||
ping.promise.probe(host, {
|
||||
timeout: 10,
|
||||
extra: ["-i", "2"],
|
||||
})
|
||||
.then(function (res) {
|
||||
console.log(res);
|
||||
})
|
||||
.done();
|
||||
});
|
||||
|
||||
// Running ping with some default argument gone
|
||||
hosts.forEach(function (host) {
|
||||
// WARNING: -i 2 argument may not work in other platform like window
|
||||
ping.promise.probe(host, {
|
||||
timeout: false,
|
||||
// Below extra arguments may not work in platforms other than linux
|
||||
extra: ["-i", "2"],
|
||||
})
|
||||
.then(function (res) {
|
||||
console.log(res);
|
||||
})
|
||||
.done();
|
||||
});
|
||||
7
node_modules/ping/index.js
generated
vendored
Normal file
7
node_modules/ping/index.js
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
var ping = {};
|
||||
|
||||
ping.sys = require('./lib/ping-sys');
|
||||
//ping.pcap = require('./lib/ping-pcap');
|
||||
ping.promise = require("./lib/ping-promise");
|
||||
|
||||
module.exports = ping;
|
||||
111
node_modules/ping/lib/builder/factory.js
generated
vendored
Normal file
111
node_modules/ping/lib/builder/factory.js
generated
vendored
Normal file
@@ -0,0 +1,111 @@
|
||||
'use strict';
|
||||
|
||||
var __ = require('underscore');
|
||||
var util = require('util');
|
||||
|
||||
// Our library
|
||||
var linuxBuilder = require('./linux');
|
||||
var macBuilder = require('./mac');
|
||||
var winBuilder = require('./win');
|
||||
|
||||
/**
|
||||
* A factory creates argument builders for different platform
|
||||
* @constructor
|
||||
*/
|
||||
function factory() {}
|
||||
|
||||
/**
|
||||
* Check out linux platform
|
||||
*/
|
||||
factory.isLinux = function (p) {
|
||||
var platforms = [
|
||||
'aix',
|
||||
'linux',
|
||||
];
|
||||
|
||||
return platforms.indexOf(p) >= 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* Check out macos platform
|
||||
*/
|
||||
factory.isMacOS = function (p) {
|
||||
var platforms = [
|
||||
'darwin',
|
||||
'freebsd',
|
||||
];
|
||||
|
||||
return platforms.indexOf(p) >= 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* Check out window platform
|
||||
*/
|
||||
factory.isWindow = function (p) {
|
||||
return p && p.match(/^win/) !== null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Check whether given platform is supported
|
||||
* @param {string} p - Name of the platform
|
||||
* @return {bool} - True or False
|
||||
*/
|
||||
factory.isPlatformSupport = function (p) {
|
||||
return __.some([
|
||||
this.isWindow(p),
|
||||
this.isLinux(p),
|
||||
this.isMacOS(p),
|
||||
]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Return a path to the ping executable in the system
|
||||
* @param {string} platform - Name of the platform
|
||||
* @return {object} - Argument builder
|
||||
* @throw if given platform is not supported
|
||||
*/
|
||||
factory.getExecutablePath = function (platform) {
|
||||
if (!this.isPlatformSupport(platform)) {
|
||||
throw new Error(util.format('Platform |%s| is not support', platform));
|
||||
}
|
||||
|
||||
var ret = null;
|
||||
|
||||
if (platform === 'aix') {
|
||||
ret = '/usr/sbin/ping';
|
||||
} else if (factory.isLinux(platform)) {
|
||||
ret = '/bin/ping';
|
||||
} else if (factory.isWindow(platform)) {
|
||||
ret = process.env.SystemRoot + '/system32/ping.exe';
|
||||
} else if (factory.isMacOS(platform)) {
|
||||
ret = '/sbin/ping';
|
||||
}
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a builder
|
||||
* @param {string} platform - Name of the platform
|
||||
* @return {object} - Argument builder
|
||||
* @throw if given platform is not supported
|
||||
*/
|
||||
factory.createBuilder = function (platform) {
|
||||
if (!this.isPlatformSupport(platform)) {
|
||||
throw new Error(util.format('Platform |%s| is not support', platform));
|
||||
}
|
||||
|
||||
var ret = null;
|
||||
|
||||
if (factory.isLinux(platform)) {
|
||||
ret = linuxBuilder;
|
||||
} else if (factory.isWindow(platform)) {
|
||||
ret = winBuilder;
|
||||
} else if (factory.isMacOS(platform)) {
|
||||
ret = macBuilder;
|
||||
}
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
module.exports = factory;
|
||||
75
node_modules/ping/lib/builder/linux.js
generated
vendored
Normal file
75
node_modules/ping/lib/builder/linux.js
generated
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* A builder builds command line arguments for ping in linux environment
|
||||
* @module lib/builder/linux
|
||||
*/
|
||||
var util = require('util');
|
||||
|
||||
var builder = {};
|
||||
|
||||
/**
|
||||
* Cross platform config representation
|
||||
* @typedef {Object} PingConfig
|
||||
* @property {boolean} numeric - Map IP address to hostname or not
|
||||
* @property {number} timeout - Time duration for ping command to exit
|
||||
* @property {number} min_reply - Exit after sending number of ECHO_REQUEST
|
||||
* @property {string[]} extra - Optional options does not provided
|
||||
*/
|
||||
|
||||
var defaultConfig = {
|
||||
numeric: true,
|
||||
timeout: 2,
|
||||
min_reply: 1,
|
||||
extra: [],
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the finalized array of command line arguments
|
||||
* @param {string} target - hostname or ip address
|
||||
* @param {PingConfig} [config] - Configuration object for cmd line argument
|
||||
* @return {string[]} - Command line argument according to the configuration
|
||||
*/
|
||||
builder.getResult = function (target, config) {
|
||||
var _config = config || {};
|
||||
|
||||
// Empty argument
|
||||
var ret = [];
|
||||
|
||||
// Make every key in config has been setup properly
|
||||
var keys = ['numeric', 'timeout', 'min_reply', 'extra'];
|
||||
keys.forEach(function (k) {
|
||||
// Falsy value will be overrided without below checking
|
||||
if (typeof(_config[k]) !== 'boolean') {
|
||||
_config[k] = _config[k] || defaultConfig[k];
|
||||
}
|
||||
});
|
||||
|
||||
if (_config.numeric) {
|
||||
ret.push('-n');
|
||||
}
|
||||
|
||||
if (_config.timeout) {
|
||||
ret = ret.concat([
|
||||
'-w',
|
||||
util.format('%d', _config.timeout),
|
||||
]);
|
||||
}
|
||||
|
||||
if (_config.min_reply) {
|
||||
ret = ret.concat([
|
||||
'-c',
|
||||
util.format('%d', _config.min_reply),
|
||||
]);
|
||||
}
|
||||
|
||||
if (_config.extra) {
|
||||
ret = ret.concat(_config.extra);
|
||||
}
|
||||
|
||||
ret.push(target);
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
module.exports = builder;
|
||||
75
node_modules/ping/lib/builder/mac.js
generated
vendored
Normal file
75
node_modules/ping/lib/builder/mac.js
generated
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* A builder builds command line arguments for ping in mac environment
|
||||
* @module lib/builder/mac
|
||||
*/
|
||||
var util = require('util');
|
||||
|
||||
var builder = {};
|
||||
|
||||
/**
|
||||
* Cross platform config representation
|
||||
* @typedef {Object} PingConfig
|
||||
* @property {boolean} numeric - Map IP address to hostname or not
|
||||
* @property {number} timeout - Time duration for ping command to exit
|
||||
* @property {number} min_reply - Exit after sending number of ECHO_REQUEST
|
||||
* @property {string[]} extra - Optional options does not provided
|
||||
*/
|
||||
|
||||
var defaultConfig = {
|
||||
numeric: true,
|
||||
timeout: 2,
|
||||
min_reply: 1,
|
||||
extra: [],
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the finalized array of command line arguments
|
||||
* @param {string} target - hostname or ip address
|
||||
* @param {PingConfig} [config] - Configuration object for cmd line argument
|
||||
* @return {string[]} - Command line argument according to the configuration
|
||||
*/
|
||||
builder.getResult = function (target, config) {
|
||||
var _config = config || {};
|
||||
|
||||
// Empty argument
|
||||
var ret = [];
|
||||
|
||||
// Make every key in config has been setup properly
|
||||
var keys = ['numeric', 'timeout', 'min_reply', 'extra'];
|
||||
keys.forEach(function (k) {
|
||||
// Falsy value will be overrided without below checking
|
||||
if (typeof(_config[k]) !== 'boolean') {
|
||||
_config[k] = _config[k] || defaultConfig[k];
|
||||
}
|
||||
});
|
||||
|
||||
if (_config.numeric) {
|
||||
ret.push('-n');
|
||||
}
|
||||
|
||||
if (_config.timeout) {
|
||||
ret = ret.concat([
|
||||
'-t',
|
||||
util.format('%d', _config.timeout),
|
||||
]);
|
||||
}
|
||||
|
||||
if (_config.min_reply) {
|
||||
ret = ret.concat([
|
||||
'-c',
|
||||
util.format('%d', _config.min_reply),
|
||||
]);
|
||||
}
|
||||
|
||||
if (_config.extra) {
|
||||
ret = ret.concat(_config.extra);
|
||||
}
|
||||
|
||||
ret.push(target);
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
module.exports = builder;
|
||||
78
node_modules/ping/lib/builder/win.js
generated
vendored
Normal file
78
node_modules/ping/lib/builder/win.js
generated
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* A builder builds command line arguments for ping in window environment
|
||||
* @module lib/builder/win
|
||||
*/
|
||||
var util = require('util');
|
||||
|
||||
var builder = {};
|
||||
|
||||
/**
|
||||
* Cross platform config representation
|
||||
* @typedef {Object} PingConfig
|
||||
* @property {boolean} numeric - Map IP address to hostname or not
|
||||
* @property {number} timeout - Time duration for ping command to exit
|
||||
* @property {number} min_reply - Exit after sending number of ECHO_REQUEST
|
||||
* @property {string[]} extra - Optional options does not provided
|
||||
*/
|
||||
|
||||
var defaultConfig = {
|
||||
numeric: true,
|
||||
timeout: 5,
|
||||
min_reply: 1,
|
||||
extra: [],
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the finalized array of command line arguments
|
||||
* @param {string} target - hostname or ip address
|
||||
* @param {PingConfig} [config] - Configuration object for cmd line argument
|
||||
* @return {string[]} - Command line argument according to the configuration
|
||||
*/
|
||||
builder.getResult = function (target, config) {
|
||||
var _config = config || {};
|
||||
|
||||
// Empty argument
|
||||
var ret = [];
|
||||
|
||||
// Make every key in config has been setup properly
|
||||
var keys = ['numeric', 'timeout', 'min_reply', 'extra'];
|
||||
keys.forEach(function (k) {
|
||||
// Falsy value will be overrided without below checking
|
||||
if (typeof(_config[k]) !== 'boolean') {
|
||||
_config[k] = _config[k] || defaultConfig[k];
|
||||
}
|
||||
});
|
||||
|
||||
if (!_config.numeric) {
|
||||
ret.push('-a');
|
||||
}
|
||||
|
||||
if (_config.timeout) {
|
||||
// refs #56: Unit problem
|
||||
// Our timeout is in second while timeout in window is in milliseconds
|
||||
// so we need to convert our units accordingly
|
||||
ret = ret.concat([
|
||||
'-w',
|
||||
util.format('%d', _config.timeout * 1000),
|
||||
]);
|
||||
}
|
||||
|
||||
if (_config.min_reply) {
|
||||
ret = ret.concat([
|
||||
'-n',
|
||||
util.format('%d', _config.min_reply),
|
||||
]);
|
||||
}
|
||||
|
||||
if (_config.extra) {
|
||||
ret = ret.concat(_config.extra);
|
||||
}
|
||||
|
||||
ret.push(target);
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
module.exports = builder;
|
||||
181
node_modules/ping/lib/parser/base.js
generated
vendored
Normal file
181
node_modules/ping/lib/parser/base.js
generated
vendored
Normal file
@@ -0,0 +1,181 @@
|
||||
'use strict';
|
||||
|
||||
/* eslint no-unused-vars: 0 */
|
||||
|
||||
var __ = require('underscore');
|
||||
|
||||
/**
|
||||
* Parsed response
|
||||
* @typedef {object} PingResponse
|
||||
* @param {string} host - The input IP address or HOST
|
||||
* @param {string} numeric_host - Target IP address
|
||||
* @param {boolean} alive - True for existed host
|
||||
* @param {string} output - Raw stdout from system ping
|
||||
* @param {number} time - Time (float) in ms for first successful ping response
|
||||
* @param {string} min - Minimum time for collection records
|
||||
* @param {string} max - Maximum time for collection records
|
||||
* @param {string} avg - Average time for collection records
|
||||
* @param {string} stddev - Standard deviation time for collected records
|
||||
*/
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
function parser() {
|
||||
// Initial state is 0
|
||||
this._state = 0;
|
||||
|
||||
// Initial cache value
|
||||
this._response = {
|
||||
host: 'unknown',
|
||||
alive: false,
|
||||
output: 'unknown',
|
||||
time: 'unknown',
|
||||
min: 'unknown',
|
||||
max: 'unknown',
|
||||
avg: 'unknown',
|
||||
stddev: 'unknown',
|
||||
};
|
||||
|
||||
// Initial times storage for ping time
|
||||
this._times = [];
|
||||
|
||||
// Initial lines storage for ping output
|
||||
this._lines = [];
|
||||
|
||||
// strip string regexp
|
||||
this._stripRegex = /[ ]*\r?\n?$/g;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enum for parser states
|
||||
* @readonly
|
||||
* @enum {number}
|
||||
*/
|
||||
parser.prototype.STATES = {
|
||||
INIT: 0,
|
||||
HEADER: 1,
|
||||
BODY: 2,
|
||||
FOOTER: 3,
|
||||
END: 4,
|
||||
};
|
||||
|
||||
/**
|
||||
* Change state of this parser
|
||||
* @param {number} state - parser.STATES
|
||||
* @return {this} - This instance
|
||||
*/
|
||||
parser.prototype._changeState = function (state) {
|
||||
var states = __.values(this.STATES);
|
||||
if (states.indexOf(state) < 0) {
|
||||
throw new Error('Unknown state');
|
||||
}
|
||||
|
||||
this._state = state;
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Process output's header
|
||||
* @param {string} line - A line from system ping
|
||||
*/
|
||||
parser.prototype._processHeader = function (line) {
|
||||
throw new Error('Subclass should implement this method');
|
||||
};
|
||||
|
||||
/**
|
||||
* Process output's body
|
||||
* @param {string} line - A line from system ping
|
||||
*/
|
||||
parser.prototype._processBody = function (line) {
|
||||
throw new Error('Subclass should implement this method');
|
||||
};
|
||||
|
||||
/**
|
||||
* Process output's footer
|
||||
* @param {string} line - A line from system ping
|
||||
*/
|
||||
parser.prototype._processFooter = function (line) {
|
||||
throw new Error('Subclass should implement this method');
|
||||
};
|
||||
|
||||
/**
|
||||
* Process a line from system ping
|
||||
* @param {string} line - A line from system ping
|
||||
* @return {this} - This instance
|
||||
*/
|
||||
parser.prototype.eat = function (line) {
|
||||
var headerStates = [
|
||||
this.STATES.INIT,
|
||||
this.STATES.HEADER,
|
||||
];
|
||||
|
||||
// Store lines
|
||||
this._lines.push(line);
|
||||
|
||||
// Strip all space \r\n at the end
|
||||
var _line = line.replace(this._stripRegex, '');
|
||||
|
||||
if (_line.length === 0) {
|
||||
// Do nothing if this is an empty line
|
||||
} else if (headerStates.indexOf(this._state) >= 0) {
|
||||
this._processHeader(_line);
|
||||
} else if (this._state === this.STATES.BODY) {
|
||||
this._processBody(_line);
|
||||
} else if (this._state === this.STATES.FOOTER) {
|
||||
this._processFooter(_line);
|
||||
} else if (this._state === this.STATES.END) {
|
||||
// Do nothing
|
||||
} else {
|
||||
throw new Error('Unknown state');
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get results after parsing certain lines from system ping
|
||||
* @return {PingResponse} - Response from parsing ping output
|
||||
*/
|
||||
parser.prototype.getResult = function () {
|
||||
var ret = __.extend({}, this._response);
|
||||
|
||||
// Concat output
|
||||
ret.output = this._lines.join('\n');
|
||||
|
||||
// Determine alive
|
||||
ret.alive = this._times.length > 0;
|
||||
|
||||
// Update time at first successful line
|
||||
if (ret.alive) {
|
||||
ret.time = this._response.time = this._times[0];
|
||||
}
|
||||
|
||||
// Get stddev
|
||||
if (
|
||||
ret.stddev === 'unknown' && ret.alive
|
||||
) {
|
||||
var N = this._times.length;
|
||||
|
||||
var variances = __.reduce(this._times, function (m, time) {
|
||||
return m + Math.pow((time - ret.avg), 2);
|
||||
}, 0) / N;
|
||||
|
||||
ret.stddev = Math.round(
|
||||
Math.sqrt(variances) * 1000
|
||||
) / 1000;
|
||||
}
|
||||
|
||||
// Fix min, avg, max, stddev up to 3 decimal points
|
||||
__.each(['min', 'avg', 'max', 'stddev'], function (key) {
|
||||
var v = ret[key];
|
||||
if (__.isNumber(v)) {
|
||||
ret[key] = v.toFixed(3);
|
||||
}
|
||||
});
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
module.exports = parser;
|
||||
39
node_modules/ping/lib/parser/factory.js
generated
vendored
Normal file
39
node_modules/ping/lib/parser/factory.js
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
'use strict';
|
||||
|
||||
var util = require('util');
|
||||
|
||||
var builderFactory = require('../builder/factory');
|
||||
var WinParser = require('./win');
|
||||
var MacParser = require('./mac');
|
||||
var LinuxParser = require('./linux');
|
||||
|
||||
/**
|
||||
* A factory creates a parser for parsing output from system ping
|
||||
* @constructor
|
||||
*/
|
||||
function factory() {}
|
||||
|
||||
/**
|
||||
* Create a parser for a given platform
|
||||
* @param {string} platform - Name of the platform
|
||||
* @return {object} - Parser
|
||||
* @throw if given platform is not supported
|
||||
*/
|
||||
factory.createParser = function (platform) {
|
||||
if (!builderFactory.isPlatformSupport(platform)) {
|
||||
throw new Error(util.format('Platform |%s| is not support', platform));
|
||||
}
|
||||
|
||||
var ret = null;
|
||||
if (builderFactory.isWindow(platform)) {
|
||||
ret = new WinParser();
|
||||
} else if (builderFactory.isMacOS(platform)) {
|
||||
ret = new MacParser();
|
||||
} else if (builderFactory.isLinux(platform)) {
|
||||
ret = new LinuxParser();
|
||||
}
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
module.exports = factory;
|
||||
48
node_modules/ping/lib/parser/linux.js
generated
vendored
Normal file
48
node_modules/ping/lib/parser/linux.js
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
'use strict';
|
||||
|
||||
var util = require('util');
|
||||
var base = require('./base');
|
||||
var MacParser = require('./mac');
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
function LinuxParser() {
|
||||
base.call(this);
|
||||
}
|
||||
|
||||
util.inherits(LinuxParser, base);
|
||||
|
||||
/**
|
||||
* Process output's body
|
||||
* @param {string} line - A line from system ping
|
||||
*/
|
||||
LinuxParser.prototype._processHeader = function (line) {
|
||||
// Get host and numeric_host
|
||||
var tokens = line.split(' ');
|
||||
|
||||
this._response.host = tokens[1];
|
||||
this._response.numeric_host = tokens[2].slice(1, -1);
|
||||
|
||||
this._changeState(this.STATES.BODY);
|
||||
};
|
||||
|
||||
/**
|
||||
* Process output's body
|
||||
* @param {string} line - A line from system ping
|
||||
*/
|
||||
LinuxParser.prototype._processBody = function (line) {
|
||||
// Reuse mac parser implementation
|
||||
MacParser.prototype._processBody.call(this, line);
|
||||
};
|
||||
|
||||
/**
|
||||
* Process output's footer
|
||||
* @param {string} line - A line from system ping
|
||||
*/
|
||||
LinuxParser.prototype._processFooter = function (line) {
|
||||
// Reuse mac parser implementation
|
||||
MacParser.prototype._processFooter.call(this, line);
|
||||
};
|
||||
|
||||
module.exports = LinuxParser;
|
||||
77
node_modules/ping/lib/parser/mac.js
generated
vendored
Normal file
77
node_modules/ping/lib/parser/mac.js
generated
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
'use strict';
|
||||
|
||||
var util = require('util');
|
||||
var __ = require('underscore');
|
||||
|
||||
var base = require('./base');
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
function MacParser() {
|
||||
base.call(this);
|
||||
}
|
||||
|
||||
util.inherits(MacParser, base);
|
||||
|
||||
/**
|
||||
* Process output's header
|
||||
* @param {string} line - A line from system ping
|
||||
*/
|
||||
MacParser.prototype._processHeader = function (line) {
|
||||
// Get host and numeric_host
|
||||
var tokens = line.split(' ');
|
||||
|
||||
this._response.host = tokens[1];
|
||||
this._response.numeric_host = tokens[2].slice(1, -2);
|
||||
|
||||
this._changeState(this.STATES.BODY);
|
||||
};
|
||||
|
||||
/**
|
||||
* Process output's body
|
||||
* @param {string} line - A line from system ping
|
||||
*/
|
||||
MacParser.prototype._processBody = function (line) {
|
||||
// XXX: Assume there is at least 3 '=' can be found
|
||||
var count = (line.match(/=/g) || []).length;
|
||||
if (count >= 3) {
|
||||
var regExp = /([0-9\.]+)[ ]*ms/;
|
||||
var match = regExp.exec(line);
|
||||
this._times.push(parseFloat(match[1], 10));
|
||||
}
|
||||
|
||||
// Change state if it see a '---'
|
||||
if (line.indexOf('---') >= 0) {
|
||||
this._changeState(this.STATES.FOOTER);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Process output's footer
|
||||
* @param {string} line - A line from system ping
|
||||
*/
|
||||
MacParser.prototype._processFooter = function (line) {
|
||||
// XXX: Assume number of keywords '/' more than 3
|
||||
var count = (line.match(/[\/]/g) || []).length;
|
||||
if (count >= 3) {
|
||||
var regExp = /([0-9\.]+)/g;
|
||||
// XXX: Assume min avg max stddev
|
||||
var m1 = regExp.exec(line);
|
||||
var m2 = regExp.exec(line);
|
||||
var m3 = regExp.exec(line);
|
||||
var m4 = regExp.exec(line);
|
||||
|
||||
if (__.all([m1, m2, m3, m4])) {
|
||||
this._response.min = parseFloat(m1[1], 10);
|
||||
this._response.avg = parseFloat(m2[1], 10);
|
||||
this._response.max = parseFloat(m3[1], 10);
|
||||
this._response.stddev = parseFloat(m4[1], 10);
|
||||
this._changeState(this.STATES.END);
|
||||
}
|
||||
|
||||
this._changeState(this.STATES.END);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = MacParser;
|
||||
87
node_modules/ping/lib/parser/win.js
generated
vendored
Normal file
87
node_modules/ping/lib/parser/win.js
generated
vendored
Normal file
@@ -0,0 +1,87 @@
|
||||
'use strict';
|
||||
|
||||
var util = require('util');
|
||||
var __ = require('underscore');
|
||||
|
||||
var base = require('./base');
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
function WinParser() {
|
||||
base.call(this);
|
||||
this._ipv4Regex = /^([0-9]{1,3}\.){3}[0-9]{1,3}$/;
|
||||
}
|
||||
|
||||
util.inherits(WinParser, base);
|
||||
|
||||
/**
|
||||
* Process output's header
|
||||
* @param {string} line - A line from system ping
|
||||
*/
|
||||
WinParser.prototype._processHeader = function (line) {
|
||||
// Get host and numeric_host
|
||||
var tokens = line.split(' ');
|
||||
|
||||
this._response.host = tokens[1];
|
||||
if (this._ipv4Regex.test(this._response.host)) {
|
||||
this._response.numeric_host = tokens[1];
|
||||
} else {
|
||||
this._response.numeric_host = tokens[2].slice(1, -1);
|
||||
}
|
||||
|
||||
this._changeState(this.STATES.BODY);
|
||||
};
|
||||
|
||||
/**
|
||||
* Process output's body
|
||||
* @param {string} line - A line from system ping
|
||||
*/
|
||||
WinParser.prototype._processBody = function (line) {
|
||||
var tokens = line.split(' ');
|
||||
var kvps = __.filter(tokens, function (token) {
|
||||
// Sometime it shows <1ms
|
||||
return token.indexOf('=') >= 0 || token.indexOf('<') >= 0;
|
||||
});
|
||||
|
||||
// kvps.length >= 3 means target is pingable
|
||||
if (kvps.length >= 3) {
|
||||
// XXX: Assume time will alaways get keyword ms for all language
|
||||
var timeKVP = __.find(kvps, function (kvp) {
|
||||
return kvp.indexOf('ms') >= 0;
|
||||
});
|
||||
var regExp = /([0-9\.]+)/;
|
||||
var match = regExp.exec(timeKVP);
|
||||
|
||||
this._times.push(parseFloat(match[1], 10));
|
||||
}
|
||||
|
||||
// Change state if it see a ':' at the end
|
||||
if (line.slice(-1) === ':') {
|
||||
this._changeState(this.STATES.FOOTER);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Process output's footer
|
||||
* @param {string} line - A line from system ping
|
||||
*/
|
||||
WinParser.prototype._processFooter = function (line) {
|
||||
// XXX: Assume there is a keyword ms
|
||||
if (line.indexOf('ms') >= 0) {
|
||||
// XXX: Assume the ordering is Min Max Avg
|
||||
var regExp = /([0-9\.]+)/g;
|
||||
var m1 = regExp.exec(line);
|
||||
var m2 = regExp.exec(line);
|
||||
var m3 = regExp.exec(line);
|
||||
|
||||
if (__.all([m1, m2, m3])) {
|
||||
this._response.min = parseFloat(m1[1], 10);
|
||||
this._response.max = parseFloat(m2[1], 10);
|
||||
this._response.avg = parseFloat(m3[1], 10);
|
||||
this._changeState(this.STATES.END);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = WinParser;
|
||||
46
node_modules/ping/lib/ping-pcap.js
generated
vendored
Normal file
46
node_modules/ping/lib/ping-pcap.js
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
/* eslint-disable */
|
||||
|
||||
/**
|
||||
* LICENSE MIT
|
||||
* (C) Daniel Zelisko
|
||||
* http://github.com/danielzzz/node-ping
|
||||
*
|
||||
* A poor man's ping for node.js
|
||||
* It uses UDP_scanning (as node is not able to generate iCPM packets)
|
||||
* http://en.wikipedia.org/wiki/Port_scanner#UDP_scanning
|
||||
* it may not work correct for hosts that silently drop UDP traffic on their firewall
|
||||
* you need at pcap version 0.1.9 or higher
|
||||
*
|
||||
*/
|
||||
|
||||
var sys = require("util"),
|
||||
pcap = require('pcap');
|
||||
|
||||
var addr = process.argv[3] || 'localhost';
|
||||
setInterval(function() {probe(addr)}, 1000);
|
||||
|
||||
|
||||
function probe(addr) {
|
||||
sys.puts('sending a probe to ' + addr);
|
||||
var dgram = require('dgram');
|
||||
var message = new Buffer("Some bytes");
|
||||
var client = dgram.createSocket("udp4");
|
||||
client.send(message, 0, message.length, 21111, addr);
|
||||
client.close();
|
||||
}
|
||||
|
||||
// create a pcap session
|
||||
pcap_session = pcap.createSession(process.argv[2] || 'eth0', "");
|
||||
|
||||
|
||||
// listen for packets, decode them, and feed the simple printer
|
||||
pcap_session.addListener('packet', function (raw_packet) {
|
||||
var packet = pcap.decode.packet(raw_packet);
|
||||
if (packet.link && packet.link.ip && packet.link.ip.saddr==addr) {
|
||||
packet.link && packet.link.ip && sys.puts(packet.link.ip.saddr + " is alive");
|
||||
}
|
||||
});
|
||||
|
||||
//-------- example ------------------------
|
||||
|
||||
|
||||
87
node_modules/ping/lib/ping-promise.js
generated
vendored
Normal file
87
node_modules/ping/lib/ping-promise.js
generated
vendored
Normal file
@@ -0,0 +1,87 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* LICENSE MIT
|
||||
* (C) Daniel Zelisko
|
||||
* http://github.com/danielzzz/node-ping
|
||||
*
|
||||
* a simple wrapper for ping
|
||||
* Now with support of not only english Windows.
|
||||
*
|
||||
*/
|
||||
|
||||
// System library
|
||||
var util = require('util');
|
||||
var cp = require('child_process');
|
||||
var os = require('os');
|
||||
|
||||
// 3rd-party library
|
||||
var Q = require('q');
|
||||
var __ = require('underscore');
|
||||
|
||||
// Our library
|
||||
var builderFactory = require('./builder/factory');
|
||||
var parserFactory = require('./parser/factory');
|
||||
|
||||
/**
|
||||
* Class::PromisePing
|
||||
*
|
||||
* @param {string} addr - Hostname or ip addres
|
||||
* @param {PingConfig} config - Configuration for command ping
|
||||
* @return {Promise}
|
||||
*/
|
||||
function probe(addr, config) {
|
||||
// Do not reassign function argument
|
||||
var _config = config || {};
|
||||
|
||||
// Convert callback base system command to promise base
|
||||
var deferred = Q.defer();
|
||||
|
||||
// Spawn a ping process
|
||||
var ping = null;
|
||||
var platform = os.platform();
|
||||
var argumentBuilder = builderFactory.createBuilder(platform);
|
||||
ping = cp.spawn(
|
||||
builderFactory.getExecutablePath(platform),
|
||||
argumentBuilder.getResult(addr, _config)
|
||||
);
|
||||
|
||||
// Initial parser
|
||||
var parser = parserFactory.createParser(platform);
|
||||
|
||||
// Register events from system ping
|
||||
ping.once('error', function () {
|
||||
var err = new Error(
|
||||
util.format(
|
||||
'ping.probe: %s. %s',
|
||||
'there was an error while executing the ping program. ',
|
||||
'Check the path or permissions...'
|
||||
)
|
||||
);
|
||||
deferred.reject(err);
|
||||
});
|
||||
|
||||
// Cache all lines from the system ping
|
||||
var outstring = [];
|
||||
ping.stdout.on('data', function (data) {
|
||||
outstring.push(String(data));
|
||||
});
|
||||
|
||||
// Parse lines we have on closing system ping
|
||||
ping.once('close', function () {
|
||||
// Merge lines we have and split it by \n
|
||||
var lines = outstring.join('').split('\n');
|
||||
|
||||
// Parse line one by one
|
||||
__.each(lines, parser.eat, parser);
|
||||
|
||||
// Get result
|
||||
var ret = parser.getResult();
|
||||
|
||||
deferred.resolve(ret);
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
exports.probe = probe;
|
||||
45
node_modules/ping/lib/ping-sys.js
generated
vendored
Normal file
45
node_modules/ping/lib/ping-sys.js
generated
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* LICENSE MIT
|
||||
* (C) Daniel Zelisko
|
||||
* http://github.com/danielzzz/node-ping
|
||||
*
|
||||
* a simple wrapper for ping
|
||||
* Now with support of not only english Windows.
|
||||
*
|
||||
*/
|
||||
|
||||
// Promise implementation
|
||||
var ping = require('./ping-promise');
|
||||
|
||||
// TODO:
|
||||
// 1. Port round trip time to this callback
|
||||
// 2. However, it may breaks backward compatability
|
||||
// 3. Need discussion
|
||||
/**
|
||||
* Callback after probing given host
|
||||
* @callback probeCallback
|
||||
* @param {boolean} isAlive - Whether target is alive or not
|
||||
* @param {Object} error - Null if no error occurs
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class::Ping construtor
|
||||
*
|
||||
* @param {string} addr - Hostname or ip addres
|
||||
* @param {probeCallback} cb - Callback
|
||||
* @param {PingConfig} config - Configuration for command ping
|
||||
*/
|
||||
function probe(addr, cb, config) {
|
||||
// Do not reassign function parameter
|
||||
var _config = config || {};
|
||||
|
||||
return ping.probe(addr, _config).then(function (res) {
|
||||
cb(res.alive, null);
|
||||
}).catch(function (err) {
|
||||
cb(null, err);
|
||||
}).done();
|
||||
}
|
||||
|
||||
exports.probe = probe;
|
||||
130
node_modules/ping/package.json
generated
vendored
Normal file
130
node_modules/ping/package.json
generated
vendored
Normal file
@@ -0,0 +1,130 @@
|
||||
{
|
||||
"_from": "ping",
|
||||
"_id": "ping@0.2.2",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-GA+3UIwdx0eThJvONcgHP5llvOI=",
|
||||
"_location": "/ping",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "tag",
|
||||
"registry": true,
|
||||
"raw": "ping",
|
||||
"name": "ping",
|
||||
"escapedName": "ping",
|
||||
"rawSpec": "",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "latest"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"#USER",
|
||||
"/"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/ping/-/ping-0.2.2.tgz",
|
||||
"_shasum": "180fb7508c1dc74793849bce35c8073f9965bce2",
|
||||
"_spec": "ping",
|
||||
"_where": "D:\\Programming\\Projects\\Down-Detector",
|
||||
"author": {
|
||||
"name": "danielzzz",
|
||||
"email": "daniel@zelisko.net",
|
||||
"url": "http://daniel.zelisko.net"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/danielzzz/node-ping/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Mond Wan",
|
||||
"email": "mondwan.1015@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "dougluce",
|
||||
"email": "doug@tenousiperochhelical.con.com"
|
||||
},
|
||||
{
|
||||
"name": "weihua44"
|
||||
},
|
||||
{
|
||||
"name": "GermanBluefox"
|
||||
},
|
||||
{
|
||||
"name": "mabukar"
|
||||
},
|
||||
{
|
||||
"name": "microacup",
|
||||
"email": "xiangmain@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Andrew Fadeev"
|
||||
},
|
||||
{
|
||||
"name": "Joshua Pruitt",
|
||||
"email": "firefly777@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Stephan van Rooij",
|
||||
"email": "stephan@svrooij.nl",
|
||||
"url": "http://svrooij.nl"
|
||||
},
|
||||
{
|
||||
"name": "Krispin Schulz",
|
||||
"email": "krispinone@googlemail.com",
|
||||
"url": "http://kr1sp1n.io"
|
||||
},
|
||||
{
|
||||
"name": "Kathy Hill"
|
||||
},
|
||||
{
|
||||
"name": "mrMuppet"
|
||||
},
|
||||
{
|
||||
"name": "Adam Heath",
|
||||
"email": "adam@adamheath.me",
|
||||
"url": "http://www.adamheath.me"
|
||||
},
|
||||
{
|
||||
"name": "BlessJah",
|
||||
"email": "blessjah@jacekowski.org"
|
||||
},
|
||||
{
|
||||
"name": "jritsema"
|
||||
}
|
||||
],
|
||||
"dependencies": {
|
||||
"q": "1.x",
|
||||
"underscore": "^1.8.3"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "a simple wrapper for ping",
|
||||
"devDependencies": {
|
||||
"babel-eslint": "^7.0.0",
|
||||
"chai": "2.3.0",
|
||||
"eslint": "^3.8.1",
|
||||
"eslint-config-airbnb": "^12.0.0",
|
||||
"eslint-config-eslint": "^3.0.0",
|
||||
"eslint-plugin-import": "^1.16.0",
|
||||
"eslint-plugin-jsx-a11y": "^2.2.3",
|
||||
"eslint-plugin-react": "^6.4.1",
|
||||
"glob": "^7.1.1",
|
||||
"grunt": "^1.0.1",
|
||||
"grunt-mocha-test": "^0.13.2",
|
||||
"gruntify-eslint": "^3.1.0",
|
||||
"mocha": "2.5.3",
|
||||
"sinon": "1.17.6"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.8"
|
||||
},
|
||||
"homepage": "http://github.com/danielzzz/node-ping",
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"name": "ping",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/danielzzz/node-ping.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "grunt test"
|
||||
},
|
||||
"version": "0.2.2"
|
||||
}
|
||||
68
node_modules/ping/test/fixture/answer.json
generated
vendored
Normal file
68
node_modules/ping/test/fixture/answer.json
generated
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
{
|
||||
"macos_en_sample1": {
|
||||
"host": "google.com",
|
||||
"numeric_host": "172.217.24.46",
|
||||
"alive": true,
|
||||
"output": "PING google.com (172.217.24.46): 56 data bytes\n64 bytes from 172.217.24.46: icmp_seq=0 ttl=54 time=5.371 ms\n64 bytes from 172.217.24.46: icmp_seq=1 ttl=54 time=4.269 ms\n64 bytes from 172.217.24.46: icmp_seq=2 ttl=54 time=4.970 ms\n64 bytes from 172.217.24.46: icmp_seq=3 ttl=54 time=5.228 ms\n\n--- google.com ping statistics ---\n4 packets transmitted, 4 packets received, 0.0% packet loss\nround-trip min/avg/max/stddev = 4.269/4.960/5.371/0.424 ms\n",
|
||||
"time": 5.371,
|
||||
"min": "4.269",
|
||||
"max": "5.371",
|
||||
"avg": "4.960",
|
||||
"stddev": "0.424"
|
||||
},
|
||||
"linux_en_sample1": {
|
||||
"host": "localhost",
|
||||
"numeric_host": "127.0.0.1",
|
||||
"alive": true,
|
||||
"output": "PING localhost (127.0.0.1) 56(84) bytes of data.\n64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.022 ms\n64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.027 ms\n64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.029 ms\n64 bytes from localhost (127.0.0.1): icmp_seq=4 ttl=64 time=0.030 ms\n\n--- localhost ping statistics ---\n4 packets transmitted, 4 received, 0% packet loss, time 2999ms\nrtt min/avg/max/mdev = 0.022/0.027/0.030/0.003 ms\n",
|
||||
"time": 0.022,
|
||||
"min": "0.022",
|
||||
"max": "0.030",
|
||||
"avg": "0.027",
|
||||
"stddev": "0.003"
|
||||
},
|
||||
"window_en_sample1": {
|
||||
"host": "www.some-domain.com",
|
||||
"numeric_host": "127.0.0.1",
|
||||
"alive": true,
|
||||
"output": "Pinging www.some-domain.com [127.0.0.1] with 32 bytes of\nReply from 127.0.0.1: bytes=32 time=564ms TTL=237\nReply from 127.0.0.1: bytes=32 time=555ms TTL=237\nReply from 127.0.0.1: bytes=32 time=554ms TTL=237\nReply from 127.0.0.1: bytes=32 time=548ms TTL=237\n\nPing statistics for 127.0.0.1:\n Packets: Sent = 4, Received = 4, Lost = 0 (0% loss)\n Approximate round trip times in milli-seconds:\n Minimum = 548ms, Maximum = 564ms, Average = 555ms\n",
|
||||
"time": 564,
|
||||
"min": "548.000",
|
||||
"max": "564.000",
|
||||
"avg": "555.000",
|
||||
"stddev": "5.723"
|
||||
},
|
||||
"window_zh_sample1": {
|
||||
"host": "google.com",
|
||||
"numeric_host": "216.58.203.14",
|
||||
"alive": true,
|
||||
"output": "Ping google.com [216.58.203.14] (使用 32 位元組的資料):\n回覆自 216.58.203.14: 位元組=32 時間=2ms TTL=54\n回覆自 216.58.203.14: 位元組=32 時間=2ms TTL=54\n回覆自 216.58.203.14: 位元組=32 時間=3ms TTL=54\n回覆自 216.58.203.14: 位元組=32 時間=3ms TTL=54\n\n216.58.203.14 的 Ping 統計資料:\n 封包: 已傳送 = 4,已收到 = 4, 已遺失 = 0 (0% 遺失),\n 大約的來回時間 (毫秒):\n 最小值 = 2ms,最大值 = 3ms,平均 = 2ms\n",
|
||||
"time": 2,
|
||||
"min": "2.000",
|
||||
"max": "3.000",
|
||||
"avg": "2.000",
|
||||
"stddev": "0.707"
|
||||
},
|
||||
"window_zh_sample2": {
|
||||
"host": "google.com",
|
||||
"numeric_host": "216.58.203.14",
|
||||
"alive": true,
|
||||
"output": "\nPing google.com [216.58.203.14] (使用 32 位元組的資料):\n回覆自 216.58.203.14: 位元組=32 時間=2ms TTL=54\n回覆自 216.58.203.14: 位元組=32 時間=2ms TTL=54\n回覆自 216.58.203.14: 位元組=32 時間=3ms TTL=54\n回覆自 216.58.203.14: 位元組=32 時間=3ms TTL=54\n\n216.58.203.14 的 Ping 統計資料:\n 封包: 已傳送 = 4,已收到 = 4, 已遺失 = 0 (0% 遺失),\n 大約的來回時間 (毫秒):\n 最小值 = 2ms,最大值 = 3ms,平均 = 2ms\n",
|
||||
"time": 2,
|
||||
"min": "2.000",
|
||||
"max": "3.000",
|
||||
"avg": "2.000",
|
||||
"stddev": "0.707"
|
||||
},
|
||||
"window_zh_sample3": {
|
||||
"host": "127.0.0.1",
|
||||
"numeric_host": "127.0.0.1",
|
||||
"alive": true,
|
||||
"output": "\nPing 127.0.0.1 (使用 32 位元組的資料):\n回覆自 127.0.0.1: 位元組=32 時間<1ms TTL=128\n回覆自 127.0.0.1: 位元組=32 時間<1ms TTL=128\n回覆自 127.0.0.1: 位元組=32 時間<1ms TTL=128\n回覆自 127.0.0.1: 位元組=32 時間<1ms TTL=128\n\n127.0.0.1 的 Ping 統計資料:\n 封包: 已傳送 = 4,已收到 = 4, 已遺失 = 0 (0% 遺失),\n 大約的來回時間 (毫秒):\n 最小值 = 0ms,最大值 = 0ms,平均 = 0ms\n",
|
||||
"time": 1,
|
||||
"min": "0.000",
|
||||
"max": "0.000",
|
||||
"avg": "0.000",
|
||||
"stddev": "1.000"
|
||||
}
|
||||
}
|
||||
0
node_modules/ping/test/fixture/linux/.gitdirectory
generated
vendored
Normal file
0
node_modules/ping/test/fixture/linux/.gitdirectory
generated
vendored
Normal file
9
node_modules/ping/test/fixture/linux/en/sample1.txt
generated
vendored
Normal file
9
node_modules/ping/test/fixture/linux/en/sample1.txt
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
PING localhost (127.0.0.1) 56(84) bytes of data.
|
||||
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.022 ms
|
||||
64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.027 ms
|
||||
64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.029 ms
|
||||
64 bytes from localhost (127.0.0.1): icmp_seq=4 ttl=64 time=0.030 ms
|
||||
|
||||
--- localhost ping statistics ---
|
||||
4 packets transmitted, 4 received, 0% packet loss, time 2999ms
|
||||
rtt min/avg/max/mdev = 0.022/0.027/0.030/0.003 ms
|
||||
0
node_modules/ping/test/fixture/macos/.gitdirectory
generated
vendored
Normal file
0
node_modules/ping/test/fixture/macos/.gitdirectory
generated
vendored
Normal file
9
node_modules/ping/test/fixture/macos/en/sample1.txt
generated
vendored
Normal file
9
node_modules/ping/test/fixture/macos/en/sample1.txt
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
PING google.com (172.217.24.46): 56 data bytes
|
||||
64 bytes from 172.217.24.46: icmp_seq=0 ttl=54 time=5.371 ms
|
||||
64 bytes from 172.217.24.46: icmp_seq=1 ttl=54 time=4.269 ms
|
||||
64 bytes from 172.217.24.46: icmp_seq=2 ttl=54 time=4.970 ms
|
||||
64 bytes from 172.217.24.46: icmp_seq=3 ttl=54 time=5.228 ms
|
||||
|
||||
--- google.com ping statistics ---
|
||||
4 packets transmitted, 4 packets received, 0.0% packet loss
|
||||
round-trip min/avg/max/stddev = 4.269/4.960/5.371/0.424 ms
|
||||
0
node_modules/ping/test/fixture/window/.gitdirectory
generated
vendored
Normal file
0
node_modules/ping/test/fixture/window/.gitdirectory
generated
vendored
Normal file
10
node_modules/ping/test/fixture/window/en/sample1.txt
generated
vendored
Normal file
10
node_modules/ping/test/fixture/window/en/sample1.txt
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
Pinging www.some-domain.com [127.0.0.1] with 32 bytes of
|
||||
Reply from 127.0.0.1: bytes=32 time=564ms TTL=237
|
||||
Reply from 127.0.0.1: bytes=32 time=555ms TTL=237
|
||||
Reply from 127.0.0.1: bytes=32 time=554ms TTL=237
|
||||
Reply from 127.0.0.1: bytes=32 time=548ms TTL=237
|
||||
|
||||
Ping statistics for 127.0.0.1:
|
||||
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss)
|
||||
Approximate round trip times in milli-seconds:
|
||||
Minimum = 548ms, Maximum = 564ms, Average = 555ms
|
||||
10
node_modules/ping/test/fixture/window/zh/sample1.txt
generated
vendored
Normal file
10
node_modules/ping/test/fixture/window/zh/sample1.txt
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
Ping google.com [216.58.203.14] (使用 32 位元組的資料):
|
||||
回覆自 216.58.203.14: 位元組=32 時間=2ms TTL=54
|
||||
回覆自 216.58.203.14: 位元組=32 時間=2ms TTL=54
|
||||
回覆自 216.58.203.14: 位元組=32 時間=3ms TTL=54
|
||||
回覆自 216.58.203.14: 位元組=32 時間=3ms TTL=54
|
||||
|
||||
216.58.203.14 的 Ping 統計資料:
|
||||
封包: 已傳送 = 4,已收到 = 4, 已遺失 = 0 (0% 遺失),
|
||||
大約的來回時間 (毫秒):
|
||||
最小值 = 2ms,最大值 = 3ms,平均 = 2ms
|
||||
11
node_modules/ping/test/fixture/window/zh/sample2.txt
generated
vendored
Normal file
11
node_modules/ping/test/fixture/window/zh/sample2.txt
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
|
||||
Ping google.com [216.58.203.14] (使用 32 位元組的資料):
|
||||
回覆自 216.58.203.14: 位元組=32 時間=2ms TTL=54
|
||||
回覆自 216.58.203.14: 位元組=32 時間=2ms TTL=54
|
||||
回覆自 216.58.203.14: 位元組=32 時間=3ms TTL=54
|
||||
回覆自 216.58.203.14: 位元組=32 時間=3ms TTL=54
|
||||
|
||||
216.58.203.14 的 Ping 統計資料:
|
||||
封包: 已傳送 = 4,已收到 = 4, 已遺失 = 0 (0% 遺失),
|
||||
大約的來回時間 (毫秒):
|
||||
最小值 = 2ms,最大值 = 3ms,平均 = 2ms
|
||||
11
node_modules/ping/test/fixture/window/zh/sample3.txt
generated
vendored
Normal file
11
node_modules/ping/test/fixture/window/zh/sample3.txt
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
|
||||
Ping 127.0.0.1 (使用 32 位元組的資料):
|
||||
回覆自 127.0.0.1: 位元組=32 時間<1ms TTL=128
|
||||
回覆自 127.0.0.1: 位元組=32 時間<1ms TTL=128
|
||||
回覆自 127.0.0.1: 位元組=32 時間<1ms TTL=128
|
||||
回覆自 127.0.0.1: 位元組=32 時間<1ms TTL=128
|
||||
|
||||
127.0.0.1 的 Ping 統計資料:
|
||||
封包: 已傳送 = 4,已收到 = 4, 已遺失 = 0 (0% 遺失),
|
||||
大約的來回時間 (毫秒):
|
||||
最小值 = 0ms,最大值 = 0ms,平均 = 0ms
|
||||
61
node_modules/ping/test/load-fixture-path.js
generated
vendored
Normal file
61
node_modules/ping/test/load-fixture-path.js
generated
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
'use strict';
|
||||
|
||||
var path = require('path');
|
||||
var glob = require('glob');
|
||||
|
||||
/**
|
||||
* Check out linux platform
|
||||
*/
|
||||
function isLinux(p) {
|
||||
var platforms = [
|
||||
'aix',
|
||||
'linux',
|
||||
];
|
||||
|
||||
return platforms.indexOf(p) >= 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check out macos platform
|
||||
*/
|
||||
function isMacOS(p) {
|
||||
var platforms = [
|
||||
'darwin',
|
||||
'freebsd',
|
||||
];
|
||||
|
||||
return platforms.indexOf(p) >= 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check out window platform
|
||||
*/
|
||||
function isWindow(p) {
|
||||
return p && p.match(/^win/) !== null;
|
||||
}
|
||||
|
||||
module.exports = function (platform) {
|
||||
var dirname = null;
|
||||
|
||||
if (isLinux(platform)) {
|
||||
dirname = 'linux';
|
||||
} else if (isMacOS(platform)) {
|
||||
dirname = 'macos';
|
||||
} else if (isWindow(platform)) {
|
||||
dirname = 'window';
|
||||
}
|
||||
|
||||
var currentDirectory = path.dirname(__filename);
|
||||
|
||||
var targetDirectory = [currentDirectory, 'fixture'];
|
||||
if (dirname) {
|
||||
targetDirectory.push(dirname);
|
||||
}
|
||||
targetDirectory = targetDirectory.concat([
|
||||
'**',
|
||||
'*.txt',
|
||||
]);
|
||||
targetDirectory = path.posix.join.apply(path.posix, targetDirectory);
|
||||
|
||||
return glob.sync(targetDirectory);
|
||||
};
|
||||
187
node_modules/ping/test/test-ping.js
generated
vendored
Normal file
187
node_modules/ping/test/test-ping.js
generated
vendored
Normal file
@@ -0,0 +1,187 @@
|
||||
'use strict';
|
||||
/* global describe it before after*/
|
||||
/* eslint no-unused-expressions: 0 */
|
||||
|
||||
var expect = require('chai').expect;
|
||||
var sinon = require('sinon');
|
||||
var os = require('os');
|
||||
var cp = require('child_process');
|
||||
var q = require('q');
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var util = require('util');
|
||||
var events = require('events');
|
||||
|
||||
var loadFixturePath = require('./load-fixture-path');
|
||||
var ping = require('..');
|
||||
|
||||
// Some constants
|
||||
var ANSWER = require('./fixture/answer');
|
||||
var PLATFORMS = [
|
||||
'window',
|
||||
'darwin',
|
||||
'freebsd',
|
||||
// 'aix',
|
||||
'linux',
|
||||
];
|
||||
var PLATFORM_TO_EXTRA_ARGUMENTS = {
|
||||
window: ['-n', '2'],
|
||||
darwin: ['-c', '2'],
|
||||
freebsd: ['-c', '2'],
|
||||
linux: ['-c', '2'],
|
||||
};
|
||||
|
||||
var pathToAnswerKey = function (p) {
|
||||
var basename = path.posix.basename(p, '.txt');
|
||||
var dirname = path.posix.basename(path.posix.dirname(p));
|
||||
var osname = path.posix.basename(
|
||||
path.posix.dirname(path.posix.dirname(p))
|
||||
);
|
||||
|
||||
return [osname, dirname, basename].join('_');
|
||||
};
|
||||
|
||||
var mockOutSpawn = function (fp) {
|
||||
return function () {
|
||||
var e = new events.EventEmitter();
|
||||
e.stdout = e;
|
||||
|
||||
var s = fs.createReadStream(fp);
|
||||
s.on('data', function (line) {
|
||||
e.emit('data', line);
|
||||
});
|
||||
s.on('close', function () {
|
||||
e.emit('close', 0);
|
||||
});
|
||||
|
||||
return e;
|
||||
};
|
||||
};
|
||||
|
||||
var createTestCase = function (platform, pingExecution) {
|
||||
var stubs = [];
|
||||
|
||||
describe(util.format('On %s platform', platform), function () {
|
||||
var fixturePaths = loadFixturePath(platform);
|
||||
|
||||
before(function () {
|
||||
stubs.push(
|
||||
sinon.stub(os, 'platform', function () { return platform; })
|
||||
);
|
||||
});
|
||||
|
||||
after(function () {
|
||||
stubs.forEach(function (stub) {
|
||||
stub.restore();
|
||||
});
|
||||
});
|
||||
|
||||
describe('runs with default config', function () {
|
||||
fixturePaths.forEach(function (fp) {
|
||||
it(
|
||||
util.format('Using |%s|', pathToAnswerKey(fp)),
|
||||
function () {
|
||||
return pingExecution(fp);
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('runs with custom config', function () {
|
||||
fixturePaths.forEach(function (fp) {
|
||||
it(
|
||||
util.format('Using |%s|', pathToAnswerKey(fp)),
|
||||
function () {
|
||||
return pingExecution(fp, {
|
||||
timeout: 10,
|
||||
extra: PLATFORM_TO_EXTRA_ARGUMENTS[platform],
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('runs with custom config with default gone', function () {
|
||||
fixturePaths.forEach(function (fp) {
|
||||
it(
|
||||
util.format('Using |%s|', pathToAnswerKey(fp)),
|
||||
function () {
|
||||
return pingExecution(fp, {
|
||||
timeout: false,
|
||||
extra: PLATFORM_TO_EXTRA_ARGUMENTS[platform],
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
describe('Ping in callback mode', function () {
|
||||
var pingExecution = function (fp, args) {
|
||||
var deferred = q.defer();
|
||||
|
||||
var stub = sinon.stub(
|
||||
cp,
|
||||
'spawn',
|
||||
mockOutSpawn(fp)
|
||||
);
|
||||
|
||||
var cb = function (isAlive, err) {
|
||||
if (err) {
|
||||
deferred.reject(err);
|
||||
} else {
|
||||
deferred.resolve(isAlive);
|
||||
}
|
||||
};
|
||||
|
||||
if (args) {
|
||||
ping.sys.probe('whatever', cb, args);
|
||||
} else {
|
||||
ping.sys.probe('whatever', cb);
|
||||
}
|
||||
|
||||
stub.restore();
|
||||
|
||||
return deferred.promise.then(function (data) {
|
||||
var answerKey = pathToAnswerKey(fp);
|
||||
var actualIsAlive = data;
|
||||
var expectIsAlive = ANSWER[answerKey].alive;
|
||||
expect(actualIsAlive).to.equal(expectIsAlive);
|
||||
});
|
||||
};
|
||||
|
||||
PLATFORMS.forEach(function (platform) {
|
||||
createTestCase(platform, pingExecution);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Ping in promise mode', function () {
|
||||
var pingExecution = function (fp, args) {
|
||||
var stub = sinon.stub(
|
||||
cp,
|
||||
'spawn',
|
||||
mockOutSpawn(fp)
|
||||
);
|
||||
|
||||
var ret = null;
|
||||
if (args) {
|
||||
ret = ping.promise.probe('whatever', args);
|
||||
} else {
|
||||
ret = ping.promise.probe('whatever');
|
||||
}
|
||||
|
||||
stub.restore();
|
||||
|
||||
return ret.then(function (data) {
|
||||
var answerKey = pathToAnswerKey(fp);
|
||||
var actualData = data;
|
||||
var expectData = ANSWER[answerKey];
|
||||
expect(actualData).to.deep.equal(expectData);
|
||||
});
|
||||
};
|
||||
|
||||
PLATFORMS.forEach(function (platform) {
|
||||
createTestCase(platform, pingExecution);
|
||||
});
|
||||
});
|
||||
800
node_modules/q/CHANGES.md
generated
vendored
Normal file
800
node_modules/q/CHANGES.md
generated
vendored
Normal file
@@ -0,0 +1,800 @@
|
||||
|
||||
## 1.5.1
|
||||
|
||||
- Q.any now annotates its error message to clarify that Q.any was involved and
|
||||
includes only the last error emitted. (Ivan Etchart)
|
||||
- Avoid domain.dispose during tests in preparation for Node.js 9. (Anna
|
||||
Henningsen)
|
||||
|
||||
## 1.5.0
|
||||
|
||||
- Q.any gives an error message from the last rejected promise
|
||||
- Throw if callback supplied to "finally" is invalid (@grahamrhay)
|
||||
- Long stack trace improvements, can now construct long stack traces
|
||||
across rethrows.
|
||||
|
||||
## 1.4.1
|
||||
|
||||
- Address an issue that prevented Q from being used as a `<script>` for
|
||||
Firefox add-ons. Q can now be used in any environment that provides `window`
|
||||
or `self` globals, favoring `window` since add-ons have an an immutable
|
||||
`self` that is distinct from `window`.
|
||||
|
||||
## 1.4.0
|
||||
|
||||
- Add `noConflict` support for use in `<script>` (@jahnjw).
|
||||
|
||||
## 1.3.0
|
||||
|
||||
- Add tracking for unhandled and handled rejections in Node.js (@benjamingr).
|
||||
|
||||
## 1.2.1
|
||||
|
||||
- Fix Node.js environment detection for modern Browserify (@kahnjw).
|
||||
|
||||
## 1.2.0
|
||||
|
||||
- Added Q.any(promisesArray) method (@vergara).
|
||||
Returns a promise fulfilled with the value of the first resolved promise in
|
||||
promisesArray. If all promises in promisesArray are rejected, it returns
|
||||
a rejected promise.
|
||||
|
||||
## 1.1.2
|
||||
|
||||
- Removed extraneous files from the npm package by using the "files"
|
||||
whitelist in package.json instead of the .npmignore blacklist.
|
||||
(@anton-rudeshko)
|
||||
|
||||
## 1.1.1
|
||||
|
||||
- Fix a pair of regressions in bootstrapping, one which precluded
|
||||
WebWorker support, and another that precluded support in
|
||||
``<script>`` usage outright. #607
|
||||
|
||||
## 1.1.0
|
||||
|
||||
- Adds support for enabling long stack traces in node.js by setting
|
||||
environment variable `Q_DEBUG=1`.
|
||||
- Introduces the `tap` method to promises, which will see a value
|
||||
pass through without alteration.
|
||||
- Use instanceof to recognize own promise instances as opposed to
|
||||
thenables.
|
||||
- Construct timeout errors with `code === ETIMEDOUT` (Kornel Lesiński)
|
||||
- More descriminant CommonJS module environment detection.
|
||||
- Dropped continuous integration for Node.js 0.6 and 0.8 because of
|
||||
changes to npm that preclude the use of new `^` version predicate
|
||||
operator in any transitive dependency.
|
||||
- Users can now override `Q.nextTick`.
|
||||
|
||||
## 1.0.1
|
||||
|
||||
- Adds support for `Q.Promise`, which implements common usage of the
|
||||
ES6 `Promise` constructor and its methods. `Promise` does not have
|
||||
a valid promise constructor and a proper implementation awaits
|
||||
version 2 of Q.
|
||||
- Removes the console stopgap for a promise inspector. This no longer
|
||||
works with any degree of reliability.
|
||||
- Fixes support for content security policies that forbid eval. Now
|
||||
using the `StopIteration` global to distinguish SpiderMonkey
|
||||
generators from ES6 generators, assuming that they will never
|
||||
coexist.
|
||||
|
||||
## 1.0.0
|
||||
|
||||
:cake: This is all but a re-release of version 0.9, which has settled
|
||||
into a gentle maintenance mode and rightly deserves an official 1.0.
|
||||
An ambitious 2.0 release is already around the corner, but 0.9/1.0
|
||||
have been distributed far and wide and demand long term support.
|
||||
|
||||
- Q will now attempt to post a debug message in browsers regardless
|
||||
of whether window.Touch is defined. Chrome at least now has this
|
||||
property regardless of whether touch is supported by the underlying
|
||||
hardware.
|
||||
- Remove deprecation warning from `promise.valueOf`. The function is
|
||||
called by the browser in various ways so there is no way to
|
||||
distinguish usage that should be migrated from usage that cannot be
|
||||
altered.
|
||||
|
||||
## 0.9.7
|
||||
|
||||
- :warning: `q.min.js` is no longer checked-in. It is however still
|
||||
created by Grunt and NPM.
|
||||
- Fixes a bug that inhibited `Q.async` with implementations of the new
|
||||
ES6 generators.
|
||||
- Fixes a bug with `nextTick` affecting Safari 6.0.5 the first time a
|
||||
page loads when an `iframe` is involved.
|
||||
- Introduces `passByCopy`, `join`, and `race`.
|
||||
- Shows stack traces or error messages on the console, instead of
|
||||
`Error` objects.
|
||||
- Elimintates wrapper methods for improved performance.
|
||||
- `Q.all` now propagates progress notifications of the form you might
|
||||
expect of ES6 iterations, `{value, index}` where the `value` is the
|
||||
progress notification from the promise at `index`.
|
||||
|
||||
## 0.9.6
|
||||
|
||||
- Fixes a bug in recognizing the difference between compatible Q
|
||||
promises, and Q promises from before the implementation of "inspect".
|
||||
The latter are now coerced.
|
||||
- Fixes an infinite asynchronous coercion cycle introduced by former
|
||||
solution, in two independently sufficient ways. 1.) All promises
|
||||
returned by makePromise now implement "inspect", albeit a default
|
||||
that reports that the promise has an "unknown" state. 2.) The
|
||||
implementation of "then/when" is now in "then" instead of "when", so
|
||||
that the responsibility to "coerce" the given promise rests solely in
|
||||
the "when" method and the "then" method may assume that "this" is a
|
||||
promise of the right type.
|
||||
- Refactors `nextTick` to use an unrolled microtask within Q regardless
|
||||
of how new ticks a requested. #316 @rkatic
|
||||
|
||||
## 0.9.5
|
||||
|
||||
- Introduces `inspect` for getting the state of a promise as
|
||||
`{state: "fulfilled" | "rejected" | "pending", value | reason}`.
|
||||
- Introduces `allSettled` which produces an array of promises states
|
||||
for the input promises once they have all "settled". This is in
|
||||
accordance with a discussion on Promises/A+ that "settled" refers to
|
||||
a promise that is "fulfilled" or "rejected". "resolved" refers to a
|
||||
deferred promise that has been "resolved" to another promise,
|
||||
"sealing its fate" to the fate of the successor promise.
|
||||
- Long stack traces are now off by default. Set `Q.longStackSupport`
|
||||
to true to enable long stack traces.
|
||||
- Long stack traces can now follow the entire asynchronous history of a
|
||||
promise, not just a single jump.
|
||||
- Introduces `spawn` for an immediately invoked asychronous generator.
|
||||
@jlongster
|
||||
- Support for *experimental* synonyms `mapply`, `mcall`, `nmapply`,
|
||||
`nmcall` for method invocation.
|
||||
|
||||
## 0.9.4
|
||||
|
||||
- `isPromise` and `isPromiseAlike` now always returns a boolean
|
||||
(even for falsy values). #284 @lfac-pt
|
||||
- Support for ES6 Generators in `async` #288 @andywingo
|
||||
- Clear duplicate promise rejections from dispatch methods #238 @SLaks
|
||||
- Unhandled rejection API #296 @domenic
|
||||
`stopUnhandledRejectionTracking`, `getUnhandledReasons`,
|
||||
`resetUnhandledRejections`.
|
||||
|
||||
## 0.9.3
|
||||
|
||||
- Add the ability to give `Q.timeout`'s errors a custom error message. #270
|
||||
@jgrenon
|
||||
- Fix Q's call-stack busting behavior in Node.js 0.10, by switching from
|
||||
`process.nextTick` to `setImmediate`. #254 #259
|
||||
- Fix Q's behavior when used with the Mocha test runner in the browser, since
|
||||
Mocha introduces a fake `process` global without a `nextTick` property. #267
|
||||
- Fix some, but not all, cases wherein Q would give false positives in its
|
||||
unhandled rejection detection (#252). A fix for other cases (#238) is
|
||||
hopefully coming soon.
|
||||
- Made `Q.promise` throw early if given a non-function.
|
||||
|
||||
## 0.9.2
|
||||
|
||||
- Pass through progress notifications when using `timeout`. #229 @omares
|
||||
- Pass through progress notifications when using `delay`.
|
||||
- Fix `nbind` to actually bind the `thisArg`. #232 @davidpadbury
|
||||
|
||||
## 0.9.1
|
||||
|
||||
- Made the AMD detection compatible with the RequireJS optimizer's `namespace`
|
||||
option. #225 @terinjokes
|
||||
- Fix side effects from `valueOf`, and thus from `isFulfilled`, `isRejected`,
|
||||
and `isPending`. #226 @benjamn
|
||||
|
||||
## 0.9.0
|
||||
|
||||
This release removes many layers of deprecated methods and brings Q closer to
|
||||
alignment with Mark Miller’s TC39 [strawman][] for concurrency. At the same
|
||||
time, it fixes many bugs and adds a few features around error handling. Finally,
|
||||
it comes with an updated and comprehensive [API Reference][].
|
||||
|
||||
[strawman]: http://wiki.ecmascript.org/doku.php?id=strawman:concurrency
|
||||
[API Reference]: https://github.com/kriskowal/q/wiki/API-Reference
|
||||
|
||||
### API Cleanup
|
||||
|
||||
The following deprecated or undocumented methods have been removed.
|
||||
Their replacements are listed here:
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>0.8.x method</th>
|
||||
<th>0.9 replacement</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><code>Q.ref</code></td>
|
||||
<td><code>Q</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>call</code>, <code>apply</code>, <code>bind</code> (*)</td>
|
||||
<td><code>fcall</code>/<code>invoke</code>, <code>fapply</code>/<code>post</code>, <code>fbind</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>ncall</code>, <code>napply</code> (*)</td>
|
||||
<td><code>nfcall</code>/<code>ninvoke</code>, <code>nfapply</code>/<code>npost</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>end</code></td>
|
||||
<td><code>done</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>put</code></td>
|
||||
<td><code>set</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>node</code></td>
|
||||
<td><code>nbind</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>nend</code></td>
|
||||
<td><code>nodeify</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>isResolved</code></td>
|
||||
<td><code>isPending</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>deferred.node</code></td>
|
||||
<td><code>deferred.makeNodeResolver</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>Method</code>, <code>sender</code></td>
|
||||
<td><code>dispatcher</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>send</code></td>
|
||||
<td><code>dispatch</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>view</code>, <code>viewInfo</code></td>
|
||||
<td>(none)</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
(*) Use of ``thisp`` is discouraged. For calling methods, use ``post`` or
|
||||
``invoke``.
|
||||
|
||||
### Alignment with the Concurrency Strawman
|
||||
|
||||
- Q now exports a `Q(value)` function, an alias for `resolve`.
|
||||
`Q.call`, `Q.apply`, and `Q.bind` were removed to make room for the
|
||||
same methods on the function prototype.
|
||||
- `invoke` has been aliased to `send` in all its forms.
|
||||
- `post` with no method name acts like `fapply`.
|
||||
|
||||
### Error Handling
|
||||
|
||||
- Long stack traces can be turned off by setting `Q.stackJumpLimit` to zero.
|
||||
In the future, this property will be used to fine tune how many stack jumps
|
||||
are retained in long stack traces; for now, anything nonzero is treated as
|
||||
one (since Q only tracks one stack jump at the moment, see #144). #168
|
||||
- In Node.js, if there are unhandled rejections when the process exits, they
|
||||
are output to the console. #115
|
||||
|
||||
### Other
|
||||
|
||||
- `delete` and `set` (née `put`) no longer have a fulfillment value.
|
||||
- Q promises are no longer frozen, which
|
||||
[helps with performance](http://code.google.com/p/v8/issues/detail?id=1858).
|
||||
- `thenReject` is now included, as a counterpart to `thenResolve`.
|
||||
- The included browser `nextTick` shim is now faster. #195 @rkatic.
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- Q now works in Internet Explorer 10. #186 @ForbesLindesay
|
||||
- `fbind` no longer hard-binds the returned function's `this` to `undefined`.
|
||||
#202
|
||||
- `Q.reject` no longer leaks memory. #148
|
||||
- `npost` with no arguments now works. #207
|
||||
- `allResolved` now works with non-Q promises ("thenables"). #179
|
||||
- `keys` behavior is now correct even in browsers without native
|
||||
`Object.keys`. #192 @rkatic
|
||||
- `isRejected` and the `exception` property now work correctly if the
|
||||
rejection reason is falsy. #198
|
||||
|
||||
### Internals and Advanced
|
||||
|
||||
- The internal interface for a promise now uses
|
||||
`dispatchPromise(resolve, op, operands)` instead of `sendPromise(op,
|
||||
resolve, ...operands)`, which reduces the cases where Q needs to do
|
||||
argument slicing.
|
||||
- The internal protocol uses different operands. "put" is now "set".
|
||||
"del" is now "delete". "view" and "viewInfo" have been removed.
|
||||
- `Q.fulfill` has been added. It is distinct from `Q.resolve` in that
|
||||
it does not pass promises through, nor coerces promises from other
|
||||
systems. The promise becomes the fulfillment value. This is only
|
||||
recommended for use when trying to fulfill a promise with an object that has
|
||||
a `then` function that is at the same time not a promise.
|
||||
|
||||
## 0.8.12
|
||||
- Treat foreign promises as unresolved in `Q.isFulfilled`; this lets `Q.all`
|
||||
work on arrays containing foreign promises. #154
|
||||
- Fix minor incompliances with the [Promises/A+ spec][] and [test suite][]. #157
|
||||
#158
|
||||
|
||||
[Promises/A+ spec]: http://promises-aplus.github.com/promises-spec/
|
||||
[test suite]: https://github.com/promises-aplus/promises-tests
|
||||
|
||||
## 0.8.11
|
||||
|
||||
- Added ``nfcall``, ``nfapply``, and ``nfbind`` as ``thisp``-less versions of
|
||||
``ncall``, ``napply``, and ``nbind``. The latter are now deprecated. #142
|
||||
- Long stack traces no longer cause linearly-growing memory usage when chaining
|
||||
promises together. #111
|
||||
- Inspecting ``error.stack`` in a rejection handler will now give a long stack
|
||||
trace. #103
|
||||
- Fixed ``Q.timeout`` to clear its timeout handle when the promise is rejected;
|
||||
previously, it kept the event loop alive until the timeout period expired.
|
||||
#145 @dfilatov
|
||||
- Added `q/queue` module, which exports an infinite promise queue
|
||||
constructor.
|
||||
|
||||
## 0.8.10
|
||||
|
||||
- Added ``done`` as a replacement for ``end``, taking the usual fulfillment,
|
||||
rejection, and progress handlers. It's essentially equivalent to
|
||||
``then(f, r, p).end()``.
|
||||
- Added ``Q.onerror``, a settable error trap that you can use to get full stack
|
||||
traces for uncaught errors. #94
|
||||
- Added ``thenResolve`` as a shortcut for returning a constant value once a
|
||||
promise is fulfilled. #108 @ForbesLindesay
|
||||
- Various tweaks to progress notification, including propagation and
|
||||
transformation of progress values and only forwarding a single progress
|
||||
object.
|
||||
- Renamed ``nend`` to ``nodeify``. It no longer returns an always-fulfilled
|
||||
promise when a Node callback is passed.
|
||||
- ``deferred.resolve`` and ``deferred.reject`` no longer (sometimes) return
|
||||
``deferred.promise``.
|
||||
- Fixed stack traces getting mangled if they hit ``end`` twice. #116 #121 @ef4
|
||||
- Fixed ``ninvoke`` and ``npost`` to work on promises for objects with Node
|
||||
methods. #134
|
||||
- Fixed accidental coercion of objects with nontrivial ``valueOf`` methods,
|
||||
like ``Date``s, by the promise's ``valueOf`` method. #135
|
||||
- Fixed ``spread`` not calling the passed rejection handler if given a rejected
|
||||
promise.
|
||||
|
||||
## 0.8.9
|
||||
|
||||
- Added ``nend``
|
||||
- Added preliminary progress notification support, via
|
||||
``promise.then(onFulfilled, onRejected, onProgress)``,
|
||||
``promise.progress(onProgress)``, and ``deferred.notify(...progressData)``.
|
||||
- Made ``put`` and ``del`` return the object acted upon for easier chaining.
|
||||
#84
|
||||
- Fixed coercion cycles with cooperating promises. #106
|
||||
|
||||
## 0.8.7
|
||||
|
||||
- Support [Montage Require](http://github.com/kriskowal/mr)
|
||||
|
||||
## 0.8.6
|
||||
|
||||
- Fixed ``npost`` and ``ninvoke`` to pass the correct ``thisp``. #74
|
||||
- Fixed various cases involving unorthodox rejection reasons. #73 #90
|
||||
@ef4
|
||||
- Fixed double-resolving of misbehaved custom promises. #75
|
||||
- Sped up ``Q.all`` for arrays contain already-resolved promises or scalar
|
||||
values. @ForbesLindesay
|
||||
- Made stack trace filtering work when concatenating assets. #93 @ef4
|
||||
- Added warnings for deprecated methods. @ForbesLindesay
|
||||
- Added ``.npmignore`` file so that dependent packages get a slimmer
|
||||
``node_modules`` directory.
|
||||
|
||||
## 0.8.5
|
||||
|
||||
- Added preliminary support for long traces (@domenic)
|
||||
- Added ``fapply``, ``fcall``, ``fbind`` for non-thisp
|
||||
promised function calls.
|
||||
- Added ``return`` for async generators, where generators
|
||||
are implemented.
|
||||
- Rejected promises now have an "exception" property. If an object
|
||||
isRejected(object), then object.valueOf().exception will
|
||||
be the wrapped error.
|
||||
- Added Jasmine specifications
|
||||
- Support Internet Explorers 7–9 (with multiple bug fixes @domenic)
|
||||
- Support Firefox 12
|
||||
- Support Safari 5.1.5
|
||||
- Support Chrome 18
|
||||
|
||||
## 0.8.4
|
||||
|
||||
- WARNING: ``promise.timeout`` is now rejected with an ``Error`` object
|
||||
and the message now includes the duration of the timeout in
|
||||
miliseconds. This doesn't constitute (in my opinion) a
|
||||
backward-incompatibility since it is a change of an undocumented and
|
||||
unspecified public behavior, but if you happened to depend on the
|
||||
exception being a string, you will need to revise your code.
|
||||
- Added ``deferred.makeNodeResolver()`` to replace the more cryptic
|
||||
``deferred.node()`` method.
|
||||
- Added experimental ``Q.promise(maker(resolve, reject))`` to make a
|
||||
promise inside a callback, such that thrown exceptions in the
|
||||
callback are converted and the resolver and rejecter are arguments.
|
||||
This is a shorthand for making a deferred directly and inspired by
|
||||
@gozala’s stream constructor pattern and the Microsoft Windows Metro
|
||||
Promise constructor interface.
|
||||
- Added experimental ``Q.begin()`` that is intended to kick off chains
|
||||
of ``.then`` so that each of these can be reordered without having to
|
||||
edit the new and former first step.
|
||||
|
||||
## 0.8.3
|
||||
|
||||
- Added ``isFulfilled``, ``isRejected``, and ``isResolved``
|
||||
to the promise prototype.
|
||||
- Added ``allResolved`` for waiting for every promise to either be
|
||||
fulfilled or rejected, without propagating an error. @utvara #53
|
||||
- Added ``Q.bind`` as a method to transform functions that
|
||||
return and throw into promise-returning functions. See
|
||||
[an example](https://gist.github.com/1782808). @domenic
|
||||
- Renamed ``node`` export to ``nbind``, and added ``napply`` to
|
||||
complete the set. ``node`` remains as deprecated. @domenic #58
|
||||
- Renamed ``Method`` export to ``sender``. ``Method``
|
||||
remains as deprecated and will be removed in the next
|
||||
major version since I expect it has very little usage.
|
||||
- Added browser console message indicating a live list of
|
||||
unhandled errors.
|
||||
- Added support for ``msSetImmediate`` (IE10) or ``setImmediate``
|
||||
(available via [polyfill](https://github.com/NobleJS/setImmediate))
|
||||
as a browser-side ``nextTick`` implementation. #44 #50 #59
|
||||
- Stopped using the event-queue dependency, which was in place for
|
||||
Narwhal support: now directly using ``process.nextTick``.
|
||||
- WARNING: EXPERIMENTAL: added ``finally`` alias for ``fin``, ``catch``
|
||||
alias for ``fail``, ``try`` alias for ``call``, and ``delete`` alias
|
||||
for ``del``. These properties are enquoted in the library for
|
||||
cross-browser compatibility, but may be used as property names in
|
||||
modern engines.
|
||||
|
||||
## 0.8.2
|
||||
|
||||
- Deprecated ``ref`` in favor of ``resolve`` as recommended by
|
||||
@domenic.
|
||||
- Update event-queue dependency.
|
||||
|
||||
## 0.8.1
|
||||
|
||||
- Fixed Opera bug. #35 @cadorn
|
||||
- Fixed ``Q.all([])`` #32 @domenic
|
||||
|
||||
## 0.8.0
|
||||
|
||||
- WARNING: ``enqueue`` removed. Use ``nextTick`` instead.
|
||||
This is more consistent with NodeJS and (subjectively)
|
||||
more explicit and intuitive.
|
||||
- WARNING: ``def`` removed. Use ``master`` instead. The
|
||||
term ``def`` was too confusing to new users.
|
||||
- WARNING: ``spy`` removed in favor of ``fin``.
|
||||
- WARNING: ``wait`` removed. Do ``all(args).get(0)`` instead.
|
||||
- WARNING: ``join`` removed. Do ``all(args).spread(callback)`` instead.
|
||||
- WARNING: Removed the ``Q`` function module.exports alias
|
||||
for ``Q.ref``. It conflicts with ``Q.apply`` in weird
|
||||
ways, making it uncallable.
|
||||
- Revised ``delay`` so that it accepts both ``(value,
|
||||
timeout)`` and ``(timeout)`` variations based on
|
||||
arguments length.
|
||||
- Added ``ref().spread(cb(...args))``, a variant of
|
||||
``then`` that spreads an array across multiple arguments.
|
||||
Useful with ``all()``.
|
||||
- Added ``defer().node()`` Node callback generator. The
|
||||
callback accepts ``(error, value)`` or ``(error,
|
||||
...values)``. For multiple value arguments, the
|
||||
fulfillment value is an array, useful in conjunction with
|
||||
``spread``.
|
||||
- Added ``node`` and ``ncall``, both with the signature
|
||||
``(fun, thisp_opt, ...args)``. The former is a decorator
|
||||
and the latter calls immediately. ``node`` optional
|
||||
binds and partially applies. ``ncall`` can bind and pass
|
||||
arguments.
|
||||
|
||||
## 0.7.2
|
||||
|
||||
- Fixed thenable promise assimilation.
|
||||
|
||||
## 0.7.1
|
||||
|
||||
- Stopped shimming ``Array.prototype.reduce``. The
|
||||
enumerable property has bad side-effects. Libraries that
|
||||
depend on this (for example, QQ) will need to be revised.
|
||||
|
||||
## 0.7.0 - BACKWARD INCOMPATIBILITY
|
||||
|
||||
- WARNING: Removed ``report`` and ``asap``
|
||||
- WARNING: The ``callback`` argument of the ``fin``
|
||||
function no longer receives any arguments. Thus, it can
|
||||
be used to call functions that should not receive
|
||||
arguments on resolution. Use ``when``, ``then``, or
|
||||
``fail`` if you need a value.
|
||||
- IMPORTANT: Fixed a bug in the use of ``MessageChannel``
|
||||
for ``nextTick``.
|
||||
- Renamed ``enqueue`` to ``nextTick``.
|
||||
- Added experimental ``view`` and ``viewInfo`` for creating
|
||||
views of promises either when or before they're
|
||||
fulfilled.
|
||||
- Shims are now externally applied so subsequent scripts or
|
||||
dependees can use them.
|
||||
- Improved minification results.
|
||||
- Improved readability.
|
||||
|
||||
## 0.6.0 - BACKWARD INCOMPATIBILITY
|
||||
|
||||
- WARNING: In practice, the implementation of ``spy`` and
|
||||
the name ``fin`` were useful. I've removed the old
|
||||
``fin`` implementation and renamed/aliased ``spy``.
|
||||
- The "q" module now exports its ``ref`` function as a "Q"
|
||||
constructor, with module systems that support exports
|
||||
assignment including NodeJS, RequireJS, and when used as
|
||||
a ``<script>`` tag. Notably, strictly compliant CommonJS
|
||||
does not support this, but UncommonJS does.
|
||||
- Added ``async`` decorator for generators that use yield
|
||||
to "trampoline" promises. In engines that support
|
||||
generators (SpiderMonkey), this will greatly reduce the
|
||||
need for nested callbacks.
|
||||
- Made ``when`` chainable.
|
||||
- Made ``all`` chainable.
|
||||
|
||||
## 0.5.3
|
||||
|
||||
- Added ``all`` and refactored ``join`` and ``wait`` to use
|
||||
it. All of these will now reject at the earliest
|
||||
rejection.
|
||||
|
||||
## 0.5.2
|
||||
|
||||
- Minor improvement to ``spy``; now waits for resolution of
|
||||
callback promise.
|
||||
|
||||
## 0.5.1
|
||||
|
||||
- Made most Q API methods chainable on promise objects, and
|
||||
turned the previous promise-methods of ``join``,
|
||||
``wait``, and ``report`` into Q API methods.
|
||||
- Added ``apply`` and ``call`` to the Q API, and ``apply``
|
||||
as a promise handler.
|
||||
- Added ``fail``, ``fin``, and ``spy`` to Q and the promise
|
||||
prototype for convenience when observing rejection,
|
||||
fulfillment and rejection, or just observing without
|
||||
affecting the resolution.
|
||||
- Renamed ``def`` (although ``def`` remains shimmed until
|
||||
the next major release) to ``master``.
|
||||
- Switched to using ``MessageChannel`` for next tick task
|
||||
enqueue in browsers that support it.
|
||||
|
||||
## 0.5.0 - MINOR BACKWARD INCOMPATIBILITY
|
||||
|
||||
- Exceptions are no longer reported when consumed.
|
||||
- Removed ``error`` from the API. Since exceptions are
|
||||
getting consumed, throwing them in an errback causes the
|
||||
exception to silently disappear. Use ``end``.
|
||||
- Added ``end`` as both an API method and a promise-chain
|
||||
ending method. It causes propagated rejections to be
|
||||
thrown, which allows Node to write stack traces and
|
||||
emit ``uncaughtException`` events, and browsers to
|
||||
likewise emit ``onerror`` and log to the console.
|
||||
- Added ``join`` and ``wait`` as promise chain functions,
|
||||
so you can wait for variadic promises, returning your own
|
||||
promise back, or join variadic promises, resolving with a
|
||||
callback that receives variadic fulfillment values.
|
||||
|
||||
## 0.4.4
|
||||
|
||||
- ``end`` no longer returns a promise. It is the end of the
|
||||
promise chain.
|
||||
- Stopped reporting thrown exceptions in ``when`` callbacks
|
||||
and errbacks. These must be explicitly reported through
|
||||
``.end()``, ``.then(null, Q.error)``, or some other
|
||||
mechanism.
|
||||
- Added ``report`` as an API method, which can be used as
|
||||
an errback to report and propagate an error.
|
||||
- Added ``report`` as a promise-chain method, so an error
|
||||
can be reported if it passes such a gate.
|
||||
|
||||
## 0.4.3
|
||||
|
||||
- Fixed ``<script>`` support that regressed with 0.4.2
|
||||
because of "use strict" in the module system
|
||||
multi-plexer.
|
||||
|
||||
## 0.4.2
|
||||
|
||||
- Added support for RequireJS (jburke)
|
||||
|
||||
## 0.4.1
|
||||
|
||||
- Added an "end" method to the promise prototype,
|
||||
as a shorthand for waiting for the promise to
|
||||
be resolved gracefully, and failing to do so,
|
||||
to dump an error message.
|
||||
|
||||
## 0.4.0 - BACKWARD INCOMPATIBLE*
|
||||
|
||||
- *Removed the utility modules. NPM and Node no longer
|
||||
expose any module except the main module. These have
|
||||
been moved and merged into the "qq" package.
|
||||
- *In a non-CommonJS browser, q.js can be used as a script.
|
||||
It now creates a Q global variable.
|
||||
- Fixed thenable assimilation.
|
||||
- Fixed some issues with asap, when it resolves to
|
||||
undefined, or throws an exception.
|
||||
|
||||
## 0.3.0 - BACKWARD-INCOMPATIBLE
|
||||
|
||||
- The `post` method has been reverted to its original
|
||||
signature, as provided in Tyler Close's `ref_send` API.
|
||||
That is, `post` accepts two arguments, the second of
|
||||
which is an arbitrary object, but usually invocation
|
||||
arguments as an `Array`. To provide variadic arguments
|
||||
to `post`, there is a new `invoke` function that posts
|
||||
the variadic arguments to the value given in the first
|
||||
argument.
|
||||
- The `defined` method has been moved from `q` to `q/util`
|
||||
since it gets no use in practice but is still
|
||||
theoretically useful.
|
||||
- The `Promise` constructor has been renamed to
|
||||
`makePromise` to be consistent with the convention that
|
||||
functions that do not require the `new` keyword to be
|
||||
used as constructors have camelCase names.
|
||||
- The `isResolved` function has been renamed to
|
||||
`isFulfilled`. There is a new `isResolved` function that
|
||||
indicates whether a value is not a promise or, if it is a
|
||||
promise, whether it has been either fulfilled or
|
||||
rejected. The code has been revised to reflect this
|
||||
nuance in terminology.
|
||||
|
||||
## 0.2.10
|
||||
|
||||
- Added `join` to `"q/util"` for variadically joining
|
||||
multiple promises.
|
||||
|
||||
## 0.2.9
|
||||
|
||||
- The future-compatible `invoke` method has been added,
|
||||
to replace `post`, since `post` will become backward-
|
||||
incompatible in the next major release.
|
||||
- Exceptions thrown in the callbacks of a `when` call are
|
||||
now emitted to Node's `"uncaughtException"` `process`
|
||||
event in addition to being returned as a rejection reason.
|
||||
|
||||
## 0.2.8
|
||||
|
||||
- Exceptions thrown in the callbacks of a `when` call
|
||||
are now consumed, warned, and transformed into
|
||||
rejections of the promise returned by `when`.
|
||||
|
||||
## 0.2.7
|
||||
|
||||
- Fixed a minor bug in thenable assimilation, regressed
|
||||
because of the change in the forwarding protocol.
|
||||
- Fixed behavior of "q/util" `deep` method on dates and
|
||||
other primitives. Github issue #11.
|
||||
|
||||
## 0.2.6
|
||||
|
||||
- Thenables (objects with a "then" method) are accepted
|
||||
and provided, bringing this implementation of Q
|
||||
into conformance with Promises/A, B, and D.
|
||||
- Added `makePromise`, to replace the `Promise` function
|
||||
eventually.
|
||||
- Rejections are now also duck-typed. A rejection is a
|
||||
promise with a valueOf method that returns a rejection
|
||||
descriptor. A rejection descriptor has a
|
||||
"promiseRejected" property equal to "true" and a
|
||||
"reason" property corresponding to the rejection reason.
|
||||
- Altered the `makePromise` API such that the `fallback`
|
||||
method no longer receives a superfluous `resolved` method
|
||||
after the `operator`. The fallback method is responsible
|
||||
only for returning a resolution. This breaks an
|
||||
undocumented API, so third-party API's depending on the
|
||||
previous undocumented behavior may break.
|
||||
|
||||
## 0.2.5
|
||||
|
||||
- Changed promises into a duck-type such that multiple
|
||||
instances of the Q module can exchange promise objects.
|
||||
A promise is now defined as "an object that implements the
|
||||
`promiseSend(op, resolved, ...)` method and `valueOf`".
|
||||
- Exceptions in promises are now captured and returned
|
||||
as rejections.
|
||||
|
||||
## 0.2.4
|
||||
|
||||
- Fixed bug in `ref` that prevented `del` messages from
|
||||
being received (gozala)
|
||||
- Fixed a conflict with FireFox 4; constructor property
|
||||
is now read-only.
|
||||
|
||||
## 0.2.3
|
||||
|
||||
- Added `keys` message to promises and to the promise API.
|
||||
|
||||
## 0.2.2
|
||||
|
||||
- Added boilerplate to `q/queue` and `q/util`.
|
||||
- Fixed missing dependency to `q/queue`.
|
||||
|
||||
## 0.2.1
|
||||
|
||||
- The `resolve` and `reject` methods of `defer` objects now
|
||||
return the resolution promise for convenience.
|
||||
- Added `q/util`, which provides `step`, `delay`, `shallow`,
|
||||
`deep`, and three reduction orders.
|
||||
- Added `q/queue` module for a promise `Queue`.
|
||||
- Added `q-comm` to the list of compatible libraries.
|
||||
- Deprecated `defined` from `q`, with intent to move it to
|
||||
`q/util`.
|
||||
|
||||
## 0.2.0 - BACKWARD INCOMPATIBLE
|
||||
|
||||
- Changed post(ref, name, args) to variadic
|
||||
post(ref, name, ...args). BACKWARD INCOMPATIBLE
|
||||
- Added a def(value) method to annotate an object as being
|
||||
necessarily a local value that cannot be serialized, such
|
||||
that inter-process/worker/vat promise communication
|
||||
libraries will send messages to it, but never send it
|
||||
back.
|
||||
- Added a send(value, op, ...args) method to the public API, for
|
||||
forwarding messages to a value or promise in a future turn.
|
||||
|
||||
## 0.1.9
|
||||
|
||||
- Added isRejected() for testing whether a value is a rejected
|
||||
promise. isResolved() retains the behavior of stating
|
||||
that rejected promises are not resolved.
|
||||
|
||||
## 0.1.8
|
||||
|
||||
- Fixed isResolved(null) and isResolved(undefined) [issue #9]
|
||||
- Fixed a problem with the Object.create shim
|
||||
|
||||
## 0.1.7
|
||||
|
||||
- shimmed ES5 Object.create in addition to Object.freeze
|
||||
for compatibility on non-ES5 engines (gozala)
|
||||
|
||||
## 0.1.6
|
||||
|
||||
- Q.isResolved added
|
||||
- promise.valueOf() now returns the value of resolved
|
||||
and near values
|
||||
- asap retried
|
||||
- promises are frozen when possible
|
||||
|
||||
## 0.1.5
|
||||
|
||||
- fixed dependency list for Teleport (gozala)
|
||||
- all unit tests now pass (gozala)
|
||||
|
||||
## 0.1.4
|
||||
|
||||
- added support for Teleport as an engine (gozala)
|
||||
- simplified and updated methods for getting internal
|
||||
print and enqueue functions universally (gozala)
|
||||
|
||||
## 0.1.3
|
||||
|
||||
- fixed erroneous link to the q module in package.json
|
||||
|
||||
## 0.1.2
|
||||
|
||||
- restructured for overlay style package compatibility
|
||||
|
||||
## 0.1.0
|
||||
|
||||
- removed asap because it was broken, probably down to the
|
||||
philosophy.
|
||||
|
||||
## 0.0.3
|
||||
|
||||
- removed q-util
|
||||
- fixed asap so it returns a value if completed
|
||||
|
||||
## 0.0.2
|
||||
|
||||
- added q-util
|
||||
|
||||
## 0.0.1
|
||||
|
||||
- initial version
|
||||
18
node_modules/q/LICENSE
generated
vendored
Normal file
18
node_modules/q/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
Copyright 2009–2017 Kristopher Michael Kowal. All rights reserved.
|
||||
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.
|
||||
874
node_modules/q/README.md
generated
vendored
Normal file
874
node_modules/q/README.md
generated
vendored
Normal file
@@ -0,0 +1,874 @@
|
||||
[](http://travis-ci.org/kriskowal/q)
|
||||
[](https://cdnjs.com/libraries/q.js)
|
||||
|
||||
<a href="http://promises-aplus.github.com/promises-spec">
|
||||
<img src="http://kriskowal.github.io/q/q.png" align="right" alt="Q logo" />
|
||||
</a>
|
||||
|
||||
If a function cannot return a value or throw an exception without
|
||||
blocking, it can return a promise instead. A promise is an object
|
||||
that represents the return value or the thrown exception that the
|
||||
function may eventually provide. A promise can also be used as a
|
||||
proxy for a [remote object][Q-Connection] to overcome latency.
|
||||
|
||||
[Q-Connection]: https://github.com/kriskowal/q-connection
|
||||
|
||||
On the first pass, promises can mitigate the “[Pyramid of
|
||||
Doom][POD]”: the situation where code marches to the right faster
|
||||
than it marches forward.
|
||||
|
||||
[POD]: http://calculist.org/blog/2011/12/14/why-coroutines-wont-work-on-the-web/
|
||||
|
||||
```javascript
|
||||
step1(function (value1) {
|
||||
step2(value1, function(value2) {
|
||||
step3(value2, function(value3) {
|
||||
step4(value3, function(value4) {
|
||||
// Do something with value4
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
With a promise library, you can flatten the pyramid.
|
||||
|
||||
```javascript
|
||||
Q.fcall(promisedStep1)
|
||||
.then(promisedStep2)
|
||||
.then(promisedStep3)
|
||||
.then(promisedStep4)
|
||||
.then(function (value4) {
|
||||
// Do something with value4
|
||||
})
|
||||
.catch(function (error) {
|
||||
// Handle any error from all above steps
|
||||
})
|
||||
.done();
|
||||
```
|
||||
|
||||
With this approach, you also get implicit error propagation, just like `try`,
|
||||
`catch`, and `finally`. An error in `promisedStep1` will flow all the way to
|
||||
the `catch` function, where it’s caught and handled. (Here `promisedStepN` is
|
||||
a version of `stepN` that returns a promise.)
|
||||
|
||||
The callback approach is called an “inversion of control”.
|
||||
A function that accepts a callback instead of a return value
|
||||
is saying, “Don’t call me, I’ll call you.”. Promises
|
||||
[un-invert][IOC] the inversion, cleanly separating the input
|
||||
arguments from control flow arguments. This simplifies the
|
||||
use and creation of API’s, particularly variadic,
|
||||
rest and spread arguments.
|
||||
|
||||
[IOC]: http://www.slideshare.net/domenicdenicola/callbacks-promises-and-coroutines-oh-my-the-evolution-of-asynchronicity-in-javascript
|
||||
|
||||
|
||||
## Getting Started
|
||||
|
||||
The Q module can be loaded as:
|
||||
|
||||
- A ``<script>`` tag (creating a ``Q`` global variable): ~2.5 KB minified and
|
||||
gzipped.
|
||||
- A Node.js and CommonJS module, available in [npm](https://npmjs.org/) as
|
||||
the [q](https://npmjs.org/package/q) package
|
||||
- An AMD module
|
||||
- A [component](https://github.com/component/component) as ``microjs/q``
|
||||
- Using [bower](http://bower.io/) as `q#^1.4.1`
|
||||
- Using [NuGet](http://nuget.org/) as [Q](https://nuget.org/packages/q)
|
||||
|
||||
Q can exchange promises with jQuery, Dojo, When.js, WinJS, and more.
|
||||
|
||||
## Resources
|
||||
|
||||
Our [wiki][] contains a number of useful resources, including:
|
||||
|
||||
- A method-by-method [Q API reference][reference].
|
||||
- A growing [examples gallery][examples], showing how Q can be used to make
|
||||
everything better. From XHR to database access to accessing the Flickr API,
|
||||
Q is there for you.
|
||||
- There are many libraries that produce and consume Q promises for everything
|
||||
from file system/database access or RPC to templating. For a list of some of
|
||||
the more popular ones, see [Libraries][].
|
||||
- If you want materials that introduce the promise concept generally, and the
|
||||
below tutorial isn't doing it for you, check out our collection of
|
||||
[presentations, blog posts, and podcasts][resources].
|
||||
- A guide for those [coming from jQuery's `$.Deferred`][jquery].
|
||||
|
||||
We'd also love to have you join the Q-Continuum [mailing list][].
|
||||
|
||||
[wiki]: https://github.com/kriskowal/q/wiki
|
||||
[reference]: https://github.com/kriskowal/q/wiki/API-Reference
|
||||
[examples]: https://github.com/kriskowal/q/wiki/Examples-Gallery
|
||||
[Libraries]: https://github.com/kriskowal/q/wiki/Libraries
|
||||
[resources]: https://github.com/kriskowal/q/wiki/General-Promise-Resources
|
||||
[jquery]: https://github.com/kriskowal/q/wiki/Coming-from-jQuery
|
||||
[mailing list]: https://groups.google.com/forum/#!forum/q-continuum
|
||||
|
||||
|
||||
## Tutorial
|
||||
|
||||
Promises have a ``then`` method, which you can use to get the eventual
|
||||
return value (fulfillment) or thrown exception (rejection).
|
||||
|
||||
```javascript
|
||||
promiseMeSomething()
|
||||
.then(function (value) {
|
||||
}, function (reason) {
|
||||
});
|
||||
```
|
||||
|
||||
If ``promiseMeSomething`` returns a promise that gets fulfilled later
|
||||
with a return value, the first function (the fulfillment handler) will be
|
||||
called with the value. However, if the ``promiseMeSomething`` function
|
||||
gets rejected later by a thrown exception, the second function (the
|
||||
rejection handler) will be called with the exception.
|
||||
|
||||
Note that resolution of a promise is always asynchronous: that is, the
|
||||
fulfillment or rejection handler will always be called in the next turn of the
|
||||
event loop (i.e. `process.nextTick` in Node). This gives you a nice
|
||||
guarantee when mentally tracing the flow of your code, namely that
|
||||
``then`` will always return before either handler is executed.
|
||||
|
||||
In this tutorial, we begin with how to consume and work with promises. We'll
|
||||
talk about how to create them, and thus create functions like
|
||||
`promiseMeSomething` that return promises, [below](#the-beginning).
|
||||
|
||||
|
||||
### Propagation
|
||||
|
||||
The ``then`` method returns a promise, which in this example, I’m
|
||||
assigning to ``outputPromise``.
|
||||
|
||||
```javascript
|
||||
var outputPromise = getInputPromise()
|
||||
.then(function (input) {
|
||||
}, function (reason) {
|
||||
});
|
||||
```
|
||||
|
||||
The ``outputPromise`` variable becomes a new promise for the return
|
||||
value of either handler. Since a function can only either return a
|
||||
value or throw an exception, only one handler will ever be called and it
|
||||
will be responsible for resolving ``outputPromise``.
|
||||
|
||||
- If you return a value in a handler, ``outputPromise`` will get
|
||||
fulfilled.
|
||||
|
||||
- If you throw an exception in a handler, ``outputPromise`` will get
|
||||
rejected.
|
||||
|
||||
- If you return a **promise** in a handler, ``outputPromise`` will
|
||||
“become” that promise. Being able to become a new promise is useful
|
||||
for managing delays, combining results, or recovering from errors.
|
||||
|
||||
If the ``getInputPromise()`` promise gets rejected and you omit the
|
||||
rejection handler, the **error** will go to ``outputPromise``:
|
||||
|
||||
```javascript
|
||||
var outputPromise = getInputPromise()
|
||||
.then(function (value) {
|
||||
});
|
||||
```
|
||||
|
||||
If the input promise gets fulfilled and you omit the fulfillment handler, the
|
||||
**value** will go to ``outputPromise``:
|
||||
|
||||
```javascript
|
||||
var outputPromise = getInputPromise()
|
||||
.then(null, function (error) {
|
||||
});
|
||||
```
|
||||
|
||||
Q promises provide a ``fail`` shorthand for ``then`` when you are only
|
||||
interested in handling the error:
|
||||
|
||||
```javascript
|
||||
var outputPromise = getInputPromise()
|
||||
.fail(function (error) {
|
||||
});
|
||||
```
|
||||
|
||||
If you are writing JavaScript for modern engines only or using
|
||||
CoffeeScript, you may use `catch` instead of `fail`.
|
||||
|
||||
Promises also have a ``fin`` function that is like a ``finally`` clause.
|
||||
The final handler gets called, with no arguments, when the promise
|
||||
returned by ``getInputPromise()`` either returns a value or throws an
|
||||
error. The value returned or error thrown by ``getInputPromise()``
|
||||
passes directly to ``outputPromise`` unless the final handler fails, and
|
||||
may be delayed if the final handler returns a promise.
|
||||
|
||||
```javascript
|
||||
var outputPromise = getInputPromise()
|
||||
.fin(function () {
|
||||
// close files, database connections, stop servers, conclude tests
|
||||
});
|
||||
```
|
||||
|
||||
- If the handler returns a value, the value is ignored
|
||||
- If the handler throws an error, the error passes to ``outputPromise``
|
||||
- If the handler returns a promise, ``outputPromise`` gets postponed. The
|
||||
eventual value or error has the same effect as an immediate return
|
||||
value or thrown error: a value would be ignored, an error would be
|
||||
forwarded.
|
||||
|
||||
If you are writing JavaScript for modern engines only or using
|
||||
CoffeeScript, you may use `finally` instead of `fin`.
|
||||
|
||||
### Chaining
|
||||
|
||||
There are two ways to chain promises. You can chain promises either
|
||||
inside or outside handlers. The next two examples are equivalent.
|
||||
|
||||
```javascript
|
||||
return getUsername()
|
||||
.then(function (username) {
|
||||
return getUser(username)
|
||||
.then(function (user) {
|
||||
// if we get here without an error,
|
||||
// the value returned here
|
||||
// or the exception thrown here
|
||||
// resolves the promise returned
|
||||
// by the first line
|
||||
})
|
||||
});
|
||||
```
|
||||
|
||||
```javascript
|
||||
return getUsername()
|
||||
.then(function (username) {
|
||||
return getUser(username);
|
||||
})
|
||||
.then(function (user) {
|
||||
// if we get here without an error,
|
||||
// the value returned here
|
||||
// or the exception thrown here
|
||||
// resolves the promise returned
|
||||
// by the first line
|
||||
});
|
||||
```
|
||||
|
||||
The only difference is nesting. It’s useful to nest handlers if you
|
||||
need to capture multiple input values in your closure.
|
||||
|
||||
```javascript
|
||||
function authenticate() {
|
||||
return getUsername()
|
||||
.then(function (username) {
|
||||
return getUser(username);
|
||||
})
|
||||
// chained because we will not need the user name in the next event
|
||||
.then(function (user) {
|
||||
return getPassword()
|
||||
// nested because we need both user and password next
|
||||
.then(function (password) {
|
||||
if (user.passwordHash !== hash(password)) {
|
||||
throw new Error("Can't authenticate");
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
### Combination
|
||||
|
||||
You can turn an array of promises into a promise for the whole,
|
||||
fulfilled array using ``all``.
|
||||
|
||||
```javascript
|
||||
return Q.all([
|
||||
eventualAdd(2, 2),
|
||||
eventualAdd(10, 20)
|
||||
]);
|
||||
```
|
||||
|
||||
If you have a promise for an array, you can use ``spread`` as a
|
||||
replacement for ``then``. The ``spread`` function “spreads” the
|
||||
values over the arguments of the fulfillment handler. The rejection handler
|
||||
will get called at the first sign of failure. That is, whichever of
|
||||
the received promises fails first gets handled by the rejection handler.
|
||||
|
||||
```javascript
|
||||
function eventualAdd(a, b) {
|
||||
return Q.spread([a, b], function (a, b) {
|
||||
return a + b;
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
But ``spread`` calls ``all`` initially, so you can skip it in chains.
|
||||
|
||||
```javascript
|
||||
return getUsername()
|
||||
.then(function (username) {
|
||||
return [username, getUser(username)];
|
||||
})
|
||||
.spread(function (username, user) {
|
||||
});
|
||||
```
|
||||
|
||||
The ``all`` function returns a promise for an array of values. When this
|
||||
promise is fulfilled, the array contains the fulfillment values of the original
|
||||
promises, in the same order as those promises. If one of the given promises
|
||||
is rejected, the returned promise is immediately rejected, not waiting for the
|
||||
rest of the batch. If you want to wait for all of the promises to either be
|
||||
fulfilled or rejected, you can use ``allSettled``.
|
||||
|
||||
```javascript
|
||||
Q.allSettled(promises)
|
||||
.then(function (results) {
|
||||
results.forEach(function (result) {
|
||||
if (result.state === "fulfilled") {
|
||||
var value = result.value;
|
||||
} else {
|
||||
var reason = result.reason;
|
||||
}
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
The ``any`` function accepts an array of promises and returns a promise that is
|
||||
fulfilled by the first given promise to be fulfilled, or rejected if all of the
|
||||
given promises are rejected.
|
||||
|
||||
```javascript
|
||||
Q.any(promises)
|
||||
.then(function (first) {
|
||||
// Any of the promises was fulfilled.
|
||||
}, function (error) {
|
||||
// All of the promises were rejected.
|
||||
});
|
||||
```
|
||||
|
||||
### Sequences
|
||||
|
||||
If you have a number of promise-producing functions that need
|
||||
to be run sequentially, you can of course do so manually:
|
||||
|
||||
```javascript
|
||||
return foo(initialVal).then(bar).then(baz).then(qux);
|
||||
```
|
||||
|
||||
However, if you want to run a dynamically constructed sequence of
|
||||
functions, you'll want something like this:
|
||||
|
||||
```javascript
|
||||
var funcs = [foo, bar, baz, qux];
|
||||
|
||||
var result = Q(initialVal);
|
||||
funcs.forEach(function (f) {
|
||||
result = result.then(f);
|
||||
});
|
||||
return result;
|
||||
```
|
||||
|
||||
You can make this slightly more compact using `reduce`:
|
||||
|
||||
```javascript
|
||||
return funcs.reduce(function (soFar, f) {
|
||||
return soFar.then(f);
|
||||
}, Q(initialVal));
|
||||
```
|
||||
|
||||
Or, you could use the ultra-compact version:
|
||||
|
||||
```javascript
|
||||
return funcs.reduce(Q.when, Q(initialVal));
|
||||
```
|
||||
|
||||
### Handling Errors
|
||||
|
||||
One sometimes-unintuitive aspect of promises is that if you throw an
|
||||
exception in the fulfillment handler, it will not be caught by the error
|
||||
handler.
|
||||
|
||||
```javascript
|
||||
return foo()
|
||||
.then(function (value) {
|
||||
throw new Error("Can't bar.");
|
||||
}, function (error) {
|
||||
// We only get here if "foo" fails
|
||||
});
|
||||
```
|
||||
|
||||
To see why this is, consider the parallel between promises and
|
||||
``try``/``catch``. We are ``try``-ing to execute ``foo()``: the error
|
||||
handler represents a ``catch`` for ``foo()``, while the fulfillment handler
|
||||
represents code that happens *after* the ``try``/``catch`` block.
|
||||
That code then needs its own ``try``/``catch`` block.
|
||||
|
||||
In terms of promises, this means chaining your rejection handler:
|
||||
|
||||
```javascript
|
||||
return foo()
|
||||
.then(function (value) {
|
||||
throw new Error("Can't bar.");
|
||||
})
|
||||
.fail(function (error) {
|
||||
// We get here with either foo's error or bar's error
|
||||
});
|
||||
```
|
||||
|
||||
### Progress Notification
|
||||
|
||||
It's possible for promises to report their progress, e.g. for tasks that take a
|
||||
long time like a file upload. Not all promises will implement progress
|
||||
notifications, but for those that do, you can consume the progress values using
|
||||
a third parameter to ``then``:
|
||||
|
||||
```javascript
|
||||
return uploadFile()
|
||||
.then(function () {
|
||||
// Success uploading the file
|
||||
}, function (err) {
|
||||
// There was an error, and we get the reason for error
|
||||
}, function (progress) {
|
||||
// We get notified of the upload's progress as it is executed
|
||||
});
|
||||
```
|
||||
|
||||
Like `fail`, Q also provides a shorthand for progress callbacks
|
||||
called `progress`:
|
||||
|
||||
```javascript
|
||||
return uploadFile().progress(function (progress) {
|
||||
// We get notified of the upload's progress
|
||||
});
|
||||
```
|
||||
|
||||
### The End
|
||||
|
||||
When you get to the end of a chain of promises, you should either
|
||||
return the last promise or end the chain. Since handlers catch
|
||||
errors, it’s an unfortunate pattern that the exceptions can go
|
||||
unobserved.
|
||||
|
||||
So, either return it,
|
||||
|
||||
```javascript
|
||||
return foo()
|
||||
.then(function () {
|
||||
return "bar";
|
||||
});
|
||||
```
|
||||
|
||||
Or, end it.
|
||||
|
||||
```javascript
|
||||
foo()
|
||||
.then(function () {
|
||||
return "bar";
|
||||
})
|
||||
.done();
|
||||
```
|
||||
|
||||
Ending a promise chain makes sure that, if an error doesn’t get
|
||||
handled before the end, it will get rethrown and reported.
|
||||
|
||||
This is a stopgap. We are exploring ways to make unhandled errors
|
||||
visible without any explicit handling.
|
||||
|
||||
|
||||
### The Beginning
|
||||
|
||||
Everything above assumes you get a promise from somewhere else. This
|
||||
is the common case. Every once in a while, you will need to create a
|
||||
promise from scratch.
|
||||
|
||||
#### Using ``Q.fcall``
|
||||
|
||||
You can create a promise from a value using ``Q.fcall``. This returns a
|
||||
promise for 10.
|
||||
|
||||
```javascript
|
||||
return Q.fcall(function () {
|
||||
return 10;
|
||||
});
|
||||
```
|
||||
|
||||
You can also use ``fcall`` to get a promise for an exception.
|
||||
|
||||
```javascript
|
||||
return Q.fcall(function () {
|
||||
throw new Error("Can't do it");
|
||||
});
|
||||
```
|
||||
|
||||
As the name implies, ``fcall`` can call functions, or even promised
|
||||
functions. This uses the ``eventualAdd`` function above to add two
|
||||
numbers.
|
||||
|
||||
```javascript
|
||||
return Q.fcall(eventualAdd, 2, 2);
|
||||
```
|
||||
|
||||
|
||||
#### Using Deferreds
|
||||
|
||||
If you have to interface with asynchronous functions that are callback-based
|
||||
instead of promise-based, Q provides a few shortcuts (like ``Q.nfcall`` and
|
||||
friends). But much of the time, the solution will be to use *deferreds*.
|
||||
|
||||
```javascript
|
||||
var deferred = Q.defer();
|
||||
FS.readFile("foo.txt", "utf-8", function (error, text) {
|
||||
if (error) {
|
||||
deferred.reject(new Error(error));
|
||||
} else {
|
||||
deferred.resolve(text);
|
||||
}
|
||||
});
|
||||
return deferred.promise;
|
||||
```
|
||||
|
||||
Note that a deferred can be resolved with a value or a promise. The
|
||||
``reject`` function is a shorthand for resolving with a rejected
|
||||
promise.
|
||||
|
||||
```javascript
|
||||
// this:
|
||||
deferred.reject(new Error("Can't do it"));
|
||||
|
||||
// is shorthand for:
|
||||
var rejection = Q.fcall(function () {
|
||||
throw new Error("Can't do it");
|
||||
});
|
||||
deferred.resolve(rejection);
|
||||
```
|
||||
|
||||
This is a simplified implementation of ``Q.delay``.
|
||||
|
||||
```javascript
|
||||
function delay(ms) {
|
||||
var deferred = Q.defer();
|
||||
setTimeout(deferred.resolve, ms);
|
||||
return deferred.promise;
|
||||
}
|
||||
```
|
||||
|
||||
This is a simplified implementation of ``Q.timeout``
|
||||
|
||||
```javascript
|
||||
function timeout(promise, ms) {
|
||||
var deferred = Q.defer();
|
||||
Q.when(promise, deferred.resolve);
|
||||
delay(ms).then(function () {
|
||||
deferred.reject(new Error("Timed out"));
|
||||
});
|
||||
return deferred.promise;
|
||||
}
|
||||
```
|
||||
|
||||
Finally, you can send a progress notification to the promise with
|
||||
``deferred.notify``.
|
||||
|
||||
For illustration, this is a wrapper for XML HTTP requests in the browser. Note
|
||||
that a more [thorough][XHR] implementation would be in order in practice.
|
||||
|
||||
[XHR]: https://github.com/montagejs/mr/blob/71e8df99bb4f0584985accd6f2801ef3015b9763/browser.js#L29-L73
|
||||
|
||||
```javascript
|
||||
function requestOkText(url) {
|
||||
var request = new XMLHttpRequest();
|
||||
var deferred = Q.defer();
|
||||
|
||||
request.open("GET", url, true);
|
||||
request.onload = onload;
|
||||
request.onerror = onerror;
|
||||
request.onprogress = onprogress;
|
||||
request.send();
|
||||
|
||||
function onload() {
|
||||
if (request.status === 200) {
|
||||
deferred.resolve(request.responseText);
|
||||
} else {
|
||||
deferred.reject(new Error("Status code was " + request.status));
|
||||
}
|
||||
}
|
||||
|
||||
function onerror() {
|
||||
deferred.reject(new Error("Can't XHR " + JSON.stringify(url)));
|
||||
}
|
||||
|
||||
function onprogress(event) {
|
||||
deferred.notify(event.loaded / event.total);
|
||||
}
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
```
|
||||
|
||||
Below is an example of how to use this ``requestOkText`` function:
|
||||
|
||||
```javascript
|
||||
requestOkText("http://localhost:3000")
|
||||
.then(function (responseText) {
|
||||
// If the HTTP response returns 200 OK, log the response text.
|
||||
console.log(responseText);
|
||||
}, function (error) {
|
||||
// If there's an error or a non-200 status code, log the error.
|
||||
console.error(error);
|
||||
}, function (progress) {
|
||||
// Log the progress as it comes in.
|
||||
console.log("Request progress: " + Math.round(progress * 100) + "%");
|
||||
});
|
||||
```
|
||||
|
||||
#### Using `Q.Promise`
|
||||
|
||||
This is an alternative promise-creation API that has the same power as
|
||||
the deferred concept, but without introducing another conceptual entity.
|
||||
|
||||
Rewriting the `requestOkText` example above using `Q.Promise`:
|
||||
|
||||
```javascript
|
||||
function requestOkText(url) {
|
||||
return Q.Promise(function(resolve, reject, notify) {
|
||||
var request = new XMLHttpRequest();
|
||||
|
||||
request.open("GET", url, true);
|
||||
request.onload = onload;
|
||||
request.onerror = onerror;
|
||||
request.onprogress = onprogress;
|
||||
request.send();
|
||||
|
||||
function onload() {
|
||||
if (request.status === 200) {
|
||||
resolve(request.responseText);
|
||||
} else {
|
||||
reject(new Error("Status code was " + request.status));
|
||||
}
|
||||
}
|
||||
|
||||
function onerror() {
|
||||
reject(new Error("Can't XHR " + JSON.stringify(url)));
|
||||
}
|
||||
|
||||
function onprogress(event) {
|
||||
notify(event.loaded / event.total);
|
||||
}
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
If `requestOkText` were to throw an exception, the returned promise would be
|
||||
rejected with that thrown exception as the rejection reason.
|
||||
|
||||
### The Middle
|
||||
|
||||
If you are using a function that may return a promise, but just might
|
||||
return a value if it doesn’t need to defer, you can use the “static”
|
||||
methods of the Q library.
|
||||
|
||||
The ``when`` function is the static equivalent for ``then``.
|
||||
|
||||
```javascript
|
||||
return Q.when(valueOrPromise, function (value) {
|
||||
}, function (error) {
|
||||
});
|
||||
```
|
||||
|
||||
All of the other methods on a promise have static analogs with the
|
||||
same name.
|
||||
|
||||
The following are equivalent:
|
||||
|
||||
```javascript
|
||||
return Q.all([a, b]);
|
||||
```
|
||||
|
||||
```javascript
|
||||
return Q.fcall(function () {
|
||||
return [a, b];
|
||||
})
|
||||
.all();
|
||||
```
|
||||
|
||||
When working with promises provided by other libraries, you should
|
||||
convert it to a Q promise. Not all promise libraries make the same
|
||||
guarantees as Q and certainly don’t provide all of the same methods.
|
||||
Most libraries only provide a partially functional ``then`` method.
|
||||
This thankfully is all we need to turn them into vibrant Q promises.
|
||||
|
||||
```javascript
|
||||
return Q($.ajax(...))
|
||||
.then(function () {
|
||||
});
|
||||
```
|
||||
|
||||
If there is any chance that the promise you receive is not a Q promise
|
||||
as provided by your library, you should wrap it using a Q function.
|
||||
You can even use ``Q.invoke`` as a shorthand.
|
||||
|
||||
```javascript
|
||||
return Q.invoke($, 'ajax', ...)
|
||||
.then(function () {
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
### Over the Wire
|
||||
|
||||
A promise can serve as a proxy for another object, even a remote
|
||||
object. There are methods that allow you to optimistically manipulate
|
||||
properties or call functions. All of these interactions return
|
||||
promises, so they can be chained.
|
||||
|
||||
```
|
||||
direct manipulation using a promise as a proxy
|
||||
-------------------------- -------------------------------
|
||||
value.foo promise.get("foo")
|
||||
value.foo = value promise.put("foo", value)
|
||||
delete value.foo promise.del("foo")
|
||||
value.foo(...args) promise.post("foo", [args])
|
||||
value.foo(...args) promise.invoke("foo", ...args)
|
||||
value(...args) promise.fapply([args])
|
||||
value(...args) promise.fcall(...args)
|
||||
```
|
||||
|
||||
If the promise is a proxy for a remote object, you can shave
|
||||
round-trips by using these functions instead of ``then``. To take
|
||||
advantage of promises for remote objects, check out [Q-Connection][].
|
||||
|
||||
[Q-Connection]: https://github.com/kriskowal/q-connection
|
||||
|
||||
Even in the case of non-remote objects, these methods can be used as
|
||||
shorthand for particularly-simple fulfillment handlers. For example, you
|
||||
can replace
|
||||
|
||||
```javascript
|
||||
return Q.fcall(function () {
|
||||
return [{ foo: "bar" }, { foo: "baz" }];
|
||||
})
|
||||
.then(function (value) {
|
||||
return value[0].foo;
|
||||
});
|
||||
```
|
||||
|
||||
with
|
||||
|
||||
```javascript
|
||||
return Q.fcall(function () {
|
||||
return [{ foo: "bar" }, { foo: "baz" }];
|
||||
})
|
||||
.get(0)
|
||||
.get("foo");
|
||||
```
|
||||
|
||||
|
||||
### Adapting Node
|
||||
|
||||
If you're working with functions that make use of the Node.js callback pattern,
|
||||
where callbacks are in the form of `function(err, result)`, Q provides a few
|
||||
useful utility functions for converting between them. The most straightforward
|
||||
are probably `Q.nfcall` and `Q.nfapply` ("Node function call/apply") for calling
|
||||
Node.js-style functions and getting back a promise:
|
||||
|
||||
```javascript
|
||||
return Q.nfcall(FS.readFile, "foo.txt", "utf-8");
|
||||
return Q.nfapply(FS.readFile, ["foo.txt", "utf-8"]);
|
||||
```
|
||||
|
||||
If you are working with methods, instead of simple functions, you can easily
|
||||
run in to the usual problems where passing a method to another function—like
|
||||
`Q.nfcall`—"un-binds" the method from its owner. To avoid this, you can either
|
||||
use `Function.prototype.bind` or some nice shortcut methods we provide:
|
||||
|
||||
```javascript
|
||||
return Q.ninvoke(redisClient, "get", "user:1:id");
|
||||
return Q.npost(redisClient, "get", ["user:1:id"]);
|
||||
```
|
||||
|
||||
You can also create reusable wrappers with `Q.denodeify` or `Q.nbind`:
|
||||
|
||||
```javascript
|
||||
var readFile = Q.denodeify(FS.readFile);
|
||||
return readFile("foo.txt", "utf-8");
|
||||
|
||||
var redisClientGet = Q.nbind(redisClient.get, redisClient);
|
||||
return redisClientGet("user:1:id");
|
||||
```
|
||||
|
||||
Finally, if you're working with raw deferred objects, there is a
|
||||
`makeNodeResolver` method on deferreds that can be handy:
|
||||
|
||||
```javascript
|
||||
var deferred = Q.defer();
|
||||
FS.readFile("foo.txt", "utf-8", deferred.makeNodeResolver());
|
||||
return deferred.promise;
|
||||
```
|
||||
|
||||
### Long Stack Traces
|
||||
|
||||
Q comes with optional support for “long stack traces,” wherein the `stack`
|
||||
property of `Error` rejection reasons is rewritten to be traced along
|
||||
asynchronous jumps instead of stopping at the most recent one. As an example:
|
||||
|
||||
```js
|
||||
function theDepthsOfMyProgram() {
|
||||
Q.delay(100).done(function explode() {
|
||||
throw new Error("boo!");
|
||||
});
|
||||
}
|
||||
|
||||
theDepthsOfMyProgram();
|
||||
```
|
||||
|
||||
usually would give a rather unhelpful stack trace looking something like
|
||||
|
||||
```
|
||||
Error: boo!
|
||||
at explode (/path/to/test.js:3:11)
|
||||
at _fulfilled (/path/to/test.js:q:54)
|
||||
at resolvedValue.promiseDispatch.done (/path/to/q.js:823:30)
|
||||
at makePromise.promise.promiseDispatch (/path/to/q.js:496:13)
|
||||
at pending (/path/to/q.js:397:39)
|
||||
at process.startup.processNextTick.process._tickCallback (node.js:244:9)
|
||||
```
|
||||
|
||||
But, if you turn this feature on by setting
|
||||
|
||||
```js
|
||||
Q.longStackSupport = true;
|
||||
```
|
||||
|
||||
then the above code gives a nice stack trace to the tune of
|
||||
|
||||
```
|
||||
Error: boo!
|
||||
at explode (/path/to/test.js:3:11)
|
||||
From previous event:
|
||||
at theDepthsOfMyProgram (/path/to/test.js:2:16)
|
||||
at Object.<anonymous> (/path/to/test.js:7:1)
|
||||
```
|
||||
|
||||
Note how you can see the function that triggered the async operation in the
|
||||
stack trace! This is very helpful for debugging, as otherwise you end up getting
|
||||
only the first line, plus a bunch of Q internals, with no sign of where the
|
||||
operation started.
|
||||
|
||||
In node.js, this feature can also be enabled through the Q_DEBUG environment
|
||||
variable:
|
||||
|
||||
```
|
||||
Q_DEBUG=1 node server.js
|
||||
```
|
||||
|
||||
This will enable long stack support in every instance of Q.
|
||||
|
||||
This feature does come with somewhat-serious performance and memory overhead,
|
||||
however. If you're working with lots of promises, or trying to scale a server
|
||||
to many users, you should probably keep it off. But in development, go for it!
|
||||
|
||||
## Tests
|
||||
|
||||
You can view the results of the Q test suite [in your browser][tests]!
|
||||
|
||||
[tests]: https://rawgithub.com/kriskowal/q/v1/spec/q-spec.html
|
||||
|
||||
## License
|
||||
|
||||
Copyright 2009–2017 Kristopher Michael Kowal and contributors
|
||||
MIT License (enclosed)
|
||||
|
||||
116
node_modules/q/package.json
generated
vendored
Normal file
116
node_modules/q/package.json
generated
vendored
Normal file
@@ -0,0 +1,116 @@
|
||||
{
|
||||
"_from": "q@1.x",
|
||||
"_id": "q@1.5.1",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-fjL3W0E4EpHQRhHxvxQQmsAGUdc=",
|
||||
"_location": "/q",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "q@1.x",
|
||||
"name": "q",
|
||||
"escapedName": "q",
|
||||
"rawSpec": "1.x",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "1.x"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/ping"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/q/-/q-1.5.1.tgz",
|
||||
"_shasum": "7e32f75b41381291d04611f1bf14109ac00651d7",
|
||||
"_spec": "q@1.x",
|
||||
"_where": "D:\\Programming\\Projects\\Down-Detector\\node_modules\\ping",
|
||||
"author": {
|
||||
"name": "Kris Kowal",
|
||||
"email": "kris@cixar.com",
|
||||
"url": "https://github.com/kriskowal"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "http://github.com/kriskowal/q/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Kris Kowal",
|
||||
"email": "kris@cixar.com",
|
||||
"url": "https://github.com/kriskowal"
|
||||
},
|
||||
{
|
||||
"name": "Irakli Gozalishvili",
|
||||
"email": "rfobic@gmail.com",
|
||||
"url": "http://jeditoolkit.com"
|
||||
},
|
||||
{
|
||||
"name": "Domenic Denicola",
|
||||
"email": "domenic@domenicdenicola.com",
|
||||
"url": "http://domenicdenicola.com"
|
||||
}
|
||||
],
|
||||
"dependencies": {},
|
||||
"deprecated": false,
|
||||
"description": "A library for promises (CommonJS/Promises/A,B,D)",
|
||||
"devDependencies": {
|
||||
"cover": "*",
|
||||
"grunt": "~0.4.1",
|
||||
"grunt-cli": "~0.1.9",
|
||||
"grunt-contrib-uglify": "~0.9.1",
|
||||
"jasmine-node": "1.11.0",
|
||||
"jshint": "~2.1.9",
|
||||
"matcha": "~0.2.0",
|
||||
"opener": "*",
|
||||
"promises-aplus-tests": "1.x"
|
||||
},
|
||||
"directories": {
|
||||
"test": "./spec"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.6.0",
|
||||
"teleport": ">=0.2.0"
|
||||
},
|
||||
"files": [
|
||||
"LICENSE",
|
||||
"q.js",
|
||||
"queue.js"
|
||||
],
|
||||
"homepage": "https://github.com/kriskowal/q",
|
||||
"keywords": [
|
||||
"q",
|
||||
"promise",
|
||||
"promises",
|
||||
"promises-a",
|
||||
"promises-aplus",
|
||||
"deferred",
|
||||
"future",
|
||||
"async",
|
||||
"flow control",
|
||||
"fluent",
|
||||
"browser",
|
||||
"node"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "q.js",
|
||||
"name": "q",
|
||||
"overlay": {
|
||||
"teleport": {
|
||||
"dependencies": {
|
||||
"system": ">=0.0.4"
|
||||
}
|
||||
}
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/kriskowal/q.git"
|
||||
},
|
||||
"scripts": {
|
||||
"benchmark": "matcha",
|
||||
"cover": "cover run jasmine-node spec && cover report html && opener cover_html/index.html",
|
||||
"lint": "jshint q.js",
|
||||
"minify": "grunt",
|
||||
"prepublish": "grunt",
|
||||
"test": "npm ls -s && jasmine-node spec && promises-aplus-tests spec/aplus-adapter && npm run -s lint",
|
||||
"test-browser": "opener spec/q-spec.html"
|
||||
},
|
||||
"version": "1.5.1"
|
||||
}
|
||||
2076
node_modules/q/q.js
generated
vendored
Normal file
2076
node_modules/q/q.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
35
node_modules/q/queue.js
generated
vendored
Normal file
35
node_modules/q/queue.js
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
|
||||
var Q = require("./q");
|
||||
|
||||
module.exports = Queue;
|
||||
function Queue() {
|
||||
var ends = Q.defer();
|
||||
var closed = Q.defer();
|
||||
return {
|
||||
put: function (value) {
|
||||
var next = Q.defer();
|
||||
ends.resolve({
|
||||
head: value,
|
||||
tail: next.promise
|
||||
});
|
||||
ends.resolve = next.resolve;
|
||||
},
|
||||
get: function () {
|
||||
var result = ends.promise.get("head");
|
||||
ends.promise = ends.promise.get("tail");
|
||||
return result.fail(function (error) {
|
||||
closed.resolve(error);
|
||||
throw error;
|
||||
});
|
||||
},
|
||||
closed: closed.promise,
|
||||
close: function (error) {
|
||||
error = error || new Error("Can't get value from closed queue");
|
||||
var end = {head: Q.reject(error)};
|
||||
end.tail = end;
|
||||
ends.resolve(end);
|
||||
return closed.promise;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
23
node_modules/underscore/LICENSE
generated
vendored
Normal file
23
node_modules/underscore/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
Copyright (c) 2009-2017 Jeremy Ashkenas, DocumentCloud and Investigative
|
||||
Reporters & Editors
|
||||
|
||||
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.
|
||||
28
node_modules/underscore/README.md
generated
vendored
Normal file
28
node_modules/underscore/README.md
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
__
|
||||
/\ \ __
|
||||
__ __ ___ \_\ \ __ _ __ ____ ___ ___ _ __ __ /\_\ ____
|
||||
/\ \/\ \ /' _ `\ /'_ \ /'__`\/\ __\/ ,__\ / ___\ / __`\/\ __\/'__`\ \/\ \ /',__\
|
||||
\ \ \_\ \/\ \/\ \/\ \ \ \/\ __/\ \ \//\__, `\/\ \__//\ \ \ \ \ \//\ __/ __ \ \ \/\__, `\
|
||||
\ \____/\ \_\ \_\ \___,_\ \____\\ \_\\/\____/\ \____\ \____/\ \_\\ \____\/\_\ _\ \ \/\____/
|
||||
\/___/ \/_/\/_/\/__,_ /\/____/ \/_/ \/___/ \/____/\/___/ \/_/ \/____/\/_//\ \_\ \/___/
|
||||
\ \____/
|
||||
\/___/
|
||||
|
||||
Underscore.js is a utility-belt library for JavaScript that provides
|
||||
support for the usual functional suspects (each, map, reduce, filter...)
|
||||
without extending any core JavaScript objects.
|
||||
|
||||
For Docs, License, Tests, and pre-packed downloads, see:
|
||||
http://underscorejs.org
|
||||
|
||||
For support and questions, please use
|
||||
[the gitter channel](https://gitter.im/jashkenas/underscore)
|
||||
or [stackoverflow](http://stackoverflow.com/search?q=underscore.js)
|
||||
|
||||
Underscore is an open-sourced component of DocumentCloud:
|
||||
https://github.com/documentcloud
|
||||
|
||||
Many thanks to our contributors:
|
||||
https://github.com/jashkenas/underscore/contributors
|
||||
|
||||
This project adheres to a [code of conduct](CODE_OF_CONDUCT.md). By participating, you are expected to uphold this code.
|
||||
81
node_modules/underscore/package.json
generated
vendored
Normal file
81
node_modules/underscore/package.json
generated
vendored
Normal file
@@ -0,0 +1,81 @@
|
||||
{
|
||||
"_from": "underscore@^1.8.3",
|
||||
"_id": "underscore@1.9.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-4IV1DSSxC1QK48j9ONFK1MoIAKKkbE8i7u55w2R6IqBqbT7A/iG7aZBCR2Bi8piF0Uz+i/MG1aeqLwl/5vqF+A==",
|
||||
"_location": "/underscore",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "underscore@^1.8.3",
|
||||
"name": "underscore",
|
||||
"escapedName": "underscore",
|
||||
"rawSpec": "^1.8.3",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^1.8.3"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/ping"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/underscore/-/underscore-1.9.0.tgz",
|
||||
"_shasum": "31dbb314cfcc88f169cd3692d9149d81a00a73e4",
|
||||
"_spec": "underscore@^1.8.3",
|
||||
"_where": "D:\\Programming\\Projects\\Down-Detector\\node_modules\\ping",
|
||||
"author": {
|
||||
"name": "Jeremy Ashkenas",
|
||||
"email": "jeremy@documentcloud.org"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/jashkenas/underscore/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"deprecated": false,
|
||||
"description": "JavaScript's functional programming helper library.",
|
||||
"devDependencies": {
|
||||
"coveralls": "^2.11.2",
|
||||
"docco": "*",
|
||||
"eslint": "1.10.x",
|
||||
"gzip-size-cli": "^1.0.0",
|
||||
"karma": "^0.13.13",
|
||||
"karma-qunit": "~2.0.1",
|
||||
"nyc": "^2.1.3",
|
||||
"pretty-bytes-cli": "^1.0.0",
|
||||
"qunit": "^2.6.0",
|
||||
"qunit-cli": "~0.2.0",
|
||||
"uglify-js": "3.3.21"
|
||||
},
|
||||
"files": [
|
||||
"underscore.js",
|
||||
"underscore-min.js",
|
||||
"underscore-min.js.map"
|
||||
],
|
||||
"homepage": "http://underscorejs.org",
|
||||
"keywords": [
|
||||
"util",
|
||||
"functional",
|
||||
"server",
|
||||
"client",
|
||||
"browser"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "underscore.js",
|
||||
"name": "underscore",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/jashkenas/underscore.git"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "npm run minify -- --source-map --source-map-url \" \" -o underscore-min.js",
|
||||
"coverage": "nyc npm run test-node && nyc report",
|
||||
"coveralls": "nyc npm run test-node && nyc report --reporter=text-lcov | coveralls",
|
||||
"doc": "docco underscore.js",
|
||||
"lint": "eslint underscore.js test/*.js",
|
||||
"minify": "uglifyjs underscore.js -c \"evaluate=false\" --comments \"/ .*/\" -m",
|
||||
"test": "npm run test-node && npm run lint",
|
||||
"test-browser": "npm i karma-phantomjs-launcher && karma start",
|
||||
"test-node": "qunit-cli test/*.js",
|
||||
"weight": "npm run minify | gzip-size | pretty-bytes"
|
||||
},
|
||||
"version": "1.9.0"
|
||||
}
|
||||
5
node_modules/underscore/underscore-min.js
generated
vendored
Normal file
5
node_modules/underscore/underscore-min.js
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
1
node_modules/underscore/underscore-min.js.map
generated
vendored
Normal file
1
node_modules/underscore/underscore-min.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
1688
node_modules/underscore/underscore.js
generated
vendored
Normal file
1688
node_modules/underscore/underscore.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user