schnee effeckt und fehler Korektur
This commit is contained in:
402
node_modules/bin-wrapper/index.js
generated
vendored
402
node_modules/bin-wrapper/index.js
generated
vendored
@@ -1,218 +1,208 @@
|
||||
'use strict';
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const url = require('url');
|
||||
const pify = require('pify');
|
||||
const importLazy = require('import-lazy')(require);
|
||||
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var lazyReq = require('lazy-req')(require);
|
||||
var binCheck = lazyReq('bin-check');
|
||||
var binVersionCheck = lazyReq('bin-version-check');
|
||||
var Download = lazyReq('download');
|
||||
var osFilterObj = lazyReq('os-filter-obj');
|
||||
const binCheck = importLazy('bin-check');
|
||||
const binVersionCheck = importLazy('bin-version-check');
|
||||
const download = importLazy('download');
|
||||
const osFilterObj = importLazy('os-filter-obj');
|
||||
|
||||
const statAsync = pify(fs.stat);
|
||||
const chmodAsync = pify(fs.chmod);
|
||||
|
||||
/**
|
||||
* Initialize a new `BinWrapper`
|
||||
*
|
||||
* @param {Object} opts
|
||||
* @param {Object} options
|
||||
* @api public
|
||||
*/
|
||||
module.exports = class BinWrapper {
|
||||
constructor(options = {}) {
|
||||
this.options = options;
|
||||
|
||||
function BinWrapper(opts) {
|
||||
if (!(this instanceof BinWrapper)) {
|
||||
return new BinWrapper(opts);
|
||||
if (this.options.strip <= 0) {
|
||||
this.options.strip = 0;
|
||||
} else if (!this.options.strip) {
|
||||
this.options.strip = 1;
|
||||
}
|
||||
}
|
||||
|
||||
this.opts = opts || {};
|
||||
this.opts.strip = this.opts.strip <= 0 ? 0 : !this.opts.strip ? 1 : this.opts.strip;
|
||||
/**
|
||||
* Get or set files to download
|
||||
*
|
||||
* @param {String} src
|
||||
* @param {String} os
|
||||
* @param {String} arch
|
||||
* @api public
|
||||
*/
|
||||
src(src, os, arch) {
|
||||
if (arguments.length === 0) {
|
||||
return this._src;
|
||||
}
|
||||
|
||||
this._src = this._src || [];
|
||||
this._src.push({
|
||||
url: src,
|
||||
os,
|
||||
arch
|
||||
});
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get or set the destination
|
||||
*
|
||||
* @param {String} dest
|
||||
* @api public
|
||||
*/
|
||||
dest(dest) {
|
||||
if (arguments.length === 0) {
|
||||
return this._dest;
|
||||
}
|
||||
|
||||
this._dest = dest;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get or set the binary
|
||||
*
|
||||
* @param {String} bin
|
||||
* @api public
|
||||
*/
|
||||
use(bin) {
|
||||
if (arguments.length === 0) {
|
||||
return this._use;
|
||||
}
|
||||
|
||||
this._use = bin;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get or set a semver range to test the binary against
|
||||
*
|
||||
* @param {String} range
|
||||
* @api public
|
||||
*/
|
||||
version(range) {
|
||||
if (arguments.length === 0) {
|
||||
return this._version;
|
||||
}
|
||||
|
||||
this._version = range;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get path to the binary
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
path() {
|
||||
return path.join(this.dest(), this.use());
|
||||
}
|
||||
|
||||
/**
|
||||
* Run
|
||||
*
|
||||
* @param {Array} cmd
|
||||
* @api public
|
||||
*/
|
||||
run(cmd = ['--version']) {
|
||||
return this.findExisting().then(() => {
|
||||
if (this.options.skipCheck) {
|
||||
return;
|
||||
}
|
||||
|
||||
return this.runCheck(cmd);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Run binary check
|
||||
*
|
||||
* @param {Array} cmd
|
||||
* @api private
|
||||
*/
|
||||
runCheck(cmd) {
|
||||
return binCheck(this.path(), cmd).then(works => {
|
||||
if (!works) {
|
||||
throw new Error(`The \`${this.path()}\` binary doesn't seem to work correctly`);
|
||||
}
|
||||
|
||||
if (this.version()) {
|
||||
return binVersionCheck(this.path(), this.version());
|
||||
}
|
||||
|
||||
return Promise.resolve();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Find existing files
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
findExisting() {
|
||||
return statAsync(this.path()).catch(error => {
|
||||
if (error && error.code === 'ENOENT') {
|
||||
return this.download();
|
||||
}
|
||||
|
||||
return Promise.reject(error);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Download files
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
download() {
|
||||
const files = osFilterObj(this.src() || []);
|
||||
const urls = [];
|
||||
|
||||
if (files.length === 0) {
|
||||
return Promise.reject(new Error('No binary found matching your system. It\'s probably not supported.'));
|
||||
}
|
||||
|
||||
files.forEach(file => urls.push(file.url));
|
||||
|
||||
return Promise.all(urls.map(url => download(url, this.dest(), {
|
||||
extract: true,
|
||||
strip: this.options.strip
|
||||
}))).then(result => {
|
||||
const resultingFiles = flatten(result.map((item, index) => {
|
||||
if (Array.isArray(item)) {
|
||||
return item.map(file => file.path);
|
||||
}
|
||||
|
||||
const parsedUrl = url.parse(files[index].url);
|
||||
const parsedPath = path.parse(parsedUrl.pathname);
|
||||
|
||||
return parsedPath.base;
|
||||
}));
|
||||
|
||||
return Promise.all(resultingFiles.map(fileName => {
|
||||
return chmodAsync(path.join(this.dest(), fileName), 0o755);
|
||||
}));
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
function flatten(arr) {
|
||||
return arr.reduce((acc, elem) => {
|
||||
if (Array.isArray(elem)) {
|
||||
acc.push(...elem);
|
||||
} else {
|
||||
acc.push(elem);
|
||||
}
|
||||
|
||||
return acc;
|
||||
}, []);
|
||||
}
|
||||
|
||||
module.exports = BinWrapper;
|
||||
|
||||
/**
|
||||
* Get or set files to download
|
||||
*
|
||||
* @param {String} src
|
||||
* @param {String} os
|
||||
* @param {String} arch
|
||||
* @api public
|
||||
*/
|
||||
|
||||
BinWrapper.prototype.src = function (src, os, arch) {
|
||||
if (!arguments.length) {
|
||||
return this._src;
|
||||
}
|
||||
|
||||
this._src = this._src || [];
|
||||
this._src.push({
|
||||
url: src,
|
||||
os: os,
|
||||
arch: arch
|
||||
});
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get or set the destination
|
||||
*
|
||||
* @param {String} dest
|
||||
* @api public
|
||||
*/
|
||||
|
||||
BinWrapper.prototype.dest = function (dest) {
|
||||
if (!arguments.length) {
|
||||
return this._dest;
|
||||
}
|
||||
|
||||
this._dest = dest;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get or set the binary
|
||||
*
|
||||
* @param {String} bin
|
||||
* @api public
|
||||
*/
|
||||
|
||||
BinWrapper.prototype.use = function (bin) {
|
||||
if (!arguments.length) {
|
||||
return this._use;
|
||||
}
|
||||
|
||||
this._use = bin;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get or set a semver range to test the binary against
|
||||
*
|
||||
* @param {String} range
|
||||
* @api public
|
||||
*/
|
||||
|
||||
BinWrapper.prototype.version = function (range) {
|
||||
if (!arguments.length) {
|
||||
return this._version;
|
||||
}
|
||||
|
||||
this._version = range;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get path to the binary
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
BinWrapper.prototype.path = function () {
|
||||
return path.join(this.dest(), this.use());
|
||||
};
|
||||
|
||||
/**
|
||||
* Run
|
||||
*
|
||||
* @param {Array} cmd
|
||||
* @param {Function} cb
|
||||
* @api public
|
||||
*/
|
||||
|
||||
BinWrapper.prototype.run = function (cmd, cb) {
|
||||
if (typeof cmd === 'function' && !cb) {
|
||||
cb = cmd;
|
||||
cmd = ['--version'];
|
||||
}
|
||||
|
||||
this.findExisting(function (err) {
|
||||
if (err) {
|
||||
cb(err);
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.opts.skipCheck) {
|
||||
cb();
|
||||
return;
|
||||
}
|
||||
|
||||
this.runCheck(cmd, cb);
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
/**
|
||||
* Run binary check
|
||||
*
|
||||
* @param {Array} cmd
|
||||
* @param {Function} cb
|
||||
* @api private
|
||||
*/
|
||||
|
||||
BinWrapper.prototype.runCheck = function (cmd, cb) {
|
||||
binCheck()(this.path(), cmd, function (err, works) {
|
||||
if (err) {
|
||||
cb(err);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!works) {
|
||||
cb(new Error('The `' + this.path() + '` binary doesn\'t seem to work correctly'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.version()) {
|
||||
return binVersionCheck()(this.path(), this.version(), cb);
|
||||
}
|
||||
|
||||
cb();
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
/**
|
||||
* Find existing files
|
||||
*
|
||||
* @param {Function} cb
|
||||
* @api private
|
||||
*/
|
||||
|
||||
BinWrapper.prototype.findExisting = function (cb) {
|
||||
fs.stat(this.path(), function (err) {
|
||||
if (err && err.code === 'ENOENT') {
|
||||
this.download(cb);
|
||||
return;
|
||||
}
|
||||
|
||||
if (err) {
|
||||
cb(err);
|
||||
return;
|
||||
}
|
||||
|
||||
cb();
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
/**
|
||||
* Download files
|
||||
*
|
||||
* @param {Function} cb
|
||||
* @api private
|
||||
*/
|
||||
|
||||
BinWrapper.prototype.download = function (cb) {
|
||||
var files = osFilterObj()(this.src());
|
||||
var download = new Download()({
|
||||
extract: true,
|
||||
mode: '755',
|
||||
strip: this.opts.strip
|
||||
});
|
||||
|
||||
if (!files.length) {
|
||||
cb(new Error('No binary found matching your system. It\'s probably not supported.'));
|
||||
return;
|
||||
}
|
||||
|
||||
files.forEach(function (file) {
|
||||
download.get(file.url);
|
||||
});
|
||||
|
||||
download
|
||||
.dest(this.dest())
|
||||
.run(cb);
|
||||
};
|
||||
|
||||
20
node_modules/bin-wrapper/license
generated
vendored
20
node_modules/bin-wrapper/license
generated
vendored
@@ -1,21 +1,9 @@
|
||||
The MIT License (MIT)
|
||||
MIT License
|
||||
|
||||
Copyright (c) Kevin Mårtensson <kevinmartensson@gmail.com>
|
||||
|
||||
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:
|
||||
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 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.
|
||||
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.
|
||||
|
||||
119
node_modules/bin-wrapper/node_modules/download/index.js
generated
vendored
Normal file
119
node_modules/bin-wrapper/node_modules/download/index.js
generated
vendored
Normal file
@@ -0,0 +1,119 @@
|
||||
'use strict';
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const url = require('url');
|
||||
const caw = require('caw');
|
||||
const contentDisposition = require('content-disposition');
|
||||
const archiveType = require('archive-type');
|
||||
const decompress = require('decompress');
|
||||
const filenamify = require('filenamify');
|
||||
const getStream = require('get-stream');
|
||||
const got = require('got');
|
||||
const makeDir = require('make-dir');
|
||||
const pify = require('pify');
|
||||
const pEvent = require('p-event');
|
||||
const fileType = require('file-type');
|
||||
const extName = require('ext-name');
|
||||
|
||||
const fsP = pify(fs);
|
||||
const filenameFromPath = res => path.basename(url.parse(res.requestUrl).pathname);
|
||||
|
||||
const getExtFromMime = res => {
|
||||
const header = res.headers['content-type'];
|
||||
|
||||
if (!header) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const exts = extName.mime(header);
|
||||
|
||||
if (exts.length !== 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return exts[0].ext;
|
||||
};
|
||||
|
||||
const getFilename = (res, data) => {
|
||||
const header = res.headers['content-disposition'];
|
||||
|
||||
if (header) {
|
||||
const parsed = contentDisposition.parse(header);
|
||||
|
||||
if (parsed.parameters && parsed.parameters.filename) {
|
||||
return parsed.parameters.filename;
|
||||
}
|
||||
}
|
||||
|
||||
let filename = filenameFromPath(res);
|
||||
|
||||
if (!path.extname(filename)) {
|
||||
const ext = (fileType(data) || {}).ext || getExtFromMime(res);
|
||||
|
||||
if (ext) {
|
||||
filename = `${filename}.${ext}`;
|
||||
}
|
||||
}
|
||||
|
||||
return filename;
|
||||
};
|
||||
|
||||
const getProtocolFromUri = uri => {
|
||||
let {protocol} = url.parse(uri);
|
||||
|
||||
if (protocol) {
|
||||
protocol = protocol.slice(0, -1);
|
||||
}
|
||||
|
||||
return protocol;
|
||||
};
|
||||
|
||||
module.exports = (uri, output, opts) => {
|
||||
if (typeof output === 'object') {
|
||||
opts = output;
|
||||
output = null;
|
||||
}
|
||||
|
||||
const protocol = getProtocolFromUri(uri);
|
||||
|
||||
opts = Object.assign({
|
||||
encoding: null,
|
||||
rejectUnauthorized: process.env.npm_config_strict_ssl !== 'false'
|
||||
}, opts);
|
||||
|
||||
const agent = caw(opts.proxy, {protocol});
|
||||
const stream = got.stream(uri, Object.assign({agent}, opts))
|
||||
.on('redirect', (response, nextOptions) => {
|
||||
const redirectProtocol = getProtocolFromUri(nextOptions.href);
|
||||
if (redirectProtocol && redirectProtocol !== protocol) {
|
||||
nextOptions.agent = caw(opts.proxy, {protocol: redirectProtocol});
|
||||
}
|
||||
});
|
||||
|
||||
const promise = pEvent(stream, 'response').then(res => {
|
||||
const encoding = opts.encoding === null ? 'buffer' : opts.encoding;
|
||||
return Promise.all([getStream(stream, {encoding}), res]);
|
||||
}).then(result => {
|
||||
const [data, res] = result;
|
||||
|
||||
if (!output) {
|
||||
return opts.extract && archiveType(data) ? decompress(data, opts) : data;
|
||||
}
|
||||
|
||||
const filename = opts.filename || filenamify(getFilename(res, data));
|
||||
const outputFilepath = path.join(output, filename);
|
||||
|
||||
if (opts.extract && archiveType(data)) {
|
||||
return decompress(data, path.dirname(outputFilepath), opts);
|
||||
}
|
||||
|
||||
return makeDir(path.dirname(outputFilepath))
|
||||
.then(() => fsP.writeFile(outputFilepath, data))
|
||||
.then(() => data);
|
||||
});
|
||||
|
||||
stream.then = promise.then.bind(promise);
|
||||
stream.catch = promise.catch.bind(promise);
|
||||
|
||||
return stream;
|
||||
};
|
||||
9
node_modules/bin-wrapper/node_modules/download/license
generated
vendored
Normal file
9
node_modules/bin-wrapper/node_modules/download/license
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) Kevin Mårtensson <kevinmartensson@gmail.com> (github.com/kevva)
|
||||
|
||||
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.
|
||||
84
node_modules/bin-wrapper/node_modules/download/node_modules/pify/index.js
generated
vendored
Normal file
84
node_modules/bin-wrapper/node_modules/download/node_modules/pify/index.js
generated
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
'use strict';
|
||||
|
||||
const processFn = (fn, opts) => function () {
|
||||
const P = opts.promiseModule;
|
||||
const args = new Array(arguments.length);
|
||||
|
||||
for (let i = 0; i < arguments.length; i++) {
|
||||
args[i] = arguments[i];
|
||||
}
|
||||
|
||||
return new P((resolve, reject) => {
|
||||
if (opts.errorFirst) {
|
||||
args.push(function (err, result) {
|
||||
if (opts.multiArgs) {
|
||||
const results = new Array(arguments.length - 1);
|
||||
|
||||
for (let i = 1; i < arguments.length; i++) {
|
||||
results[i - 1] = arguments[i];
|
||||
}
|
||||
|
||||
if (err) {
|
||||
results.unshift(err);
|
||||
reject(results);
|
||||
} else {
|
||||
resolve(results);
|
||||
}
|
||||
} else if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
resolve(result);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
args.push(function (result) {
|
||||
if (opts.multiArgs) {
|
||||
const results = new Array(arguments.length - 1);
|
||||
|
||||
for (let i = 0; i < arguments.length; i++) {
|
||||
results[i] = arguments[i];
|
||||
}
|
||||
|
||||
resolve(results);
|
||||
} else {
|
||||
resolve(result);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn.apply(this, args);
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = (obj, opts) => {
|
||||
opts = Object.assign({
|
||||
exclude: [/.+(Sync|Stream)$/],
|
||||
errorFirst: true,
|
||||
promiseModule: Promise
|
||||
}, opts);
|
||||
|
||||
const filter = key => {
|
||||
const match = pattern => typeof pattern === 'string' ? key === pattern : pattern.test(key);
|
||||
return opts.include ? opts.include.some(match) : !opts.exclude.some(match);
|
||||
};
|
||||
|
||||
let ret;
|
||||
if (typeof obj === 'function') {
|
||||
ret = function () {
|
||||
if (opts.excludeMain) {
|
||||
return obj.apply(this, arguments);
|
||||
}
|
||||
|
||||
return processFn(obj, opts).apply(this, arguments);
|
||||
};
|
||||
} else {
|
||||
ret = Object.create(Object.getPrototypeOf(obj));
|
||||
}
|
||||
|
||||
for (const key in obj) { // eslint-disable-line guard-for-in
|
||||
const x = obj[key];
|
||||
ret[key] = typeof x === 'function' && filter(key) ? processFn(x, opts) : x;
|
||||
}
|
||||
|
||||
return ret;
|
||||
};
|
||||
9
node_modules/bin-wrapper/node_modules/download/node_modules/pify/license
generated
vendored
Normal file
9
node_modules/bin-wrapper/node_modules/download/node_modules/pify/license
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
||||
|
||||
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.
|
||||
51
node_modules/bin-wrapper/node_modules/download/node_modules/pify/package.json
generated
vendored
Normal file
51
node_modules/bin-wrapper/node_modules/download/node_modules/pify/package.json
generated
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
{
|
||||
"name": "pify",
|
||||
"version": "3.0.0",
|
||||
"description": "Promisify a callback-style function",
|
||||
"license": "MIT",
|
||||
"repository": "sindresorhus/pify",
|
||||
"author": {
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
"url": "sindresorhus.com"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && ava && npm run optimization-test",
|
||||
"optimization-test": "node --allow-natives-syntax optimization-test.js"
|
||||
},
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"keywords": [
|
||||
"promise",
|
||||
"promises",
|
||||
"promisify",
|
||||
"all",
|
||||
"denodify",
|
||||
"denodeify",
|
||||
"callback",
|
||||
"cb",
|
||||
"node",
|
||||
"then",
|
||||
"thenify",
|
||||
"convert",
|
||||
"transform",
|
||||
"wrap",
|
||||
"wrapper",
|
||||
"bind",
|
||||
"to",
|
||||
"async",
|
||||
"await",
|
||||
"es2015",
|
||||
"bluebird"
|
||||
],
|
||||
"devDependencies": {
|
||||
"ava": "*",
|
||||
"pinkie-promise": "^2.0.0",
|
||||
"v8-natives": "^1.0.0",
|
||||
"xo": "*"
|
||||
}
|
||||
}
|
||||
131
node_modules/bin-wrapper/node_modules/download/node_modules/pify/readme.md
generated
vendored
Normal file
131
node_modules/bin-wrapper/node_modules/download/node_modules/pify/readme.md
generated
vendored
Normal file
@@ -0,0 +1,131 @@
|
||||
# pify [](https://travis-ci.org/sindresorhus/pify)
|
||||
|
||||
> Promisify a callback-style function
|
||||
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install --save pify
|
||||
```
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const fs = require('fs');
|
||||
const pify = require('pify');
|
||||
|
||||
// Promisify a single function
|
||||
pify(fs.readFile)('package.json', 'utf8').then(data => {
|
||||
console.log(JSON.parse(data).name);
|
||||
//=> 'pify'
|
||||
});
|
||||
|
||||
// Promisify all methods in a module
|
||||
pify(fs).readFile('package.json', 'utf8').then(data => {
|
||||
console.log(JSON.parse(data).name);
|
||||
//=> 'pify'
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
## API
|
||||
|
||||
### pify(input, [options])
|
||||
|
||||
Returns a `Promise` wrapped version of the supplied function or module.
|
||||
|
||||
#### input
|
||||
|
||||
Type: `Function` `Object`
|
||||
|
||||
Callback-style function or module whose methods you want to promisify.
|
||||
|
||||
#### options
|
||||
|
||||
##### multiArgs
|
||||
|
||||
Type: `boolean`<br>
|
||||
Default: `false`
|
||||
|
||||
By default, the promisified function will only return the second argument from the callback, which works fine for most APIs. This option can be useful for modules like `request` that return multiple arguments. Turning this on will make it return an array of all arguments from the callback, excluding the error argument, instead of just the second argument. This also applies to rejections, where it returns an array of all the callback arguments, including the error.
|
||||
|
||||
```js
|
||||
const request = require('request');
|
||||
const pify = require('pify');
|
||||
|
||||
pify(request, {multiArgs: true})('https://sindresorhus.com').then(result => {
|
||||
const [httpResponse, body] = result;
|
||||
});
|
||||
```
|
||||
|
||||
##### include
|
||||
|
||||
Type: `string[]` `RegExp[]`
|
||||
|
||||
Methods in a module to promisify. Remaining methods will be left untouched.
|
||||
|
||||
##### exclude
|
||||
|
||||
Type: `string[]` `RegExp[]`<br>
|
||||
Default: `[/.+(Sync|Stream)$/]`
|
||||
|
||||
Methods in a module **not** to promisify. Methods with names ending with `'Sync'` are excluded by default.
|
||||
|
||||
##### excludeMain
|
||||
|
||||
Type: `boolean`<br>
|
||||
Default: `false`
|
||||
|
||||
If given module is a function itself, it will be promisified. Turn this option on if you want to promisify only methods of the module.
|
||||
|
||||
```js
|
||||
const pify = require('pify');
|
||||
|
||||
function fn() {
|
||||
return true;
|
||||
}
|
||||
|
||||
fn.method = (data, callback) => {
|
||||
setImmediate(() => {
|
||||
callback(null, data);
|
||||
});
|
||||
};
|
||||
|
||||
// Promisify methods but not `fn()`
|
||||
const promiseFn = pify(fn, {excludeMain: true});
|
||||
|
||||
if (promiseFn()) {
|
||||
promiseFn.method('hi').then(data => {
|
||||
console.log(data);
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
##### errorFirst
|
||||
|
||||
Type: `boolean`<br>
|
||||
Default: `true`
|
||||
|
||||
Whether the callback has an error as the first argument. You'll want to set this to `false` if you're dealing with an API that doesn't have an error as the first argument, like `fs.exists()`, some browser APIs, Chrome Extension APIs, etc.
|
||||
|
||||
##### promiseModule
|
||||
|
||||
Type: `Function`
|
||||
|
||||
Custom promise module to use instead of the native one.
|
||||
|
||||
Check out [`pinkie-promise`](https://github.com/floatdrop/pinkie-promise) if you need a tiny promise polyfill.
|
||||
|
||||
|
||||
## Related
|
||||
|
||||
- [p-event](https://github.com/sindresorhus/p-event) - Promisify an event by waiting for it to be emitted
|
||||
- [p-map](https://github.com/sindresorhus/p-map) - Map over promises concurrently
|
||||
- [More…](https://github.com/sindresorhus/promise-fun)
|
||||
|
||||
|
||||
## License
|
||||
|
||||
MIT © [Sindre Sorhus](https://sindresorhus.com)
|
||||
51
node_modules/bin-wrapper/node_modules/download/package.json
generated
vendored
Normal file
51
node_modules/bin-wrapper/node_modules/download/package.json
generated
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
{
|
||||
"name": "download",
|
||||
"version": "7.1.0",
|
||||
"description": "Download and extract files",
|
||||
"license": "MIT",
|
||||
"repository": "kevva/download",
|
||||
"author": {
|
||||
"email": "kevinmartensson@gmail.com",
|
||||
"name": "Kevin Mårtensson",
|
||||
"url": "github.com/kevva"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && ava"
|
||||
},
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"keywords": [
|
||||
"download",
|
||||
"extract",
|
||||
"http",
|
||||
"request",
|
||||
"url"
|
||||
],
|
||||
"dependencies": {
|
||||
"archive-type": "^4.0.0",
|
||||
"caw": "^2.0.1",
|
||||
"content-disposition": "^0.5.2",
|
||||
"decompress": "^4.2.0",
|
||||
"ext-name": "^5.0.0",
|
||||
"file-type": "^8.1.0",
|
||||
"filenamify": "^2.0.0",
|
||||
"get-stream": "^3.0.0",
|
||||
"got": "^8.3.1",
|
||||
"make-dir": "^1.2.0",
|
||||
"p-event": "^2.1.0",
|
||||
"pify": "^3.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"ava": "*",
|
||||
"is-zip": "^1.0.0",
|
||||
"nock": "^9.2.5",
|
||||
"path-exists": "^3.0.0",
|
||||
"random-buffer": "^0.1.0",
|
||||
"rimraf": "^2.6.2",
|
||||
"xo": "*"
|
||||
}
|
||||
}
|
||||
86
node_modules/bin-wrapper/node_modules/download/readme.md
generated
vendored
Normal file
86
node_modules/bin-wrapper/node_modules/download/readme.md
generated
vendored
Normal file
@@ -0,0 +1,86 @@
|
||||
# download [](https://travis-ci.org/kevva/download)
|
||||
|
||||
> Download and extract files
|
||||
|
||||
*See [download-cli](https://github.com/kevva/download-cli) for the command-line version.*
|
||||
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install download
|
||||
```
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const fs = require('fs');
|
||||
const download = require('download');
|
||||
|
||||
download('http://unicorn.com/foo.jpg', 'dist').then(() => {
|
||||
console.log('done!');
|
||||
});
|
||||
|
||||
download('http://unicorn.com/foo.jpg').then(data => {
|
||||
fs.writeFileSync('dist/foo.jpg', data);
|
||||
});
|
||||
|
||||
download('unicorn.com/foo.jpg').pipe(fs.createWriteStream('dist/foo.jpg'));
|
||||
|
||||
Promise.all([
|
||||
'unicorn.com/foo.jpg',
|
||||
'cats.com/dancing.gif'
|
||||
].map(x => download(x, 'dist'))).then(() => {
|
||||
console.log('files downloaded!');
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
## API
|
||||
|
||||
### download(url, [destination], [options])
|
||||
|
||||
Returns both a `Promise<Buffer>` and a [Duplex stream](https://nodejs.org/api/stream.html#stream_class_stream_duplex) with [additional events](https://github.com/sindresorhus/got#streams-1).
|
||||
|
||||
#### url
|
||||
|
||||
Type: `string`
|
||||
|
||||
URL to download.
|
||||
|
||||
#### destination
|
||||
|
||||
Type: `string`
|
||||
|
||||
Path to where your file will be written.
|
||||
|
||||
#### options
|
||||
|
||||
Type: `Object`
|
||||
|
||||
Same options as [`got`](https://github.com/sindresorhus/got#options) and [`decompress`](https://github.com/kevva/decompress#options) in addition to the ones below.
|
||||
|
||||
##### extract
|
||||
|
||||
Type: `boolean`<br>
|
||||
Default: `false`
|
||||
|
||||
If set to `true`, try extracting the file using [`decompress`](https://github.com/kevva/decompress).
|
||||
|
||||
##### filename
|
||||
|
||||
Type: `string`
|
||||
|
||||
Name of the saved file.
|
||||
|
||||
##### proxy
|
||||
|
||||
Type: `string`
|
||||
|
||||
Proxy endpoint.
|
||||
|
||||
|
||||
## License
|
||||
|
||||
MIT © [Kevin Mårtensson](https://github.com/kevva)
|
||||
809
node_modules/bin-wrapper/node_modules/file-type/index.js
generated
vendored
Normal file
809
node_modules/bin-wrapper/node_modules/file-type/index.js
generated
vendored
Normal file
@@ -0,0 +1,809 @@
|
||||
'use strict';
|
||||
const toBytes = s => [...s].map(c => c.charCodeAt(0));
|
||||
const xpiZipFilename = toBytes('META-INF/mozilla.rsa');
|
||||
const oxmlContentTypes = toBytes('[Content_Types].xml');
|
||||
const oxmlRels = toBytes('_rels/.rels');
|
||||
|
||||
module.exports = input => {
|
||||
const buf = input instanceof Uint8Array ? input : new Uint8Array(input);
|
||||
|
||||
if (!(buf && buf.length > 1)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const check = (header, options) => {
|
||||
options = Object.assign({
|
||||
offset: 0
|
||||
}, options);
|
||||
|
||||
for (let i = 0; i < header.length; i++) {
|
||||
// If a bitmask is set
|
||||
if (options.mask) {
|
||||
// If header doesn't equal `buf` with bits masked off
|
||||
if (header[i] !== (options.mask[i] & buf[i + options.offset])) {
|
||||
return false;
|
||||
}
|
||||
} else if (header[i] !== buf[i + options.offset]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
const checkString = (header, options) => check(toBytes(header), options);
|
||||
|
||||
if (check([0xFF, 0xD8, 0xFF])) {
|
||||
return {
|
||||
ext: 'jpg',
|
||||
mime: 'image/jpeg'
|
||||
};
|
||||
}
|
||||
|
||||
if (check([0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A])) {
|
||||
return {
|
||||
ext: 'png',
|
||||
mime: 'image/png'
|
||||
};
|
||||
}
|
||||
|
||||
if (check([0x47, 0x49, 0x46])) {
|
||||
return {
|
||||
ext: 'gif',
|
||||
mime: 'image/gif'
|
||||
};
|
||||
}
|
||||
|
||||
if (check([0x57, 0x45, 0x42, 0x50], {offset: 8})) {
|
||||
return {
|
||||
ext: 'webp',
|
||||
mime: 'image/webp'
|
||||
};
|
||||
}
|
||||
|
||||
if (check([0x46, 0x4C, 0x49, 0x46])) {
|
||||
return {
|
||||
ext: 'flif',
|
||||
mime: 'image/flif'
|
||||
};
|
||||
}
|
||||
|
||||
// Needs to be before `tif` check
|
||||
if (
|
||||
(check([0x49, 0x49, 0x2A, 0x0]) || check([0x4D, 0x4D, 0x0, 0x2A])) &&
|
||||
check([0x43, 0x52], {offset: 8})
|
||||
) {
|
||||
return {
|
||||
ext: 'cr2',
|
||||
mime: 'image/x-canon-cr2'
|
||||
};
|
||||
}
|
||||
|
||||
if (
|
||||
check([0x49, 0x49, 0x2A, 0x0]) ||
|
||||
check([0x4D, 0x4D, 0x0, 0x2A])
|
||||
) {
|
||||
return {
|
||||
ext: 'tif',
|
||||
mime: 'image/tiff'
|
||||
};
|
||||
}
|
||||
|
||||
if (check([0x42, 0x4D])) {
|
||||
return {
|
||||
ext: 'bmp',
|
||||
mime: 'image/bmp'
|
||||
};
|
||||
}
|
||||
|
||||
if (check([0x49, 0x49, 0xBC])) {
|
||||
return {
|
||||
ext: 'jxr',
|
||||
mime: 'image/vnd.ms-photo'
|
||||
};
|
||||
}
|
||||
|
||||
if (check([0x38, 0x42, 0x50, 0x53])) {
|
||||
return {
|
||||
ext: 'psd',
|
||||
mime: 'image/vnd.adobe.photoshop'
|
||||
};
|
||||
}
|
||||
|
||||
// Zip-based file formats
|
||||
// Need to be before the `zip` check
|
||||
if (check([0x50, 0x4B, 0x3, 0x4])) {
|
||||
if (
|
||||
check([0x6D, 0x69, 0x6D, 0x65, 0x74, 0x79, 0x70, 0x65, 0x61, 0x70, 0x70, 0x6C, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6F, 0x6E, 0x2F, 0x65, 0x70, 0x75, 0x62, 0x2B, 0x7A, 0x69, 0x70], {offset: 30})
|
||||
) {
|
||||
return {
|
||||
ext: 'epub',
|
||||
mime: 'application/epub+zip'
|
||||
};
|
||||
}
|
||||
|
||||
// Assumes signed `.xpi` from addons.mozilla.org
|
||||
if (check(xpiZipFilename, {offset: 30})) {
|
||||
return {
|
||||
ext: 'xpi',
|
||||
mime: 'application/x-xpinstall'
|
||||
};
|
||||
}
|
||||
|
||||
if (checkString('mimetypeapplication/vnd.oasis.opendocument.text', {offset: 30})) {
|
||||
return {
|
||||
ext: 'odt',
|
||||
mime: 'application/vnd.oasis.opendocument.text'
|
||||
};
|
||||
}
|
||||
|
||||
if (checkString('mimetypeapplication/vnd.oasis.opendocument.spreadsheet', {offset: 30})) {
|
||||
return {
|
||||
ext: 'ods',
|
||||
mime: 'application/vnd.oasis.opendocument.spreadsheet'
|
||||
};
|
||||
}
|
||||
|
||||
if (checkString('mimetypeapplication/vnd.oasis.opendocument.presentation', {offset: 30})) {
|
||||
return {
|
||||
ext: 'odp',
|
||||
mime: 'application/vnd.oasis.opendocument.presentation'
|
||||
};
|
||||
}
|
||||
|
||||
// https://github.com/file/file/blob/master/magic/Magdir/msooxml
|
||||
if (check(oxmlContentTypes, {offset: 30}) || check(oxmlRels, {offset: 30})) {
|
||||
const sliced = buf.subarray(4, 4 + 2000);
|
||||
const nextZipHeaderIndex = arr => arr.findIndex((el, i, arr) => arr[i] === 0x50 && arr[i + 1] === 0x4B && arr[i + 2] === 0x3 && arr[i + 3] === 0x4);
|
||||
const header2Pos = nextZipHeaderIndex(sliced);
|
||||
|
||||
if (header2Pos !== -1) {
|
||||
const slicedAgain = buf.subarray(header2Pos + 8, header2Pos + 8 + 1000);
|
||||
const header3Pos = nextZipHeaderIndex(slicedAgain);
|
||||
|
||||
if (header3Pos !== -1) {
|
||||
const offset = 8 + header2Pos + header3Pos + 30;
|
||||
|
||||
if (checkString('word/', {offset})) {
|
||||
return {
|
||||
ext: 'docx',
|
||||
mime: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
|
||||
};
|
||||
}
|
||||
|
||||
if (checkString('ppt/', {offset})) {
|
||||
return {
|
||||
ext: 'pptx',
|
||||
mime: 'application/vnd.openxmlformats-officedocument.presentationml.presentation'
|
||||
};
|
||||
}
|
||||
|
||||
if (checkString('xl/', {offset})) {
|
||||
return {
|
||||
ext: 'xlsx',
|
||||
mime: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
check([0x50, 0x4B]) &&
|
||||
(buf[2] === 0x3 || buf[2] === 0x5 || buf[2] === 0x7) &&
|
||||
(buf[3] === 0x4 || buf[3] === 0x6 || buf[3] === 0x8)
|
||||
) {
|
||||
return {
|
||||
ext: 'zip',
|
||||
mime: 'application/zip'
|
||||
};
|
||||
}
|
||||
|
||||
if (check([0x75, 0x73, 0x74, 0x61, 0x72], {offset: 257})) {
|
||||
return {
|
||||
ext: 'tar',
|
||||
mime: 'application/x-tar'
|
||||
};
|
||||
}
|
||||
|
||||
if (
|
||||
check([0x52, 0x61, 0x72, 0x21, 0x1A, 0x7]) &&
|
||||
(buf[6] === 0x0 || buf[6] === 0x1)
|
||||
) {
|
||||
return {
|
||||
ext: 'rar',
|
||||
mime: 'application/x-rar-compressed'
|
||||
};
|
||||
}
|
||||
|
||||
if (check([0x1F, 0x8B, 0x8])) {
|
||||
return {
|
||||
ext: 'gz',
|
||||
mime: 'application/gzip'
|
||||
};
|
||||
}
|
||||
|
||||
if (check([0x42, 0x5A, 0x68])) {
|
||||
return {
|
||||
ext: 'bz2',
|
||||
mime: 'application/x-bzip2'
|
||||
};
|
||||
}
|
||||
|
||||
if (check([0x37, 0x7A, 0xBC, 0xAF, 0x27, 0x1C])) {
|
||||
return {
|
||||
ext: '7z',
|
||||
mime: 'application/x-7z-compressed'
|
||||
};
|
||||
}
|
||||
|
||||
if (check([0x78, 0x01])) {
|
||||
return {
|
||||
ext: 'dmg',
|
||||
mime: 'application/x-apple-diskimage'
|
||||
};
|
||||
}
|
||||
|
||||
if (check([0x33, 0x67, 0x70, 0x35]) || // 3gp5
|
||||
(
|
||||
check([0x0, 0x0, 0x0]) && check([0x66, 0x74, 0x79, 0x70], {offset: 4}) &&
|
||||
(
|
||||
check([0x6D, 0x70, 0x34, 0x31], {offset: 8}) || // MP41
|
||||
check([0x6D, 0x70, 0x34, 0x32], {offset: 8}) || // MP42
|
||||
check([0x69, 0x73, 0x6F, 0x6D], {offset: 8}) || // ISOM
|
||||
check([0x69, 0x73, 0x6F, 0x32], {offset: 8}) || // ISO2
|
||||
check([0x6D, 0x6D, 0x70, 0x34], {offset: 8}) || // MMP4
|
||||
check([0x4D, 0x34, 0x56], {offset: 8}) || // M4V
|
||||
check([0x64, 0x61, 0x73, 0x68], {offset: 8}) // DASH
|
||||
)
|
||||
)) {
|
||||
return {
|
||||
ext: 'mp4',
|
||||
mime: 'video/mp4'
|
||||
};
|
||||
}
|
||||
|
||||
if (check([0x4D, 0x54, 0x68, 0x64])) {
|
||||
return {
|
||||
ext: 'mid',
|
||||
mime: 'audio/midi'
|
||||
};
|
||||
}
|
||||
|
||||
// https://github.com/threatstack/libmagic/blob/master/magic/Magdir/matroska
|
||||
if (check([0x1A, 0x45, 0xDF, 0xA3])) {
|
||||
const sliced = buf.subarray(4, 4 + 4096);
|
||||
const idPos = sliced.findIndex((el, i, arr) => arr[i] === 0x42 && arr[i + 1] === 0x82);
|
||||
|
||||
if (idPos !== -1) {
|
||||
const docTypePos = idPos + 3;
|
||||
const findDocType = type => [...type].every((c, i) => sliced[docTypePos + i] === c.charCodeAt(0));
|
||||
|
||||
if (findDocType('matroska')) {
|
||||
return {
|
||||
ext: 'mkv',
|
||||
mime: 'video/x-matroska'
|
||||
};
|
||||
}
|
||||
|
||||
if (findDocType('webm')) {
|
||||
return {
|
||||
ext: 'webm',
|
||||
mime: 'video/webm'
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (check([0x0, 0x0, 0x0, 0x14, 0x66, 0x74, 0x79, 0x70, 0x71, 0x74, 0x20, 0x20]) ||
|
||||
check([0x66, 0x72, 0x65, 0x65], {offset: 4}) ||
|
||||
check([0x66, 0x74, 0x79, 0x70, 0x71, 0x74, 0x20, 0x20], {offset: 4}) ||
|
||||
check([0x6D, 0x64, 0x61, 0x74], {offset: 4}) || // MJPEG
|
||||
check([0x77, 0x69, 0x64, 0x65], {offset: 4})) {
|
||||
return {
|
||||
ext: 'mov',
|
||||
mime: 'video/quicktime'
|
||||
};
|
||||
}
|
||||
|
||||
// RIFF file format which might be AVI, WAV, QCP, etc
|
||||
if (check([0x52, 0x49, 0x46, 0x46])) {
|
||||
if (check([0x41, 0x56, 0x49], {offset: 8})) {
|
||||
return {
|
||||
ext: 'avi',
|
||||
mime: 'video/x-msvideo'
|
||||
};
|
||||
}
|
||||
if (check([0x57, 0x41, 0x56, 0x45], {offset: 8})) {
|
||||
return {
|
||||
ext: 'wav',
|
||||
mime: 'audio/x-wav'
|
||||
};
|
||||
}
|
||||
// QLCM, QCP file
|
||||
if (check([0x51, 0x4C, 0x43, 0x4D], {offset: 8})) {
|
||||
return {
|
||||
ext: 'qcp',
|
||||
mime: 'audio/qcelp'
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (check([0x30, 0x26, 0xB2, 0x75, 0x8E, 0x66, 0xCF, 0x11, 0xA6, 0xD9])) {
|
||||
return {
|
||||
ext: 'wmv',
|
||||
mime: 'video/x-ms-wmv'
|
||||
};
|
||||
}
|
||||
|
||||
if (
|
||||
check([0x0, 0x0, 0x1, 0xBA]) ||
|
||||
check([0x0, 0x0, 0x1, 0xB3])
|
||||
) {
|
||||
return {
|
||||
ext: 'mpg',
|
||||
mime: 'video/mpeg'
|
||||
};
|
||||
}
|
||||
|
||||
if (check([0x66, 0x74, 0x79, 0x70, 0x33, 0x67], {offset: 4})) {
|
||||
return {
|
||||
ext: '3gp',
|
||||
mime: 'video/3gpp'
|
||||
};
|
||||
}
|
||||
|
||||
// Check for MPEG header at different starting offsets
|
||||
for (let start = 0; start < 2 && start < (buf.length - 16); start++) {
|
||||
if (
|
||||
check([0x49, 0x44, 0x33], {offset: start}) || // ID3 header
|
||||
check([0xFF, 0xE2], {offset: start, mask: [0xFF, 0xE2]}) // MPEG 1 or 2 Layer 3 header
|
||||
) {
|
||||
return {
|
||||
ext: 'mp3',
|
||||
mime: 'audio/mpeg'
|
||||
};
|
||||
}
|
||||
|
||||
if (
|
||||
check([0xFF, 0xE4], {offset: start, mask: [0xFF, 0xE4]}) // MPEG 1 or 2 Layer 2 header
|
||||
) {
|
||||
return {
|
||||
ext: 'mp2',
|
||||
mime: 'audio/mpeg'
|
||||
};
|
||||
}
|
||||
|
||||
if (
|
||||
check([0xFF, 0xF8], {offset: start, mask: [0xFF, 0xFC]}) // MPEG 2 layer 0 using ADTS
|
||||
) {
|
||||
return {
|
||||
ext: 'mp2',
|
||||
mime: 'audio/mpeg'
|
||||
};
|
||||
}
|
||||
|
||||
if (
|
||||
check([0xFF, 0xF0], {offset: start, mask: [0xFF, 0xFC]}) // MPEG 4 layer 0 using ADTS
|
||||
) {
|
||||
return {
|
||||
ext: 'mp4',
|
||||
mime: 'audio/mpeg'
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
check([0x66, 0x74, 0x79, 0x70, 0x4D, 0x34, 0x41], {offset: 4}) ||
|
||||
check([0x4D, 0x34, 0x41, 0x20])
|
||||
) {
|
||||
return {
|
||||
ext: 'm4a',
|
||||
mime: 'audio/m4a'
|
||||
};
|
||||
}
|
||||
|
||||
// Needs to be before `ogg` check
|
||||
if (check([0x4F, 0x70, 0x75, 0x73, 0x48, 0x65, 0x61, 0x64], {offset: 28})) {
|
||||
return {
|
||||
ext: 'opus',
|
||||
mime: 'audio/opus'
|
||||
};
|
||||
}
|
||||
|
||||
// If 'OggS' in first bytes, then OGG container
|
||||
if (check([0x4F, 0x67, 0x67, 0x53])) {
|
||||
// This is a OGG container
|
||||
|
||||
// If ' theora' in header.
|
||||
if (check([0x80, 0x74, 0x68, 0x65, 0x6F, 0x72, 0x61], {offset: 28})) {
|
||||
return {
|
||||
ext: 'ogv',
|
||||
mime: 'video/ogg'
|
||||
};
|
||||
}
|
||||
// If '\x01video' in header.
|
||||
if (check([0x01, 0x76, 0x69, 0x64, 0x65, 0x6F, 0x00], {offset: 28})) {
|
||||
return {
|
||||
ext: 'ogm',
|
||||
mime: 'video/ogg'
|
||||
};
|
||||
}
|
||||
// If ' FLAC' in header https://xiph.org/flac/faq.html
|
||||
if (check([0x7F, 0x46, 0x4C, 0x41, 0x43], {offset: 28})) {
|
||||
return {
|
||||
ext: 'oga',
|
||||
mime: 'audio/ogg'
|
||||
};
|
||||
}
|
||||
|
||||
// 'Speex ' in header https://en.wikipedia.org/wiki/Speex
|
||||
if (check([0x53, 0x70, 0x65, 0x65, 0x78, 0x20, 0x20], {offset: 28})) {
|
||||
return {
|
||||
ext: 'spx',
|
||||
mime: 'audio/ogg'
|
||||
};
|
||||
}
|
||||
|
||||
// If '\x01vorbis' in header
|
||||
if (check([0x01, 0x76, 0x6F, 0x72, 0x62, 0x69, 0x73], {offset: 28})) {
|
||||
return {
|
||||
ext: 'ogg',
|
||||
mime: 'audio/ogg'
|
||||
};
|
||||
}
|
||||
|
||||
// Default OGG container https://www.iana.org/assignments/media-types/application/ogg
|
||||
return {
|
||||
ext: 'ogx',
|
||||
mime: 'application/ogg'
|
||||
};
|
||||
}
|
||||
|
||||
if (check([0x66, 0x4C, 0x61, 0x43])) {
|
||||
return {
|
||||
ext: 'flac',
|
||||
mime: 'audio/x-flac'
|
||||
};
|
||||
}
|
||||
|
||||
if (check([0x4D, 0x41, 0x43, 0x20])) {
|
||||
return {
|
||||
ext: 'ape',
|
||||
mime: 'audio/ape'
|
||||
};
|
||||
}
|
||||
|
||||
if (check([0x23, 0x21, 0x41, 0x4D, 0x52, 0x0A])) {
|
||||
return {
|
||||
ext: 'amr',
|
||||
mime: 'audio/amr'
|
||||
};
|
||||
}
|
||||
|
||||
if (check([0x25, 0x50, 0x44, 0x46])) {
|
||||
return {
|
||||
ext: 'pdf',
|
||||
mime: 'application/pdf'
|
||||
};
|
||||
}
|
||||
|
||||
if (check([0x4D, 0x5A])) {
|
||||
return {
|
||||
ext: 'exe',
|
||||
mime: 'application/x-msdownload'
|
||||
};
|
||||
}
|
||||
|
||||
if (
|
||||
(buf[0] === 0x43 || buf[0] === 0x46) &&
|
||||
check([0x57, 0x53], {offset: 1})
|
||||
) {
|
||||
return {
|
||||
ext: 'swf',
|
||||
mime: 'application/x-shockwave-flash'
|
||||
};
|
||||
}
|
||||
|
||||
if (check([0x7B, 0x5C, 0x72, 0x74, 0x66])) {
|
||||
return {
|
||||
ext: 'rtf',
|
||||
mime: 'application/rtf'
|
||||
};
|
||||
}
|
||||
|
||||
if (check([0x00, 0x61, 0x73, 0x6D])) {
|
||||
return {
|
||||
ext: 'wasm',
|
||||
mime: 'application/wasm'
|
||||
};
|
||||
}
|
||||
|
||||
if (
|
||||
check([0x77, 0x4F, 0x46, 0x46]) &&
|
||||
(
|
||||
check([0x00, 0x01, 0x00, 0x00], {offset: 4}) ||
|
||||
check([0x4F, 0x54, 0x54, 0x4F], {offset: 4})
|
||||
)
|
||||
) {
|
||||
return {
|
||||
ext: 'woff',
|
||||
mime: 'font/woff'
|
||||
};
|
||||
}
|
||||
|
||||
if (
|
||||
check([0x77, 0x4F, 0x46, 0x32]) &&
|
||||
(
|
||||
check([0x00, 0x01, 0x00, 0x00], {offset: 4}) ||
|
||||
check([0x4F, 0x54, 0x54, 0x4F], {offset: 4})
|
||||
)
|
||||
) {
|
||||
return {
|
||||
ext: 'woff2',
|
||||
mime: 'font/woff2'
|
||||
};
|
||||
}
|
||||
|
||||
if (
|
||||
check([0x4C, 0x50], {offset: 34}) &&
|
||||
(
|
||||
check([0x00, 0x00, 0x01], {offset: 8}) ||
|
||||
check([0x01, 0x00, 0x02], {offset: 8}) ||
|
||||
check([0x02, 0x00, 0x02], {offset: 8})
|
||||
)
|
||||
) {
|
||||
return {
|
||||
ext: 'eot',
|
||||
mime: 'application/octet-stream'
|
||||
};
|
||||
}
|
||||
|
||||
if (check([0x00, 0x01, 0x00, 0x00, 0x00])) {
|
||||
return {
|
||||
ext: 'ttf',
|
||||
mime: 'font/ttf'
|
||||
};
|
||||
}
|
||||
|
||||
if (check([0x4F, 0x54, 0x54, 0x4F, 0x00])) {
|
||||
return {
|
||||
ext: 'otf',
|
||||
mime: 'font/otf'
|
||||
};
|
||||
}
|
||||
|
||||
if (check([0x00, 0x00, 0x01, 0x00])) {
|
||||
return {
|
||||
ext: 'ico',
|
||||
mime: 'image/x-icon'
|
||||
};
|
||||
}
|
||||
|
||||
if (check([0x00, 0x00, 0x02, 0x00])) {
|
||||
return {
|
||||
ext: 'cur',
|
||||
mime: 'image/x-icon'
|
||||
};
|
||||
}
|
||||
|
||||
if (check([0x46, 0x4C, 0x56, 0x01])) {
|
||||
return {
|
||||
ext: 'flv',
|
||||
mime: 'video/x-flv'
|
||||
};
|
||||
}
|
||||
|
||||
if (check([0x25, 0x21])) {
|
||||
return {
|
||||
ext: 'ps',
|
||||
mime: 'application/postscript'
|
||||
};
|
||||
}
|
||||
|
||||
if (check([0xFD, 0x37, 0x7A, 0x58, 0x5A, 0x00])) {
|
||||
return {
|
||||
ext: 'xz',
|
||||
mime: 'application/x-xz'
|
||||
};
|
||||
}
|
||||
|
||||
if (check([0x53, 0x51, 0x4C, 0x69])) {
|
||||
return {
|
||||
ext: 'sqlite',
|
||||
mime: 'application/x-sqlite3'
|
||||
};
|
||||
}
|
||||
|
||||
if (check([0x4E, 0x45, 0x53, 0x1A])) {
|
||||
return {
|
||||
ext: 'nes',
|
||||
mime: 'application/x-nintendo-nes-rom'
|
||||
};
|
||||
}
|
||||
|
||||
if (check([0x43, 0x72, 0x32, 0x34])) {
|
||||
return {
|
||||
ext: 'crx',
|
||||
mime: 'application/x-google-chrome-extension'
|
||||
};
|
||||
}
|
||||
|
||||
if (
|
||||
check([0x4D, 0x53, 0x43, 0x46]) ||
|
||||
check([0x49, 0x53, 0x63, 0x28])
|
||||
) {
|
||||
return {
|
||||
ext: 'cab',
|
||||
mime: 'application/vnd.ms-cab-compressed'
|
||||
};
|
||||
}
|
||||
|
||||
// Needs to be before `ar` check
|
||||
if (check([0x21, 0x3C, 0x61, 0x72, 0x63, 0x68, 0x3E, 0x0A, 0x64, 0x65, 0x62, 0x69, 0x61, 0x6E, 0x2D, 0x62, 0x69, 0x6E, 0x61, 0x72, 0x79])) {
|
||||
return {
|
||||
ext: 'deb',
|
||||
mime: 'application/x-deb'
|
||||
};
|
||||
}
|
||||
|
||||
if (check([0x21, 0x3C, 0x61, 0x72, 0x63, 0x68, 0x3E])) {
|
||||
return {
|
||||
ext: 'ar',
|
||||
mime: 'application/x-unix-archive'
|
||||
};
|
||||
}
|
||||
|
||||
if (check([0xED, 0xAB, 0xEE, 0xDB])) {
|
||||
return {
|
||||
ext: 'rpm',
|
||||
mime: 'application/x-rpm'
|
||||
};
|
||||
}
|
||||
|
||||
if (
|
||||
check([0x1F, 0xA0]) ||
|
||||
check([0x1F, 0x9D])
|
||||
) {
|
||||
return {
|
||||
ext: 'Z',
|
||||
mime: 'application/x-compress'
|
||||
};
|
||||
}
|
||||
|
||||
if (check([0x4C, 0x5A, 0x49, 0x50])) {
|
||||
return {
|
||||
ext: 'lz',
|
||||
mime: 'application/x-lzip'
|
||||
};
|
||||
}
|
||||
|
||||
if (check([0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1])) {
|
||||
return {
|
||||
ext: 'msi',
|
||||
mime: 'application/x-msi'
|
||||
};
|
||||
}
|
||||
|
||||
if (check([0x06, 0x0E, 0x2B, 0x34, 0x02, 0x05, 0x01, 0x01, 0x0D, 0x01, 0x02, 0x01, 0x01, 0x02])) {
|
||||
return {
|
||||
ext: 'mxf',
|
||||
mime: 'application/mxf'
|
||||
};
|
||||
}
|
||||
|
||||
if (check([0x47], {offset: 4}) && (check([0x47], {offset: 192}) || check([0x47], {offset: 196}))) {
|
||||
return {
|
||||
ext: 'mts',
|
||||
mime: 'video/mp2t'
|
||||
};
|
||||
}
|
||||
|
||||
if (check([0x42, 0x4C, 0x45, 0x4E, 0x44, 0x45, 0x52])) {
|
||||
return {
|
||||
ext: 'blend',
|
||||
mime: 'application/x-blender'
|
||||
};
|
||||
}
|
||||
|
||||
if (check([0x42, 0x50, 0x47, 0xFB])) {
|
||||
return {
|
||||
ext: 'bpg',
|
||||
mime: 'image/bpg'
|
||||
};
|
||||
}
|
||||
|
||||
if (check([0x00, 0x00, 0x00, 0x0C, 0x6A, 0x50, 0x20, 0x20, 0x0D, 0x0A, 0x87, 0x0A])) {
|
||||
// JPEG-2000 family
|
||||
|
||||
if (check([0x6A, 0x70, 0x32, 0x20], {offset: 20})) {
|
||||
return {
|
||||
ext: 'jp2',
|
||||
mime: 'image/jp2'
|
||||
};
|
||||
}
|
||||
|
||||
if (check([0x6A, 0x70, 0x78, 0x20], {offset: 20})) {
|
||||
return {
|
||||
ext: 'jpx',
|
||||
mime: 'image/jpx'
|
||||
};
|
||||
}
|
||||
|
||||
if (check([0x6A, 0x70, 0x6D, 0x20], {offset: 20})) {
|
||||
return {
|
||||
ext: 'jpm',
|
||||
mime: 'image/jpm'
|
||||
};
|
||||
}
|
||||
|
||||
if (check([0x6D, 0x6A, 0x70, 0x32], {offset: 20})) {
|
||||
return {
|
||||
ext: 'mj2',
|
||||
mime: 'image/mj2'
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (check([0x46, 0x4F, 0x52, 0x4D, 0x00])) {
|
||||
return {
|
||||
ext: 'aif',
|
||||
mime: 'audio/aiff'
|
||||
};
|
||||
}
|
||||
|
||||
if (checkString('<?xml ')) {
|
||||
return {
|
||||
ext: 'xml',
|
||||
mime: 'application/xml'
|
||||
};
|
||||
}
|
||||
|
||||
if (check([0x42, 0x4F, 0x4F, 0x4B, 0x4D, 0x4F, 0x42, 0x49], {offset: 60})) {
|
||||
return {
|
||||
ext: 'mobi',
|
||||
mime: 'application/x-mobipocket-ebook'
|
||||
};
|
||||
}
|
||||
|
||||
// File Type Box (https://en.wikipedia.org/wiki/ISO_base_media_file_format)
|
||||
if (check([0x66, 0x74, 0x79, 0x70], {offset: 4})) {
|
||||
if (check([0x6D, 0x69, 0x66, 0x31], {offset: 8})) {
|
||||
return {
|
||||
ext: 'heic',
|
||||
mime: 'image/heif'
|
||||
};
|
||||
}
|
||||
|
||||
if (check([0x6D, 0x73, 0x66, 0x31], {offset: 8})) {
|
||||
return {
|
||||
ext: 'heic',
|
||||
mime: 'image/heif-sequence'
|
||||
};
|
||||
}
|
||||
|
||||
if (check([0x68, 0x65, 0x69, 0x63], {offset: 8}) || check([0x68, 0x65, 0x69, 0x78], {offset: 8})) {
|
||||
return {
|
||||
ext: 'heic',
|
||||
mime: 'image/heic'
|
||||
};
|
||||
}
|
||||
|
||||
if (check([0x68, 0x65, 0x76, 0x63], {offset: 8}) || check([0x68, 0x65, 0x76, 0x78], {offset: 8})) {
|
||||
return {
|
||||
ext: 'heic',
|
||||
mime: 'image/heic-sequence'
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (check([0xAB, 0x4B, 0x54, 0x58, 0x20, 0x31, 0x31, 0xBB, 0x0D, 0x0A, 0x1A, 0x0A])) {
|
||||
return {
|
||||
ext: 'ktx',
|
||||
mime: 'image/ktx'
|
||||
};
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
9
node_modules/bin-wrapper/node_modules/file-type/license
generated
vendored
Normal file
9
node_modules/bin-wrapper/node_modules/file-type/license
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
||||
|
||||
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.
|
||||
123
node_modules/bin-wrapper/node_modules/file-type/package.json
generated
vendored
Normal file
123
node_modules/bin-wrapper/node_modules/file-type/package.json
generated
vendored
Normal file
@@ -0,0 +1,123 @@
|
||||
{
|
||||
"name": "file-type",
|
||||
"version": "8.1.0",
|
||||
"description": "Detect the file type of a Buffer/Uint8Array",
|
||||
"license": "MIT",
|
||||
"repository": "sindresorhus/file-type",
|
||||
"author": {
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
"url": "sindresorhus.com"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && ava"
|
||||
},
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"keywords": [
|
||||
"mime",
|
||||
"file",
|
||||
"type",
|
||||
"archive",
|
||||
"image",
|
||||
"img",
|
||||
"pic",
|
||||
"picture",
|
||||
"flash",
|
||||
"photo",
|
||||
"video",
|
||||
"detect",
|
||||
"check",
|
||||
"is",
|
||||
"exif",
|
||||
"exe",
|
||||
"binary",
|
||||
"buffer",
|
||||
"uint8array",
|
||||
"jpg",
|
||||
"png",
|
||||
"gif",
|
||||
"webp",
|
||||
"flif",
|
||||
"cr2",
|
||||
"tif",
|
||||
"bmp",
|
||||
"jxr",
|
||||
"psd",
|
||||
"zip",
|
||||
"tar",
|
||||
"rar",
|
||||
"gz",
|
||||
"bz2",
|
||||
"7z",
|
||||
"dmg",
|
||||
"mp4",
|
||||
"m4v",
|
||||
"mid",
|
||||
"mkv",
|
||||
"webm",
|
||||
"mov",
|
||||
"avi",
|
||||
"mpg",
|
||||
"mp2",
|
||||
"mp3",
|
||||
"m4a",
|
||||
"ogg",
|
||||
"opus",
|
||||
"flac",
|
||||
"wav",
|
||||
"amr",
|
||||
"pdf",
|
||||
"epub",
|
||||
"mobi",
|
||||
"swf",
|
||||
"rtf",
|
||||
"woff",
|
||||
"woff2",
|
||||
"eot",
|
||||
"ttf",
|
||||
"otf",
|
||||
"ico",
|
||||
"flv",
|
||||
"ps",
|
||||
"xz",
|
||||
"sqlite",
|
||||
"xpi",
|
||||
"cab",
|
||||
"deb",
|
||||
"ar",
|
||||
"rpm",
|
||||
"Z",
|
||||
"lz",
|
||||
"msi",
|
||||
"mxf",
|
||||
"mts",
|
||||
"wasm",
|
||||
"webassembly",
|
||||
"blend",
|
||||
"bpg",
|
||||
"docx",
|
||||
"pptx",
|
||||
"xlsx",
|
||||
"3gp",
|
||||
"jp2",
|
||||
"jpm",
|
||||
"jpx",
|
||||
"mj2",
|
||||
"aif",
|
||||
"odt",
|
||||
"ods",
|
||||
"odp",
|
||||
"xml",
|
||||
"heic"
|
||||
],
|
||||
"devDependencies": {
|
||||
"ava": "*",
|
||||
"read-chunk": "^2.0.0",
|
||||
"xo": "*"
|
||||
}
|
||||
}
|
||||
186
node_modules/bin-wrapper/node_modules/file-type/readme.md
generated
vendored
Normal file
186
node_modules/bin-wrapper/node_modules/file-type/readme.md
generated
vendored
Normal file
@@ -0,0 +1,186 @@
|
||||
# file-type [](https://travis-ci.org/sindresorhus/file-type)
|
||||
|
||||
> Detect the file type of a Buffer/Uint8Array
|
||||
|
||||
The file type is detected by checking the [magic number](http://en.wikipedia.org/wiki/Magic_number_(programming)#Magic_numbers_in_files) of the buffer.
|
||||
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install file-type
|
||||
```
|
||||
|
||||
<a href="https://www.patreon.com/sindresorhus">
|
||||
<img src="https://c5.patreon.com/external/logo/become_a_patron_button@2x.png" width="160">
|
||||
</a>
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
##### Node.js
|
||||
|
||||
```js
|
||||
const readChunk = require('read-chunk');
|
||||
const fileType = require('file-type');
|
||||
const buffer = readChunk.sync('unicorn.png', 0, 4100);
|
||||
|
||||
fileType(buffer);
|
||||
//=> {ext: 'png', mime: 'image/png'}
|
||||
```
|
||||
|
||||
Or from a remote location:
|
||||
|
||||
```js
|
||||
const http = require('http');
|
||||
const fileType = require('file-type');
|
||||
const url = 'http://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif';
|
||||
|
||||
http.get(url, res => {
|
||||
res.once('data', chunk => {
|
||||
res.destroy();
|
||||
console.log(fileType(chunk));
|
||||
//=> {ext: 'gif', mime: 'image/gif'}
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
##### Browser
|
||||
|
||||
```js
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', 'unicorn.png');
|
||||
xhr.responseType = 'arraybuffer';
|
||||
|
||||
xhr.onload = () => {
|
||||
fileType(new Uint8Array(this.response));
|
||||
//=> {ext: 'png', mime: 'image/png'}
|
||||
};
|
||||
|
||||
xhr.send();
|
||||
```
|
||||
|
||||
|
||||
## API
|
||||
|
||||
### fileType(input)
|
||||
|
||||
Returns an `Object` with:
|
||||
|
||||
- `ext` - One of the [supported file types](#supported-file-types)
|
||||
- `mime` - The [MIME type](http://en.wikipedia.org/wiki/Internet_media_type)
|
||||
|
||||
Or `null` when no match.
|
||||
|
||||
#### input
|
||||
|
||||
Type: `Buffer` `Uint8Array`
|
||||
|
||||
It only needs the first 4100 bytes.
|
||||
|
||||
|
||||
## Supported file types
|
||||
|
||||
- [`jpg`](https://en.wikipedia.org/wiki/JPEG)
|
||||
- [`png`](https://en.wikipedia.org/wiki/Portable_Network_Graphics)
|
||||
- [`gif`](https://en.wikipedia.org/wiki/GIF)
|
||||
- [`webp`](https://en.wikipedia.org/wiki/WebP)
|
||||
- [`flif`](https://en.wikipedia.org/wiki/Free_Lossless_Image_Format)
|
||||
- [`cr2`](http://fileinfo.com/extension/cr2)
|
||||
- [`tif`](https://en.wikipedia.org/wiki/Tagged_Image_File_Format)
|
||||
- [`bmp`](https://en.wikipedia.org/wiki/BMP_file_format)
|
||||
- [`jxr`](https://en.wikipedia.org/wiki/JPEG_XR)
|
||||
- [`psd`](https://en.wikipedia.org/wiki/Adobe_Photoshop#File_format)
|
||||
- [`zip`](https://en.wikipedia.org/wiki/Zip_(file_format))
|
||||
- [`tar`](https://en.wikipedia.org/wiki/Tar_(computing)#File_format)
|
||||
- [`rar`](https://en.wikipedia.org/wiki/RAR_(file_format))
|
||||
- [`gz`](https://en.wikipedia.org/wiki/Gzip)
|
||||
- [`bz2`](https://en.wikipedia.org/wiki/Bzip2)
|
||||
- [`7z`](https://en.wikipedia.org/wiki/7z)
|
||||
- [`dmg`](https://en.wikipedia.org/wiki/Apple_Disk_Image)
|
||||
- [`mp4`](https://en.wikipedia.org/wiki/MPEG-4_Part_14#Filename_extensions)
|
||||
- [`m4v`](https://en.wikipedia.org/wiki/M4V)
|
||||
- [`mid`](https://en.wikipedia.org/wiki/MIDI)
|
||||
- [`mkv`](https://en.wikipedia.org/wiki/Matroska)
|
||||
- [`webm`](https://en.wikipedia.org/wiki/WebM)
|
||||
- [`mov`](https://en.wikipedia.org/wiki/QuickTime_File_Format)
|
||||
- [`avi`](https://en.wikipedia.org/wiki/Audio_Video_Interleave)
|
||||
- [`wmv`](https://en.wikipedia.org/wiki/Windows_Media_Video)
|
||||
- [`mpg`](https://en.wikipedia.org/wiki/MPEG-1)
|
||||
- [`mp2`](https://en.wikipedia.org/wiki/MPEG-1_Audio_Layer_II)
|
||||
- [`mp3`](https://en.wikipedia.org/wiki/MP3)
|
||||
- [`m4a`](https://en.wikipedia.org/wiki/MPEG-4_Part_14#.MP4_versus_.M4A)
|
||||
- [`ogg`](https://en.wikipedia.org/wiki/Ogg)
|
||||
- [`opus`](https://en.wikipedia.org/wiki/Opus_(audio_format))
|
||||
- [`flac`](https://en.wikipedia.org/wiki/FLAC)
|
||||
- [`wav`](https://en.wikipedia.org/wiki/WAV)
|
||||
- [`qcp`](https://en.wikipedia.org/wiki/QCP)
|
||||
- [`amr`](https://en.wikipedia.org/wiki/Adaptive_Multi-Rate_audio_codec)
|
||||
- [`pdf`](https://en.wikipedia.org/wiki/Portable_Document_Format)
|
||||
- [`epub`](https://en.wikipedia.org/wiki/EPUB)
|
||||
- [`mobi`](https://en.wikipedia.org/wiki/Mobipocket) - Mobipocket
|
||||
- [`exe`](https://en.wikipedia.org/wiki/.exe)
|
||||
- [`swf`](https://en.wikipedia.org/wiki/SWF)
|
||||
- [`rtf`](https://en.wikipedia.org/wiki/Rich_Text_Format)
|
||||
- [`woff`](https://en.wikipedia.org/wiki/Web_Open_Font_Format)
|
||||
- [`woff2`](https://en.wikipedia.org/wiki/Web_Open_Font_Format)
|
||||
- [`eot`](https://en.wikipedia.org/wiki/Embedded_OpenType)
|
||||
- [`ttf`](https://en.wikipedia.org/wiki/TrueType)
|
||||
- [`otf`](https://en.wikipedia.org/wiki/OpenType)
|
||||
- [`ico`](https://en.wikipedia.org/wiki/ICO_(file_format))
|
||||
- [`flv`](https://en.wikipedia.org/wiki/Flash_Video)
|
||||
- [`ps`](https://en.wikipedia.org/wiki/Postscript)
|
||||
- [`xz`](https://en.wikipedia.org/wiki/Xz)
|
||||
- [`sqlite`](https://www.sqlite.org/fileformat2.html)
|
||||
- [`nes`](http://fileinfo.com/extension/nes)
|
||||
- [`crx`](https://developer.chrome.com/extensions/crx)
|
||||
- [`xpi`](https://en.wikipedia.org/wiki/XPInstall)
|
||||
- [`cab`](https://en.wikipedia.org/wiki/Cabinet_(file_format))
|
||||
- [`deb`](https://en.wikipedia.org/wiki/Deb_(file_format))
|
||||
- [`ar`](https://en.wikipedia.org/wiki/Ar_(Unix))
|
||||
- [`rpm`](http://fileinfo.com/extension/rpm)
|
||||
- [`Z`](http://fileinfo.com/extension/z)
|
||||
- [`lz`](https://en.wikipedia.org/wiki/Lzip)
|
||||
- [`msi`](https://en.wikipedia.org/wiki/Windows_Installer)
|
||||
- [`mxf`](https://en.wikipedia.org/wiki/Material_Exchange_Format)
|
||||
- [`mts`](https://en.wikipedia.org/wiki/.m2ts)
|
||||
- [`wasm`](https://en.wikipedia.org/wiki/WebAssembly)
|
||||
- [`blend`](https://wiki.blender.org/index.php/Dev:Source/Architecture/File_Format)
|
||||
- [`bpg`](https://bellard.org/bpg/)
|
||||
- [`docx`](https://en.wikipedia.org/wiki/Office_Open_XML)
|
||||
- [`pptx`](https://en.wikipedia.org/wiki/Office_Open_XML)
|
||||
- [`xlsx`](https://en.wikipedia.org/wiki/Office_Open_XML)
|
||||
- [`3gp`](https://en.wikipedia.org/wiki/3GP_and_3G2)
|
||||
- [`jp2`](https://en.wikipedia.org/wiki/JPEG_2000) - JPEG 2000
|
||||
- [`jpm`](https://en.wikipedia.org/wiki/JPEG_2000) - JPEG 2000
|
||||
- [`jpx`](https://en.wikipedia.org/wiki/JPEG_2000) - JPEG 2000
|
||||
- [`mj2`](https://en.wikipedia.org/wiki/Motion_JPEG_2000) - Motion JPEG 2000
|
||||
- [`aif`](https://en.wikipedia.org/wiki/Audio_Interchange_File_Format)
|
||||
- [`odt`](https://en.wikipedia.org/wiki/OpenDocument) - OpenDocument for word processing
|
||||
- [`ods`](https://en.wikipedia.org/wiki/OpenDocument) - OpenDocument for spreadsheets
|
||||
- [`odp`](https://en.wikipedia.org/wiki/OpenDocument) - OpenDocument for presentations
|
||||
- [`xml`](https://en.wikipedia.org/wiki/XML)
|
||||
- [`heic`](http://nokiatech.github.io/heif/technical.html)
|
||||
- [`cur`](https://en.wikipedia.org/wiki/ICO_(file_format))
|
||||
- [`ktx`](https://www.khronos.org/opengles/sdk/tools/KTX/file_format_spec/)
|
||||
- [`ape`](https://en.wikipedia.org/wiki/Monkey%27s_Audio) - Monkey's Audio
|
||||
|
||||
*SVG isn't included as it requires the whole file to be read, but you can get it [here](https://github.com/sindresorhus/is-svg).*
|
||||
|
||||
*Pull request welcome for additional commonly used file types.*
|
||||
|
||||
|
||||
## Related
|
||||
|
||||
- [file-type-cli](https://github.com/sindresorhus/file-type-cli) - CLI for this module
|
||||
|
||||
|
||||
## Created by
|
||||
|
||||
- [Sindre Sorhus](https://github.com/sindresorhus)
|
||||
- [Mikael Finstad](https://github.com/mifi)
|
||||
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
51
node_modules/bin-wrapper/node_modules/get-stream/buffer-stream.js
generated
vendored
Normal file
51
node_modules/bin-wrapper/node_modules/get-stream/buffer-stream.js
generated
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
'use strict';
|
||||
const PassThrough = require('stream').PassThrough;
|
||||
|
||||
module.exports = opts => {
|
||||
opts = Object.assign({}, opts);
|
||||
|
||||
const array = opts.array;
|
||||
let encoding = opts.encoding;
|
||||
const buffer = encoding === 'buffer';
|
||||
let objectMode = false;
|
||||
|
||||
if (array) {
|
||||
objectMode = !(encoding || buffer);
|
||||
} else {
|
||||
encoding = encoding || 'utf8';
|
||||
}
|
||||
|
||||
if (buffer) {
|
||||
encoding = null;
|
||||
}
|
||||
|
||||
let len = 0;
|
||||
const ret = [];
|
||||
const stream = new PassThrough({objectMode});
|
||||
|
||||
if (encoding) {
|
||||
stream.setEncoding(encoding);
|
||||
}
|
||||
|
||||
stream.on('data', chunk => {
|
||||
ret.push(chunk);
|
||||
|
||||
if (objectMode) {
|
||||
len = ret.length;
|
||||
} else {
|
||||
len += chunk.length;
|
||||
}
|
||||
});
|
||||
|
||||
stream.getBufferedValue = () => {
|
||||
if (array) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return buffer ? Buffer.concat(ret, len) : ret.join('');
|
||||
};
|
||||
|
||||
stream.getBufferedLength = () => len;
|
||||
|
||||
return stream;
|
||||
};
|
||||
51
node_modules/bin-wrapper/node_modules/get-stream/index.js
generated
vendored
Normal file
51
node_modules/bin-wrapper/node_modules/get-stream/index.js
generated
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
'use strict';
|
||||
const bufferStream = require('./buffer-stream');
|
||||
|
||||
function getStream(inputStream, opts) {
|
||||
if (!inputStream) {
|
||||
return Promise.reject(new Error('Expected a stream'));
|
||||
}
|
||||
|
||||
opts = Object.assign({maxBuffer: Infinity}, opts);
|
||||
|
||||
const maxBuffer = opts.maxBuffer;
|
||||
let stream;
|
||||
let clean;
|
||||
|
||||
const p = new Promise((resolve, reject) => {
|
||||
const error = err => {
|
||||
if (err) { // null check
|
||||
err.bufferedData = stream.getBufferedValue();
|
||||
}
|
||||
|
||||
reject(err);
|
||||
};
|
||||
|
||||
stream = bufferStream(opts);
|
||||
inputStream.once('error', error);
|
||||
inputStream.pipe(stream);
|
||||
|
||||
stream.on('data', () => {
|
||||
if (stream.getBufferedLength() > maxBuffer) {
|
||||
reject(new Error('maxBuffer exceeded'));
|
||||
}
|
||||
});
|
||||
stream.once('error', error);
|
||||
stream.on('end', resolve);
|
||||
|
||||
clean = () => {
|
||||
// some streams doesn't implement the `stream.Readable` interface correctly
|
||||
if (inputStream.unpipe) {
|
||||
inputStream.unpipe(stream);
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
p.then(clean, clean);
|
||||
|
||||
return p.then(() => stream.getBufferedValue());
|
||||
}
|
||||
|
||||
module.exports = getStream;
|
||||
module.exports.buffer = (stream, opts) => getStream(stream, Object.assign({}, opts, {encoding: 'buffer'}));
|
||||
module.exports.array = (stream, opts) => getStream(stream, Object.assign({}, opts, {array: true}));
|
||||
21
node_modules/bin-wrapper/node_modules/get-stream/license
generated
vendored
Normal file
21
node_modules/bin-wrapper/node_modules/get-stream/license
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
||||
|
||||
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.
|
||||
48
node_modules/bin-wrapper/node_modules/get-stream/package.json
generated
vendored
Normal file
48
node_modules/bin-wrapper/node_modules/get-stream/package.json
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
{
|
||||
"name": "get-stream",
|
||||
"version": "3.0.0",
|
||||
"description": "Get a stream as a string, buffer, or array",
|
||||
"license": "MIT",
|
||||
"repository": "sindresorhus/get-stream",
|
||||
"author": {
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
"url": "sindresorhus.com"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && ava"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"buffer-stream.js"
|
||||
],
|
||||
"keywords": [
|
||||
"get",
|
||||
"stream",
|
||||
"promise",
|
||||
"concat",
|
||||
"string",
|
||||
"str",
|
||||
"text",
|
||||
"buffer",
|
||||
"read",
|
||||
"data",
|
||||
"consume",
|
||||
"readable",
|
||||
"readablestream",
|
||||
"array",
|
||||
"object",
|
||||
"obj"
|
||||
],
|
||||
"devDependencies": {
|
||||
"ava": "*",
|
||||
"into-stream": "^3.0.0",
|
||||
"xo": "*"
|
||||
},
|
||||
"xo": {
|
||||
"esnext": true
|
||||
}
|
||||
}
|
||||
117
node_modules/bin-wrapper/node_modules/get-stream/readme.md
generated
vendored
Normal file
117
node_modules/bin-wrapper/node_modules/get-stream/readme.md
generated
vendored
Normal file
@@ -0,0 +1,117 @@
|
||||
# get-stream [](https://travis-ci.org/sindresorhus/get-stream)
|
||||
|
||||
> Get a stream as a string, buffer, or array
|
||||
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install --save get-stream
|
||||
```
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const fs = require('fs');
|
||||
const getStream = require('get-stream');
|
||||
const stream = fs.createReadStream('unicorn.txt');
|
||||
|
||||
getStream(stream).then(str => {
|
||||
console.log(str);
|
||||
/*
|
||||
,,))))))));,
|
||||
__)))))))))))))),
|
||||
\|/ -\(((((''''((((((((.
|
||||
-*-==//////(('' . `)))))),
|
||||
/|\ ))| o ;-. '((((( ,(,
|
||||
( `| / ) ;))))' ,_))^;(~
|
||||
| | | ,))((((_ _____------~~~-. %,;(;(>';'~
|
||||
o_); ; )))(((` ~---~ `:: \ %%~~)(v;(`('~
|
||||
; ''''```` `: `:::|\,__,%% );`'; ~
|
||||
| _ ) / `:|`----' `-'
|
||||
______/\/~ | / /
|
||||
/~;;.____/;;' / ___--,-( `;;;/
|
||||
/ // _;______;'------~~~~~ /;;/\ /
|
||||
// | | / ; \;;,\
|
||||
(<_ | ; /',/-----' _>
|
||||
\_| ||_ //~;~~~~~~~~~
|
||||
`\_| (,~~
|
||||
\~\
|
||||
~~
|
||||
*/
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
## API
|
||||
|
||||
The methods returns a promise that resolves when the `end` event fires on the stream, indicating that there is no more data to be read. The stream is switched to flowing mode.
|
||||
|
||||
### getStream(stream, [options])
|
||||
|
||||
Get the `stream` as a string.
|
||||
|
||||
#### options
|
||||
|
||||
##### encoding
|
||||
|
||||
Type: `string`<br>
|
||||
Default: `utf8`
|
||||
|
||||
[Encoding](https://nodejs.org/api/buffer.html#buffer_buffer) of the incoming stream.
|
||||
|
||||
##### maxBuffer
|
||||
|
||||
Type: `number`<br>
|
||||
Default: `Infinity`
|
||||
|
||||
Maximum length of the returned string. If it exceeds this value before the stream ends, the promise will be rejected.
|
||||
|
||||
### getStream.buffer(stream, [options])
|
||||
|
||||
Get the `stream` as a buffer.
|
||||
|
||||
It honors the `maxBuffer` option as above, but it refers to byte length rather than string length.
|
||||
|
||||
### getStream.array(stream, [options])
|
||||
|
||||
Get the `stream` as an array of values.
|
||||
|
||||
It honors both the `maxBuffer` and `encoding` options. The behavior changes slightly based on the encoding chosen:
|
||||
|
||||
- When `encoding` is unset, it assumes an [object mode stream](https://nodesource.com/blog/understanding-object-streams/) and collects values emitted from `stream` unmodified. In this case `maxBuffer` refers to the number of items in the array (not the sum of their sizes).
|
||||
|
||||
- When `encoding` is set to `buffer`, it collects an array of buffers. `maxBuffer` refers to the summed byte lengths of every buffer in the array.
|
||||
|
||||
- When `encoding` is set to anything else, it collects an array of strings. `maxBuffer` refers to the summed character lengths of every string in the array.
|
||||
|
||||
|
||||
## Errors
|
||||
|
||||
If the input stream emits an `error` event, the promise will be rejected with the error. The buffered data will be attached to the `bufferedData` property of the error.
|
||||
|
||||
```js
|
||||
getStream(streamThatErrorsAtTheEnd('unicorn'))
|
||||
.catch(err => {
|
||||
console.log(err.bufferedData);
|
||||
//=> 'unicorn'
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
## FAQ
|
||||
|
||||
### How is this different from [`concat-stream`](https://github.com/maxogden/concat-stream)?
|
||||
|
||||
This module accepts a stream instead of being one and returns a promise instead of using a callback. The API is simpler and it only supports returning a string, buffer, or array. It doesn't have a fragile type inference. You explicitly choose what you want. And it doesn't depend on the huge `readable-stream` package.
|
||||
|
||||
|
||||
## Related
|
||||
|
||||
- [get-stdin](https://github.com/sindresorhus/get-stdin) - Get stdin as a string or buffer
|
||||
|
||||
|
||||
## License
|
||||
|
||||
MIT © [Sindre Sorhus](https://sindresorhus.com)
|
||||
92
node_modules/bin-wrapper/node_modules/got/errors.js
generated
vendored
Normal file
92
node_modules/bin-wrapper/node_modules/got/errors.js
generated
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
'use strict';
|
||||
const urlLib = require('url');
|
||||
const http = require('http');
|
||||
const PCancelable = require('p-cancelable');
|
||||
const is = require('@sindresorhus/is');
|
||||
|
||||
class GotError extends Error {
|
||||
constructor(message, error, opts) {
|
||||
super(message);
|
||||
Error.captureStackTrace(this, this.constructor);
|
||||
this.name = 'GotError';
|
||||
|
||||
if (!is.undefined(error.code)) {
|
||||
this.code = error.code;
|
||||
}
|
||||
|
||||
Object.assign(this, {
|
||||
host: opts.host,
|
||||
hostname: opts.hostname,
|
||||
method: opts.method,
|
||||
path: opts.path,
|
||||
protocol: opts.protocol,
|
||||
url: opts.href
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports.GotError = GotError;
|
||||
|
||||
module.exports.CacheError = class extends GotError {
|
||||
constructor(error, opts) {
|
||||
super(error.message, error, opts);
|
||||
this.name = 'CacheError';
|
||||
}
|
||||
};
|
||||
|
||||
module.exports.RequestError = class extends GotError {
|
||||
constructor(error, opts) {
|
||||
super(error.message, error, opts);
|
||||
this.name = 'RequestError';
|
||||
}
|
||||
};
|
||||
|
||||
module.exports.ReadError = class extends GotError {
|
||||
constructor(error, opts) {
|
||||
super(error.message, error, opts);
|
||||
this.name = 'ReadError';
|
||||
}
|
||||
};
|
||||
|
||||
module.exports.ParseError = class extends GotError {
|
||||
constructor(error, statusCode, opts, data) {
|
||||
super(`${error.message} in "${urlLib.format(opts)}": \n${data.slice(0, 77)}...`, error, opts);
|
||||
this.name = 'ParseError';
|
||||
this.statusCode = statusCode;
|
||||
this.statusMessage = http.STATUS_CODES[this.statusCode];
|
||||
}
|
||||
};
|
||||
|
||||
module.exports.HTTPError = class extends GotError {
|
||||
constructor(statusCode, statusMessage, headers, opts) {
|
||||
if (statusMessage) {
|
||||
statusMessage = statusMessage.replace(/\r?\n/g, ' ').trim();
|
||||
} else {
|
||||
statusMessage = http.STATUS_CODES[statusCode];
|
||||
}
|
||||
super(`Response code ${statusCode} (${statusMessage})`, {}, opts);
|
||||
this.name = 'HTTPError';
|
||||
this.statusCode = statusCode;
|
||||
this.statusMessage = statusMessage;
|
||||
this.headers = headers;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports.MaxRedirectsError = class extends GotError {
|
||||
constructor(statusCode, redirectUrls, opts) {
|
||||
super('Redirected 10 times. Aborting.', {}, opts);
|
||||
this.name = 'MaxRedirectsError';
|
||||
this.statusCode = statusCode;
|
||||
this.statusMessage = http.STATUS_CODES[this.statusCode];
|
||||
this.redirectUrls = redirectUrls;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports.UnsupportedProtocolError = class extends GotError {
|
||||
constructor(opts) {
|
||||
super(`Unsupported protocol "${opts.protocol}"`, {}, opts);
|
||||
this.name = 'UnsupportedProtocolError';
|
||||
}
|
||||
};
|
||||
|
||||
module.exports.CancelError = PCancelable.CancelError;
|
||||
675
node_modules/bin-wrapper/node_modules/got/index.js
generated
vendored
Normal file
675
node_modules/bin-wrapper/node_modules/got/index.js
generated
vendored
Normal file
@@ -0,0 +1,675 @@
|
||||
'use strict';
|
||||
const EventEmitter = require('events');
|
||||
const http = require('http');
|
||||
const https = require('https');
|
||||
const PassThrough = require('stream').PassThrough;
|
||||
const Transform = require('stream').Transform;
|
||||
const urlLib = require('url');
|
||||
const fs = require('fs');
|
||||
const querystring = require('querystring');
|
||||
const CacheableRequest = require('cacheable-request');
|
||||
const duplexer3 = require('duplexer3');
|
||||
const intoStream = require('into-stream');
|
||||
const is = require('@sindresorhus/is');
|
||||
const getStream = require('get-stream');
|
||||
const timedOut = require('timed-out');
|
||||
const urlParseLax = require('url-parse-lax');
|
||||
const urlToOptions = require('url-to-options');
|
||||
const lowercaseKeys = require('lowercase-keys');
|
||||
const decompressResponse = require('decompress-response');
|
||||
const mimicResponse = require('mimic-response');
|
||||
const isRetryAllowed = require('is-retry-allowed');
|
||||
const isURL = require('isurl');
|
||||
const PCancelable = require('p-cancelable');
|
||||
const pTimeout = require('p-timeout');
|
||||
const pify = require('pify');
|
||||
const Buffer = require('safe-buffer').Buffer;
|
||||
const pkg = require('./package.json');
|
||||
const errors = require('./errors');
|
||||
|
||||
const getMethodRedirectCodes = new Set([300, 301, 302, 303, 304, 305, 307, 308]);
|
||||
const allMethodRedirectCodes = new Set([300, 303, 307, 308]);
|
||||
|
||||
const isFormData = body => is.nodeStream(body) && is.function(body.getBoundary);
|
||||
|
||||
const getBodySize = opts => {
|
||||
const body = opts.body;
|
||||
|
||||
if (opts.headers['content-length']) {
|
||||
return Number(opts.headers['content-length']);
|
||||
}
|
||||
|
||||
if (!body && !opts.stream) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (is.string(body)) {
|
||||
return Buffer.byteLength(body);
|
||||
}
|
||||
|
||||
if (isFormData(body)) {
|
||||
return pify(body.getLength.bind(body))();
|
||||
}
|
||||
|
||||
if (body instanceof fs.ReadStream) {
|
||||
return pify(fs.stat)(body.path).then(stat => stat.size);
|
||||
}
|
||||
|
||||
if (is.nodeStream(body) && is.buffer(body._buffer)) {
|
||||
return body._buffer.length;
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
function requestAsEventEmitter(opts) {
|
||||
opts = opts || {};
|
||||
|
||||
const ee = new EventEmitter();
|
||||
const requestUrl = opts.href || urlLib.resolve(urlLib.format(opts), opts.path);
|
||||
const redirects = [];
|
||||
const agents = is.object(opts.agent) ? opts.agent : null;
|
||||
let retryCount = 0;
|
||||
let redirectUrl;
|
||||
let uploadBodySize;
|
||||
let uploaded = 0;
|
||||
|
||||
const get = opts => {
|
||||
if (opts.protocol !== 'http:' && opts.protocol !== 'https:') {
|
||||
ee.emit('error', new got.UnsupportedProtocolError(opts));
|
||||
return;
|
||||
}
|
||||
|
||||
let fn = opts.protocol === 'https:' ? https : http;
|
||||
|
||||
if (agents) {
|
||||
const protocolName = opts.protocol === 'https:' ? 'https' : 'http';
|
||||
opts.agent = agents[protocolName] || opts.agent;
|
||||
}
|
||||
|
||||
if (opts.useElectronNet && process.versions.electron) {
|
||||
const electron = require('electron');
|
||||
fn = electron.net || electron.remote.net;
|
||||
}
|
||||
|
||||
let progressInterval;
|
||||
|
||||
const cacheableRequest = new CacheableRequest(fn.request, opts.cache);
|
||||
const cacheReq = cacheableRequest(opts, res => {
|
||||
clearInterval(progressInterval);
|
||||
|
||||
ee.emit('uploadProgress', {
|
||||
percent: 1,
|
||||
transferred: uploaded,
|
||||
total: uploadBodySize
|
||||
});
|
||||
|
||||
const statusCode = res.statusCode;
|
||||
|
||||
res.url = redirectUrl || requestUrl;
|
||||
res.requestUrl = requestUrl;
|
||||
|
||||
const followRedirect = opts.followRedirect && 'location' in res.headers;
|
||||
const redirectGet = followRedirect && getMethodRedirectCodes.has(statusCode);
|
||||
const redirectAll = followRedirect && allMethodRedirectCodes.has(statusCode);
|
||||
|
||||
if (redirectAll || (redirectGet && (opts.method === 'GET' || opts.method === 'HEAD'))) {
|
||||
res.resume();
|
||||
|
||||
if (statusCode === 303) {
|
||||
// Server responded with "see other", indicating that the resource exists at another location,
|
||||
// and the client should request it from that location via GET or HEAD.
|
||||
opts.method = 'GET';
|
||||
}
|
||||
|
||||
if (redirects.length >= 10) {
|
||||
ee.emit('error', new got.MaxRedirectsError(statusCode, redirects, opts), null, res);
|
||||
return;
|
||||
}
|
||||
|
||||
const bufferString = Buffer.from(res.headers.location, 'binary').toString();
|
||||
|
||||
redirectUrl = urlLib.resolve(urlLib.format(opts), bufferString);
|
||||
|
||||
redirects.push(redirectUrl);
|
||||
|
||||
const redirectOpts = Object.assign({}, opts, urlLib.parse(redirectUrl));
|
||||
|
||||
ee.emit('redirect', res, redirectOpts);
|
||||
|
||||
get(redirectOpts);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
setImmediate(() => {
|
||||
try {
|
||||
getResponse(res, opts, ee, redirects);
|
||||
} catch (e) {
|
||||
ee.emit('error', e);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
cacheReq.on('error', err => {
|
||||
if (err instanceof CacheableRequest.RequestError) {
|
||||
ee.emit('error', new got.RequestError(err, opts));
|
||||
} else {
|
||||
ee.emit('error', new got.CacheError(err, opts));
|
||||
}
|
||||
});
|
||||
|
||||
cacheReq.once('request', req => {
|
||||
let aborted = false;
|
||||
req.once('abort', _ => {
|
||||
aborted = true;
|
||||
});
|
||||
|
||||
req.once('error', err => {
|
||||
clearInterval(progressInterval);
|
||||
|
||||
if (aborted) {
|
||||
return;
|
||||
}
|
||||
|
||||
const backoff = opts.retries(++retryCount, err);
|
||||
|
||||
if (backoff) {
|
||||
setTimeout(get, backoff, opts);
|
||||
return;
|
||||
}
|
||||
|
||||
ee.emit('error', new got.RequestError(err, opts));
|
||||
});
|
||||
|
||||
ee.once('request', req => {
|
||||
ee.emit('uploadProgress', {
|
||||
percent: 0,
|
||||
transferred: 0,
|
||||
total: uploadBodySize
|
||||
});
|
||||
|
||||
const socket = req.connection;
|
||||
if (socket) {
|
||||
// `._connecting` was the old property which was made public in node v6.1.0
|
||||
const isConnecting = socket.connecting === undefined ? socket._connecting : socket.connecting;
|
||||
|
||||
const onSocketConnect = () => {
|
||||
const uploadEventFrequency = 150;
|
||||
|
||||
progressInterval = setInterval(() => {
|
||||
if (socket.destroyed) {
|
||||
clearInterval(progressInterval);
|
||||
return;
|
||||
}
|
||||
|
||||
const lastUploaded = uploaded;
|
||||
const headersSize = req._header ? Buffer.byteLength(req._header) : 0;
|
||||
uploaded = socket.bytesWritten - headersSize;
|
||||
|
||||
// Prevent the known issue of `bytesWritten` being larger than body size
|
||||
if (uploadBodySize && uploaded > uploadBodySize) {
|
||||
uploaded = uploadBodySize;
|
||||
}
|
||||
|
||||
// Don't emit events with unchanged progress and
|
||||
// prevent last event from being emitted, because
|
||||
// it's emitted when `response` is emitted
|
||||
if (uploaded === lastUploaded || uploaded === uploadBodySize) {
|
||||
return;
|
||||
}
|
||||
|
||||
ee.emit('uploadProgress', {
|
||||
percent: uploadBodySize ? uploaded / uploadBodySize : 0,
|
||||
transferred: uploaded,
|
||||
total: uploadBodySize
|
||||
});
|
||||
}, uploadEventFrequency);
|
||||
};
|
||||
|
||||
// Only subscribe to 'connect' event if we're actually connecting a new
|
||||
// socket, otherwise if we're already connected (because this is a
|
||||
// keep-alive connection) do not bother. This is important since we won't
|
||||
// get a 'connect' event for an already connected socket.
|
||||
if (isConnecting) {
|
||||
socket.once('connect', onSocketConnect);
|
||||
} else {
|
||||
onSocketConnect();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (opts.gotTimeout) {
|
||||
clearInterval(progressInterval);
|
||||
timedOut(req, opts.gotTimeout);
|
||||
}
|
||||
|
||||
setImmediate(() => {
|
||||
ee.emit('request', req);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
setImmediate(() => {
|
||||
Promise.resolve(getBodySize(opts))
|
||||
.then(size => {
|
||||
uploadBodySize = size;
|
||||
|
||||
if (
|
||||
is.undefined(opts.headers['content-length']) &&
|
||||
is.undefined(opts.headers['transfer-encoding']) &&
|
||||
isFormData(opts.body)
|
||||
) {
|
||||
opts.headers['content-length'] = size;
|
||||
}
|
||||
|
||||
get(opts);
|
||||
})
|
||||
.catch(err => {
|
||||
ee.emit('error', err);
|
||||
});
|
||||
});
|
||||
|
||||
return ee;
|
||||
}
|
||||
|
||||
function getResponse(res, opts, ee, redirects) {
|
||||
const downloadBodySize = Number(res.headers['content-length']) || null;
|
||||
let downloaded = 0;
|
||||
|
||||
const progressStream = new Transform({
|
||||
transform(chunk, encoding, callback) {
|
||||
downloaded += chunk.length;
|
||||
|
||||
const percent = downloadBodySize ? downloaded / downloadBodySize : 0;
|
||||
|
||||
// Let flush() be responsible for emitting the last event
|
||||
if (percent < 1) {
|
||||
ee.emit('downloadProgress', {
|
||||
percent,
|
||||
transferred: downloaded,
|
||||
total: downloadBodySize
|
||||
});
|
||||
}
|
||||
|
||||
callback(null, chunk);
|
||||
},
|
||||
|
||||
flush(callback) {
|
||||
ee.emit('downloadProgress', {
|
||||
percent: 1,
|
||||
transferred: downloaded,
|
||||
total: downloadBodySize
|
||||
});
|
||||
|
||||
callback();
|
||||
}
|
||||
});
|
||||
|
||||
mimicResponse(res, progressStream);
|
||||
progressStream.redirectUrls = redirects;
|
||||
|
||||
const response = opts.decompress === true &&
|
||||
is.function(decompressResponse) &&
|
||||
opts.method !== 'HEAD' ? decompressResponse(progressStream) : progressStream;
|
||||
|
||||
if (!opts.decompress && ['gzip', 'deflate'].indexOf(res.headers['content-encoding']) !== -1) {
|
||||
opts.encoding = null;
|
||||
}
|
||||
|
||||
ee.emit('response', response);
|
||||
|
||||
ee.emit('downloadProgress', {
|
||||
percent: 0,
|
||||
transferred: 0,
|
||||
total: downloadBodySize
|
||||
});
|
||||
|
||||
res.pipe(progressStream);
|
||||
}
|
||||
|
||||
function asPromise(opts) {
|
||||
const timeoutFn = requestPromise => opts.gotTimeout && opts.gotTimeout.request ?
|
||||
pTimeout(requestPromise, opts.gotTimeout.request, new got.RequestError({message: 'Request timed out', code: 'ETIMEDOUT'}, opts)) :
|
||||
requestPromise;
|
||||
|
||||
const proxy = new EventEmitter();
|
||||
|
||||
const cancelable = new PCancelable((resolve, reject, onCancel) => {
|
||||
const ee = requestAsEventEmitter(opts);
|
||||
let cancelOnRequest = false;
|
||||
|
||||
onCancel(() => {
|
||||
cancelOnRequest = true;
|
||||
});
|
||||
|
||||
ee.on('request', req => {
|
||||
if (cancelOnRequest) {
|
||||
req.abort();
|
||||
}
|
||||
|
||||
onCancel(() => {
|
||||
req.abort();
|
||||
});
|
||||
|
||||
if (is.nodeStream(opts.body)) {
|
||||
opts.body.pipe(req);
|
||||
opts.body = undefined;
|
||||
return;
|
||||
}
|
||||
|
||||
req.end(opts.body);
|
||||
});
|
||||
|
||||
ee.on('response', res => {
|
||||
const stream = is.null(opts.encoding) ? getStream.buffer(res) : getStream(res, opts);
|
||||
|
||||
stream
|
||||
.catch(err => reject(new got.ReadError(err, opts)))
|
||||
.then(data => {
|
||||
const statusCode = res.statusCode;
|
||||
const limitStatusCode = opts.followRedirect ? 299 : 399;
|
||||
|
||||
res.body = data;
|
||||
|
||||
if (opts.json && res.body) {
|
||||
try {
|
||||
res.body = JSON.parse(res.body);
|
||||
} catch (err) {
|
||||
if (statusCode >= 200 && statusCode < 300) {
|
||||
throw new got.ParseError(err, statusCode, opts, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (opts.throwHttpErrors && statusCode !== 304 && (statusCode < 200 || statusCode > limitStatusCode)) {
|
||||
throw new got.HTTPError(statusCode, res.statusMessage, res.headers, opts);
|
||||
}
|
||||
|
||||
resolve(res);
|
||||
})
|
||||
.catch(err => {
|
||||
Object.defineProperty(err, 'response', {value: res});
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
|
||||
ee.once('error', reject);
|
||||
ee.on('redirect', proxy.emit.bind(proxy, 'redirect'));
|
||||
ee.on('uploadProgress', proxy.emit.bind(proxy, 'uploadProgress'));
|
||||
ee.on('downloadProgress', proxy.emit.bind(proxy, 'downloadProgress'));
|
||||
});
|
||||
|
||||
// Preserve backwards-compatibility
|
||||
// TODO: Remove this in the next major version
|
||||
Object.defineProperty(cancelable, 'canceled', {
|
||||
get() {
|
||||
return cancelable.isCanceled;
|
||||
}
|
||||
});
|
||||
|
||||
const promise = timeoutFn(cancelable);
|
||||
|
||||
promise.cancel = cancelable.cancel.bind(cancelable);
|
||||
|
||||
promise.on = (name, fn) => {
|
||||
proxy.on(name, fn);
|
||||
return promise;
|
||||
};
|
||||
|
||||
return promise;
|
||||
}
|
||||
|
||||
function asStream(opts) {
|
||||
opts.stream = true;
|
||||
|
||||
const input = new PassThrough();
|
||||
const output = new PassThrough();
|
||||
const proxy = duplexer3(input, output);
|
||||
let timeout;
|
||||
|
||||
if (opts.gotTimeout && opts.gotTimeout.request) {
|
||||
timeout = setTimeout(() => {
|
||||
proxy.emit('error', new got.RequestError({message: 'Request timed out', code: 'ETIMEDOUT'}, opts));
|
||||
}, opts.gotTimeout.request);
|
||||
}
|
||||
|
||||
if (opts.json) {
|
||||
throw new Error('Got can not be used as a stream when the `json` option is used');
|
||||
}
|
||||
|
||||
if (opts.body) {
|
||||
proxy.write = () => {
|
||||
throw new Error('Got\'s stream is not writable when the `body` option is used');
|
||||
};
|
||||
}
|
||||
|
||||
const ee = requestAsEventEmitter(opts);
|
||||
|
||||
ee.on('request', req => {
|
||||
proxy.emit('request', req);
|
||||
|
||||
if (is.nodeStream(opts.body)) {
|
||||
opts.body.pipe(req);
|
||||
return;
|
||||
}
|
||||
|
||||
if (opts.body) {
|
||||
req.end(opts.body);
|
||||
return;
|
||||
}
|
||||
|
||||
if (opts.method === 'POST' || opts.method === 'PUT' || opts.method === 'PATCH') {
|
||||
input.pipe(req);
|
||||
return;
|
||||
}
|
||||
|
||||
req.end();
|
||||
});
|
||||
|
||||
ee.on('response', res => {
|
||||
clearTimeout(timeout);
|
||||
|
||||
const statusCode = res.statusCode;
|
||||
|
||||
res.on('error', err => {
|
||||
proxy.emit('error', new got.ReadError(err, opts));
|
||||
});
|
||||
|
||||
res.pipe(output);
|
||||
|
||||
if (opts.throwHttpErrors && statusCode !== 304 && (statusCode < 200 || statusCode > 299)) {
|
||||
proxy.emit('error', new got.HTTPError(statusCode, res.statusMessage, res.headers, opts), null, res);
|
||||
return;
|
||||
}
|
||||
|
||||
proxy.emit('response', res);
|
||||
});
|
||||
|
||||
ee.on('error', proxy.emit.bind(proxy, 'error'));
|
||||
ee.on('redirect', proxy.emit.bind(proxy, 'redirect'));
|
||||
ee.on('uploadProgress', proxy.emit.bind(proxy, 'uploadProgress'));
|
||||
ee.on('downloadProgress', proxy.emit.bind(proxy, 'downloadProgress'));
|
||||
|
||||
return proxy;
|
||||
}
|
||||
|
||||
function normalizeArguments(url, opts) {
|
||||
if (!is.string(url) && !is.object(url)) {
|
||||
throw new TypeError(`Parameter \`url\` must be a string or object, not ${is(url)}`);
|
||||
} else if (is.string(url)) {
|
||||
url = url.replace(/^unix:/, 'http://$&');
|
||||
|
||||
try {
|
||||
decodeURI(url);
|
||||
} catch (err) {
|
||||
throw new Error('Parameter `url` must contain valid UTF-8 character sequences');
|
||||
}
|
||||
|
||||
url = urlParseLax(url);
|
||||
if (url.auth) {
|
||||
throw new Error('Basic authentication must be done with the `auth` option');
|
||||
}
|
||||
} else if (isURL.lenient(url)) {
|
||||
url = urlToOptions(url);
|
||||
}
|
||||
|
||||
opts = Object.assign(
|
||||
{
|
||||
path: '',
|
||||
retries: 2,
|
||||
cache: false,
|
||||
decompress: true,
|
||||
useElectronNet: false,
|
||||
throwHttpErrors: true
|
||||
},
|
||||
url,
|
||||
{
|
||||
protocol: url.protocol || 'http:' // Override both null/undefined with default protocol
|
||||
},
|
||||
opts
|
||||
);
|
||||
|
||||
const headers = lowercaseKeys(opts.headers);
|
||||
for (const key of Object.keys(headers)) {
|
||||
if (is.nullOrUndefined(headers[key])) {
|
||||
delete headers[key];
|
||||
}
|
||||
}
|
||||
|
||||
opts.headers = Object.assign({
|
||||
'user-agent': `${pkg.name}/${pkg.version} (https://github.com/sindresorhus/got)`
|
||||
}, headers);
|
||||
|
||||
if (opts.decompress && is.undefined(opts.headers['accept-encoding'])) {
|
||||
opts.headers['accept-encoding'] = 'gzip, deflate';
|
||||
}
|
||||
|
||||
const query = opts.query;
|
||||
|
||||
if (query) {
|
||||
if (!is.string(query)) {
|
||||
opts.query = querystring.stringify(query);
|
||||
}
|
||||
|
||||
opts.path = `${opts.path.split('?')[0]}?${opts.query}`;
|
||||
delete opts.query;
|
||||
}
|
||||
|
||||
if (opts.json && is.undefined(opts.headers.accept)) {
|
||||
opts.headers.accept = 'application/json';
|
||||
}
|
||||
|
||||
const body = opts.body;
|
||||
if (is.nullOrUndefined(body)) {
|
||||
opts.method = (opts.method || 'GET').toUpperCase();
|
||||
} else {
|
||||
const headers = opts.headers;
|
||||
if (!is.nodeStream(body) && !is.string(body) && !is.buffer(body) && !(opts.form || opts.json)) {
|
||||
throw new TypeError('The `body` option must be a stream.Readable, string, Buffer or plain Object');
|
||||
}
|
||||
|
||||
const canBodyBeStringified = is.plainObject(body) || is.array(body);
|
||||
if ((opts.form || opts.json) && !canBodyBeStringified) {
|
||||
throw new TypeError('The `body` option must be a plain Object or Array when the `form` or `json` option is used');
|
||||
}
|
||||
|
||||
if (isFormData(body)) {
|
||||
// Special case for https://github.com/form-data/form-data
|
||||
headers['content-type'] = headers['content-type'] || `multipart/form-data; boundary=${body.getBoundary()}`;
|
||||
} else if (opts.form && canBodyBeStringified) {
|
||||
headers['content-type'] = headers['content-type'] || 'application/x-www-form-urlencoded';
|
||||
opts.body = querystring.stringify(body);
|
||||
} else if (opts.json && canBodyBeStringified) {
|
||||
headers['content-type'] = headers['content-type'] || 'application/json';
|
||||
opts.body = JSON.stringify(body);
|
||||
}
|
||||
|
||||
if (is.undefined(headers['content-length']) && is.undefined(headers['transfer-encoding']) && !is.nodeStream(body)) {
|
||||
const length = is.string(opts.body) ? Buffer.byteLength(opts.body) : opts.body.length;
|
||||
headers['content-length'] = length;
|
||||
}
|
||||
|
||||
// Convert buffer to stream to receive upload progress events
|
||||
// see https://github.com/sindresorhus/got/pull/322
|
||||
if (is.buffer(body)) {
|
||||
opts.body = intoStream(body);
|
||||
opts.body._buffer = body;
|
||||
}
|
||||
|
||||
opts.method = (opts.method || 'POST').toUpperCase();
|
||||
}
|
||||
|
||||
if (opts.hostname === 'unix') {
|
||||
const matches = /(.+?):(.+)/.exec(opts.path);
|
||||
|
||||
if (matches) {
|
||||
opts.socketPath = matches[1];
|
||||
opts.path = matches[2];
|
||||
opts.host = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (!is.function(opts.retries)) {
|
||||
const retries = opts.retries;
|
||||
|
||||
opts.retries = (iter, err) => {
|
||||
if (iter > retries || !isRetryAllowed(err)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const noise = Math.random() * 100;
|
||||
|
||||
return ((1 << iter) * 1000) + noise;
|
||||
};
|
||||
}
|
||||
|
||||
if (is.undefined(opts.followRedirect)) {
|
||||
opts.followRedirect = true;
|
||||
}
|
||||
|
||||
if (opts.timeout) {
|
||||
if (is.number(opts.timeout)) {
|
||||
opts.gotTimeout = {request: opts.timeout};
|
||||
} else {
|
||||
opts.gotTimeout = opts.timeout;
|
||||
}
|
||||
delete opts.timeout;
|
||||
}
|
||||
|
||||
return opts;
|
||||
}
|
||||
|
||||
function got(url, opts) {
|
||||
try {
|
||||
const normalizedArgs = normalizeArguments(url, opts);
|
||||
|
||||
if (normalizedArgs.stream) {
|
||||
return asStream(normalizedArgs);
|
||||
}
|
||||
|
||||
return asPromise(normalizedArgs);
|
||||
} catch (err) {
|
||||
return Promise.reject(err);
|
||||
}
|
||||
}
|
||||
|
||||
got.stream = (url, opts) => asStream(normalizeArguments(url, opts));
|
||||
|
||||
const methods = [
|
||||
'get',
|
||||
'post',
|
||||
'put',
|
||||
'patch',
|
||||
'head',
|
||||
'delete'
|
||||
];
|
||||
|
||||
for (const method of methods) {
|
||||
got[method] = (url, opts) => got(url, Object.assign({}, opts, {method}));
|
||||
got.stream[method] = (url, opts) => got.stream(url, Object.assign({}, opts, {method}));
|
||||
}
|
||||
|
||||
Object.assign(got, errors);
|
||||
|
||||
module.exports = got;
|
||||
9
node_modules/bin-wrapper/node_modules/got/license
generated
vendored
Normal file
9
node_modules/bin-wrapper/node_modules/got/license
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
||||
|
||||
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.
|
||||
84
node_modules/bin-wrapper/node_modules/got/node_modules/pify/index.js
generated
vendored
Normal file
84
node_modules/bin-wrapper/node_modules/got/node_modules/pify/index.js
generated
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
'use strict';
|
||||
|
||||
const processFn = (fn, opts) => function () {
|
||||
const P = opts.promiseModule;
|
||||
const args = new Array(arguments.length);
|
||||
|
||||
for (let i = 0; i < arguments.length; i++) {
|
||||
args[i] = arguments[i];
|
||||
}
|
||||
|
||||
return new P((resolve, reject) => {
|
||||
if (opts.errorFirst) {
|
||||
args.push(function (err, result) {
|
||||
if (opts.multiArgs) {
|
||||
const results = new Array(arguments.length - 1);
|
||||
|
||||
for (let i = 1; i < arguments.length; i++) {
|
||||
results[i - 1] = arguments[i];
|
||||
}
|
||||
|
||||
if (err) {
|
||||
results.unshift(err);
|
||||
reject(results);
|
||||
} else {
|
||||
resolve(results);
|
||||
}
|
||||
} else if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
resolve(result);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
args.push(function (result) {
|
||||
if (opts.multiArgs) {
|
||||
const results = new Array(arguments.length - 1);
|
||||
|
||||
for (let i = 0; i < arguments.length; i++) {
|
||||
results[i] = arguments[i];
|
||||
}
|
||||
|
||||
resolve(results);
|
||||
} else {
|
||||
resolve(result);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn.apply(this, args);
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = (obj, opts) => {
|
||||
opts = Object.assign({
|
||||
exclude: [/.+(Sync|Stream)$/],
|
||||
errorFirst: true,
|
||||
promiseModule: Promise
|
||||
}, opts);
|
||||
|
||||
const filter = key => {
|
||||
const match = pattern => typeof pattern === 'string' ? key === pattern : pattern.test(key);
|
||||
return opts.include ? opts.include.some(match) : !opts.exclude.some(match);
|
||||
};
|
||||
|
||||
let ret;
|
||||
if (typeof obj === 'function') {
|
||||
ret = function () {
|
||||
if (opts.excludeMain) {
|
||||
return obj.apply(this, arguments);
|
||||
}
|
||||
|
||||
return processFn(obj, opts).apply(this, arguments);
|
||||
};
|
||||
} else {
|
||||
ret = Object.create(Object.getPrototypeOf(obj));
|
||||
}
|
||||
|
||||
for (const key in obj) { // eslint-disable-line guard-for-in
|
||||
const x = obj[key];
|
||||
ret[key] = typeof x === 'function' && filter(key) ? processFn(x, opts) : x;
|
||||
}
|
||||
|
||||
return ret;
|
||||
};
|
||||
9
node_modules/bin-wrapper/node_modules/got/node_modules/pify/license
generated
vendored
Normal file
9
node_modules/bin-wrapper/node_modules/got/node_modules/pify/license
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
||||
|
||||
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.
|
||||
51
node_modules/bin-wrapper/node_modules/got/node_modules/pify/package.json
generated
vendored
Normal file
51
node_modules/bin-wrapper/node_modules/got/node_modules/pify/package.json
generated
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
{
|
||||
"name": "pify",
|
||||
"version": "3.0.0",
|
||||
"description": "Promisify a callback-style function",
|
||||
"license": "MIT",
|
||||
"repository": "sindresorhus/pify",
|
||||
"author": {
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
"url": "sindresorhus.com"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && ava && npm run optimization-test",
|
||||
"optimization-test": "node --allow-natives-syntax optimization-test.js"
|
||||
},
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"keywords": [
|
||||
"promise",
|
||||
"promises",
|
||||
"promisify",
|
||||
"all",
|
||||
"denodify",
|
||||
"denodeify",
|
||||
"callback",
|
||||
"cb",
|
||||
"node",
|
||||
"then",
|
||||
"thenify",
|
||||
"convert",
|
||||
"transform",
|
||||
"wrap",
|
||||
"wrapper",
|
||||
"bind",
|
||||
"to",
|
||||
"async",
|
||||
"await",
|
||||
"es2015",
|
||||
"bluebird"
|
||||
],
|
||||
"devDependencies": {
|
||||
"ava": "*",
|
||||
"pinkie-promise": "^2.0.0",
|
||||
"v8-natives": "^1.0.0",
|
||||
"xo": "*"
|
||||
}
|
||||
}
|
||||
131
node_modules/bin-wrapper/node_modules/got/node_modules/pify/readme.md
generated
vendored
Normal file
131
node_modules/bin-wrapper/node_modules/got/node_modules/pify/readme.md
generated
vendored
Normal file
@@ -0,0 +1,131 @@
|
||||
# pify [](https://travis-ci.org/sindresorhus/pify)
|
||||
|
||||
> Promisify a callback-style function
|
||||
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install --save pify
|
||||
```
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const fs = require('fs');
|
||||
const pify = require('pify');
|
||||
|
||||
// Promisify a single function
|
||||
pify(fs.readFile)('package.json', 'utf8').then(data => {
|
||||
console.log(JSON.parse(data).name);
|
||||
//=> 'pify'
|
||||
});
|
||||
|
||||
// Promisify all methods in a module
|
||||
pify(fs).readFile('package.json', 'utf8').then(data => {
|
||||
console.log(JSON.parse(data).name);
|
||||
//=> 'pify'
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
## API
|
||||
|
||||
### pify(input, [options])
|
||||
|
||||
Returns a `Promise` wrapped version of the supplied function or module.
|
||||
|
||||
#### input
|
||||
|
||||
Type: `Function` `Object`
|
||||
|
||||
Callback-style function or module whose methods you want to promisify.
|
||||
|
||||
#### options
|
||||
|
||||
##### multiArgs
|
||||
|
||||
Type: `boolean`<br>
|
||||
Default: `false`
|
||||
|
||||
By default, the promisified function will only return the second argument from the callback, which works fine for most APIs. This option can be useful for modules like `request` that return multiple arguments. Turning this on will make it return an array of all arguments from the callback, excluding the error argument, instead of just the second argument. This also applies to rejections, where it returns an array of all the callback arguments, including the error.
|
||||
|
||||
```js
|
||||
const request = require('request');
|
||||
const pify = require('pify');
|
||||
|
||||
pify(request, {multiArgs: true})('https://sindresorhus.com').then(result => {
|
||||
const [httpResponse, body] = result;
|
||||
});
|
||||
```
|
||||
|
||||
##### include
|
||||
|
||||
Type: `string[]` `RegExp[]`
|
||||
|
||||
Methods in a module to promisify. Remaining methods will be left untouched.
|
||||
|
||||
##### exclude
|
||||
|
||||
Type: `string[]` `RegExp[]`<br>
|
||||
Default: `[/.+(Sync|Stream)$/]`
|
||||
|
||||
Methods in a module **not** to promisify. Methods with names ending with `'Sync'` are excluded by default.
|
||||
|
||||
##### excludeMain
|
||||
|
||||
Type: `boolean`<br>
|
||||
Default: `false`
|
||||
|
||||
If given module is a function itself, it will be promisified. Turn this option on if you want to promisify only methods of the module.
|
||||
|
||||
```js
|
||||
const pify = require('pify');
|
||||
|
||||
function fn() {
|
||||
return true;
|
||||
}
|
||||
|
||||
fn.method = (data, callback) => {
|
||||
setImmediate(() => {
|
||||
callback(null, data);
|
||||
});
|
||||
};
|
||||
|
||||
// Promisify methods but not `fn()`
|
||||
const promiseFn = pify(fn, {excludeMain: true});
|
||||
|
||||
if (promiseFn()) {
|
||||
promiseFn.method('hi').then(data => {
|
||||
console.log(data);
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
##### errorFirst
|
||||
|
||||
Type: `boolean`<br>
|
||||
Default: `true`
|
||||
|
||||
Whether the callback has an error as the first argument. You'll want to set this to `false` if you're dealing with an API that doesn't have an error as the first argument, like `fs.exists()`, some browser APIs, Chrome Extension APIs, etc.
|
||||
|
||||
##### promiseModule
|
||||
|
||||
Type: `Function`
|
||||
|
||||
Custom promise module to use instead of the native one.
|
||||
|
||||
Check out [`pinkie-promise`](https://github.com/floatdrop/pinkie-promise) if you need a tiny promise polyfill.
|
||||
|
||||
|
||||
## Related
|
||||
|
||||
- [p-event](https://github.com/sindresorhus/p-event) - Promisify an event by waiting for it to be emitted
|
||||
- [p-map](https://github.com/sindresorhus/p-map) - Map over promises concurrently
|
||||
- [More…](https://github.com/sindresorhus/promise-fun)
|
||||
|
||||
|
||||
## License
|
||||
|
||||
MIT © [Sindre Sorhus](https://sindresorhus.com)
|
||||
95
node_modules/bin-wrapper/node_modules/got/package.json
generated
vendored
Normal file
95
node_modules/bin-wrapper/node_modules/got/package.json
generated
vendored
Normal file
@@ -0,0 +1,95 @@
|
||||
{
|
||||
"name": "got",
|
||||
"version": "8.3.2",
|
||||
"description": "Simplified HTTP requests",
|
||||
"license": "MIT",
|
||||
"repository": "sindresorhus/got",
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
"url": "sindresorhus.com"
|
||||
},
|
||||
{
|
||||
"name": "Vsevolod Strukchinsky",
|
||||
"email": "floatdrop@gmail.com",
|
||||
"url": "github.com/floatdrop"
|
||||
},
|
||||
{
|
||||
"name": "Alexander Tesfamichael",
|
||||
"email": "alex.tesfamichael@gmail.com",
|
||||
"url": "alextes.me"
|
||||
}
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && nyc ava",
|
||||
"coveralls": "nyc report --reporter=text-lcov | coveralls"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"errors.js"
|
||||
],
|
||||
"keywords": [
|
||||
"http",
|
||||
"https",
|
||||
"get",
|
||||
"got",
|
||||
"url",
|
||||
"uri",
|
||||
"request",
|
||||
"util",
|
||||
"utility",
|
||||
"simple",
|
||||
"curl",
|
||||
"wget",
|
||||
"fetch",
|
||||
"net",
|
||||
"network",
|
||||
"electron"
|
||||
],
|
||||
"dependencies": {
|
||||
"@sindresorhus/is": "^0.7.0",
|
||||
"cacheable-request": "^2.1.1",
|
||||
"decompress-response": "^3.3.0",
|
||||
"duplexer3": "^0.1.4",
|
||||
"get-stream": "^3.0.0",
|
||||
"into-stream": "^3.1.0",
|
||||
"is-retry-allowed": "^1.1.0",
|
||||
"isurl": "^1.0.0-alpha5",
|
||||
"lowercase-keys": "^1.0.0",
|
||||
"mimic-response": "^1.0.0",
|
||||
"p-cancelable": "^0.4.0",
|
||||
"p-timeout": "^2.0.1",
|
||||
"pify": "^3.0.0",
|
||||
"safe-buffer": "^5.1.1",
|
||||
"timed-out": "^4.0.1",
|
||||
"url-parse-lax": "^3.0.0",
|
||||
"url-to-options": "^1.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"ava": "^0.25.0",
|
||||
"coveralls": "^3.0.0",
|
||||
"form-data": "^2.1.1",
|
||||
"get-port": "^3.0.0",
|
||||
"nyc": "^11.0.2",
|
||||
"p-event": "^1.3.0",
|
||||
"pem": "^1.4.4",
|
||||
"proxyquire": "^1.8.0",
|
||||
"sinon": "^4.0.0",
|
||||
"slow-stream": "0.0.4",
|
||||
"tempfile": "^2.0.0",
|
||||
"tempy": "^0.2.1",
|
||||
"universal-url": "1.0.0-alpha",
|
||||
"xo": "^0.20.0"
|
||||
},
|
||||
"ava": {
|
||||
"concurrency": 4
|
||||
},
|
||||
"browser": {
|
||||
"decompress-response": false,
|
||||
"electron": false
|
||||
}
|
||||
}
|
||||
650
node_modules/bin-wrapper/node_modules/got/readme.md
generated
vendored
Normal file
650
node_modules/bin-wrapper/node_modules/got/readme.md
generated
vendored
Normal file
@@ -0,0 +1,650 @@
|
||||
<div align="center">
|
||||
<br>
|
||||
<br>
|
||||
<img width="360" src="media/logo.svg" alt="Got">
|
||||
<br>
|
||||
<br>
|
||||
<br>
|
||||
<p align="center">Huge thanks to <a href="https://moxy.studio"><img src="https://sindresorhus.com/assets/thanks/moxy-logo.svg" width="150"></a> for sponsoring me!
|
||||
</p>
|
||||
<br>
|
||||
<br>
|
||||
</div>
|
||||
|
||||
> Simplified HTTP requests
|
||||
|
||||
[](https://travis-ci.org/sindresorhus/got) [](https://coveralls.io/github/sindresorhus/got?branch=master) [](https://npmjs.com/got)
|
||||
|
||||
A nicer interface to the built-in [`http`](http://nodejs.org/api/http.html) module.
|
||||
|
||||
Created because [`request`](https://github.com/request/request) is bloated *(several megabytes!)*.
|
||||
|
||||
|
||||
## Highlights
|
||||
|
||||
- [Promise & stream API](#api)
|
||||
- [Request cancelation](#aborting-the-request)
|
||||
- [RFC compliant caching](#cache-adapters)
|
||||
- [Follows redirects](#followredirect)
|
||||
- [Retries on network failure](#retries)
|
||||
- [Progress events](#onuploadprogress-progress)
|
||||
- [Handles gzip/deflate](#decompress)
|
||||
- [Timeout handling](#timeout)
|
||||
- [Errors with metadata](#errors)
|
||||
- [JSON mode](#json)
|
||||
- [WHATWG URL support](#url)
|
||||
- [Electron support](#useelectronnet)
|
||||
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install got
|
||||
```
|
||||
|
||||
<a href="https://www.patreon.com/sindresorhus">
|
||||
<img src="https://c5.patreon.com/external/logo/become_a_patron_button@2x.png" width="160">
|
||||
</a>
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const got = require('got');
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
const response = await got('sindresorhus.com');
|
||||
console.log(response.body);
|
||||
//=> '<!doctype html> ...'
|
||||
} catch (error) {
|
||||
console.log(error.response.body);
|
||||
//=> 'Internal server error ...'
|
||||
}
|
||||
})();
|
||||
```
|
||||
|
||||
###### Streams
|
||||
|
||||
```js
|
||||
const fs = require('fs');
|
||||
const got = require('got');
|
||||
|
||||
got.stream('sindresorhus.com').pipe(fs.createWriteStream('index.html'));
|
||||
|
||||
// For POST, PUT, and PATCH methods `got.stream` returns a `stream.Writable`
|
||||
fs.createReadStream('index.html').pipe(got.stream.post('sindresorhus.com'));
|
||||
```
|
||||
|
||||
|
||||
### API
|
||||
|
||||
It's a `GET` request by default, but can be changed by using different methods or in the `options`.
|
||||
|
||||
#### got(url, [options])
|
||||
|
||||
Returns a Promise for a `response` object with a `body` property, a `url` property with the request URL or the final URL after redirects, and a `requestUrl` property with the original request URL.
|
||||
|
||||
The response object will normally be a [Node.js HTTP response stream](https://nodejs.org/api/http.html#http_class_http_incomingmessage), however if returned from the cache it will be a [responselike object](https://github.com/lukechilds/responselike) which behaves in the same way.
|
||||
|
||||
The response will also have a `fromCache` property set with a boolean value.
|
||||
|
||||
##### url
|
||||
|
||||
Type: `string` `Object`
|
||||
|
||||
The URL to request as simple string, a [`http.request` options](https://nodejs.org/api/http.html#http_http_request_options_callback), or a [WHATWG `URL`](https://nodejs.org/api/url.html#url_class_url).
|
||||
|
||||
Properties from `options` will override properties in the parsed `url`.
|
||||
|
||||
If no protocol is specified, it will default to `https`.
|
||||
|
||||
##### options
|
||||
|
||||
Type: `Object`
|
||||
|
||||
Any of the [`http.request`](http://nodejs.org/api/http.html#http_http_request_options_callback) options.
|
||||
|
||||
###### stream
|
||||
|
||||
Type: `boolean`<br>
|
||||
Default: `false`
|
||||
|
||||
Returns a `Stream` instead of a `Promise`. This is equivalent to calling `got.stream(url, [options])`.
|
||||
|
||||
###### body
|
||||
|
||||
Type: `string` `Buffer` `stream.Readable`
|
||||
|
||||
*This is mutually exclusive with stream mode.*
|
||||
|
||||
Body that will be sent with a `POST` request.
|
||||
|
||||
If present in `options` and `options.method` is not set, `options.method` will be set to `POST`.
|
||||
|
||||
If `content-length` or `transfer-encoding` is not set in `options.headers` and `body` is a string or buffer, `content-length` will be set to the body length.
|
||||
|
||||
###### encoding
|
||||
|
||||
Type: `string` `null`<br>
|
||||
Default: `'utf8'`
|
||||
|
||||
[Encoding](https://nodejs.org/api/buffer.html#buffer_buffers_and_character_encodings) to be used on `setEncoding` of the response data. If `null`, the body is returned as a [`Buffer`](https://nodejs.org/api/buffer.html) (binary data).
|
||||
|
||||
###### form
|
||||
|
||||
Type: `boolean`<br>
|
||||
Default: `false`
|
||||
|
||||
*This is mutually exclusive with stream mode.*
|
||||
|
||||
If set to `true` and `Content-Type` header is not set, it will be set to `application/x-www-form-urlencoded`.
|
||||
|
||||
`body` must be a plain object or array and will be stringified.
|
||||
|
||||
###### json
|
||||
|
||||
Type: `boolean`<br>
|
||||
Default: `false`
|
||||
|
||||
*This is mutually exclusive with stream mode.*
|
||||
|
||||
If set to `true` and `Content-Type` header is not set, it will be set to `application/json`.
|
||||
|
||||
Parse response body with `JSON.parse` and set `accept` header to `application/json`. If used in conjunction with the `form` option, the `body` will the stringified as querystring and the response parsed as JSON.
|
||||
|
||||
`body` must be a plain object or array and will be stringified.
|
||||
|
||||
###### query
|
||||
|
||||
Type: `string` `Object`<br>
|
||||
|
||||
Query string object that will be added to the request URL. This will override the query string in `url`.
|
||||
|
||||
###### timeout
|
||||
|
||||
Type: `number` `Object`
|
||||
|
||||
Milliseconds to wait for the server to end the response before aborting request with `ETIMEDOUT` error.
|
||||
|
||||
This also accepts an object with separate `connect`, `socket`, and `request` fields for connection, socket, and entire request timeouts.
|
||||
|
||||
###### retries
|
||||
|
||||
Type: `number` `Function`<br>
|
||||
Default: `2`
|
||||
|
||||
Number of request retries when network errors happens. Delays between retries counts with function `1000 * Math.pow(2, retry) + Math.random() * 100`, where `retry` is attempt number (starts from 0).
|
||||
|
||||
Option accepts `function` with `retry` and `error` arguments. Function must return delay in milliseconds (`0` return value cancels retry).
|
||||
|
||||
**Note:** if `retries` is `number`, `ENOTFOUND` and `ENETUNREACH` error will not be retried (see full list in [`is-retry-allowed`](https://github.com/floatdrop/is-retry-allowed/blob/master/index.js#L12) module).
|
||||
|
||||
###### followRedirect
|
||||
|
||||
Type: `boolean`<br>
|
||||
Default: `true`
|
||||
|
||||
Defines if redirect responses should be followed automatically.
|
||||
|
||||
Note that if a `303` is sent by the server in response to any request type (`POST`, `DELETE`, etc.), got will automatically
|
||||
request the resource pointed to in the location header via `GET`. This is in accordance with [the spec](https://tools.ietf.org/html/rfc7231#section-6.4.4).
|
||||
|
||||
###### decompress
|
||||
|
||||
Type: `boolean`<br>
|
||||
Default: `true`
|
||||
|
||||
Decompress the response automatically. This will set the `accept-encoding` header to `gzip, deflate` unless you set it yourself.
|
||||
|
||||
If this is disabled, a compressed response is returned as a `Buffer`. This may be useful if you want to handle decompression yourself or stream the raw compressed data.
|
||||
|
||||
###### cache
|
||||
|
||||
Type: `Object`<br>
|
||||
Default: `false`
|
||||
|
||||
[Cache adapter instance](#cache-adapters) for storing cached data.
|
||||
|
||||
###### useElectronNet
|
||||
|
||||
Type: `boolean`<br>
|
||||
Default: `false`
|
||||
|
||||
When used in Electron, Got will use [`electron.net`](https://electronjs.org/docs/api/net/) instead of the Node.js `http` module. According to the Electron docs, it should be fully compatible, but it's not entirely. See [#315](https://github.com/sindresorhus/got/issues/315).
|
||||
|
||||
###### throwHttpErrors
|
||||
|
||||
Type: `boolean`<br>
|
||||
Default: `true`
|
||||
|
||||
Determines if a `got.HTTPError` is thrown for error responses (non-2xx status codes).
|
||||
|
||||
If this is disabled, requests that encounter an error status code will be resolved with the `response` instead of throwing. This may be useful if you are checking for resource availability and are expecting error responses.
|
||||
|
||||
#### Streams
|
||||
|
||||
#### got.stream(url, [options])
|
||||
|
||||
`stream` method will return Duplex stream with additional events:
|
||||
|
||||
##### .on('request', request)
|
||||
|
||||
`request` event to get the request object of the request.
|
||||
|
||||
**Tip**: You can use `request` event to abort request:
|
||||
|
||||
```js
|
||||
got.stream('github.com')
|
||||
.on('request', req => setTimeout(() => req.abort(), 50));
|
||||
```
|
||||
|
||||
##### .on('response', response)
|
||||
|
||||
`response` event to get the response object of the final request.
|
||||
|
||||
##### .on('redirect', response, nextOptions)
|
||||
|
||||
`redirect` event to get the response object of a redirect. The second argument is options for the next request to the redirect location.
|
||||
|
||||
##### .on('uploadProgress', progress)
|
||||
##### .on('downloadProgress', progress)
|
||||
|
||||
Progress events for uploading (sending request) and downloading (receiving response). The `progress` argument is an object like:
|
||||
|
||||
```js
|
||||
{
|
||||
percent: 0.1,
|
||||
transferred: 1024,
|
||||
total: 10240
|
||||
}
|
||||
```
|
||||
|
||||
If it's not possible to retrieve the body size (can happen when streaming), `total` will be `null`.
|
||||
|
||||
**Note**: Progress events can also be used with promises.
|
||||
|
||||
```js
|
||||
(async () => {
|
||||
const response = await got('sindresorhus.com')
|
||||
.on('downloadProgress', progress => {
|
||||
// Report download progress
|
||||
})
|
||||
.on('uploadProgress', progress => {
|
||||
// Report upload progress
|
||||
});
|
||||
|
||||
console.log(response);
|
||||
})();
|
||||
```
|
||||
|
||||
##### .on('error', error, body, response)
|
||||
|
||||
`error` event emitted in case of protocol error (like `ENOTFOUND` etc.) or status error (4xx or 5xx). The second argument is the body of the server response in case of status error. The third argument is response object.
|
||||
|
||||
#### got.get(url, [options])
|
||||
#### got.post(url, [options])
|
||||
#### got.put(url, [options])
|
||||
#### got.patch(url, [options])
|
||||
#### got.head(url, [options])
|
||||
#### got.delete(url, [options])
|
||||
|
||||
Sets `options.method` to the method name and makes a request.
|
||||
|
||||
|
||||
## Errors
|
||||
|
||||
Each error contains (if available) `statusCode`, `statusMessage`, `host`, `hostname`, `method`, `path`, `protocol` and `url` properties to make debugging easier.
|
||||
|
||||
In Promise mode, the `response` is attached to the error.
|
||||
|
||||
#### got.CacheError
|
||||
|
||||
When a cache method fails, for example if the database goes down, or there's a filesystem error.
|
||||
|
||||
#### got.RequestError
|
||||
|
||||
When a request fails. Contains a `code` property with error class code, like `ECONNREFUSED`.
|
||||
|
||||
#### got.ReadError
|
||||
|
||||
When reading from response stream fails.
|
||||
|
||||
#### got.ParseError
|
||||
|
||||
When `json` option is enabled, server response code is 2xx, and `JSON.parse` fails.
|
||||
|
||||
#### got.HTTPError
|
||||
|
||||
When server response code is not 2xx. Includes `statusCode`, `statusMessage`, and `redirectUrls` properties.
|
||||
|
||||
#### got.MaxRedirectsError
|
||||
|
||||
When server redirects you more than 10 times. Includes a `redirectUrls` property, which is an array of the URLs Got was redirected to before giving up.
|
||||
|
||||
#### got.UnsupportedProtocolError
|
||||
|
||||
When given an unsupported protocol.
|
||||
|
||||
#### got.CancelError
|
||||
|
||||
When the request is aborted with `.cancel()`.
|
||||
|
||||
|
||||
## Aborting the request
|
||||
|
||||
The promise returned by Got has a [`.cancel()`](https://github.com/sindresorhus/p-cancelable) method which, when called, aborts the request.
|
||||
|
||||
```js
|
||||
(async () => {
|
||||
const request = got(url, options);
|
||||
|
||||
…
|
||||
|
||||
// In another part of the code
|
||||
if (something) {
|
||||
request.cancel();
|
||||
}
|
||||
|
||||
…
|
||||
|
||||
try {
|
||||
await request;
|
||||
} catch (error) {
|
||||
if (request.isCanceled) { // Or `error instanceof got.CancelError`
|
||||
// Handle cancelation
|
||||
}
|
||||
|
||||
// Handle other errors
|
||||
}
|
||||
})();
|
||||
```
|
||||
|
||||
<a name="cache-adapters"></a>
|
||||
## Cache
|
||||
|
||||
Got implements [RFC 7234](http://httpwg.org/specs/rfc7234.html) compliant HTTP caching which works out of the box in memory or is easily pluggable with a wide range of storage adapters. Fresh cache entries are served directly from cache and stale cache entries are revalidated with `If-None-Match`/`If-Modified-Since` headers. You can read more about the underlying cache behaviour in the `cacheable-request` [documentation](https://github.com/lukechilds/cacheable-request).
|
||||
|
||||
You can use the JavaScript `Map` type as an in memory cache:
|
||||
|
||||
```js
|
||||
const got = require('got');
|
||||
const map = new Map();
|
||||
|
||||
(async () => {
|
||||
let response = await got('sindresorhus.com', {cache: map});
|
||||
console.log(response.fromCache);
|
||||
//=> false
|
||||
|
||||
response = await got('sindresorhus.com', {cache: map});
|
||||
console.log(response.fromCache);
|
||||
//=> true
|
||||
})();
|
||||
```
|
||||
|
||||
Got uses [Keyv](https://github.com/lukechilds/keyv) internally to support a wide range of storage adapters. For something more scalable you could use an [official Keyv storage adapter](https://github.com/lukechilds/keyv#official-storage-adapters):
|
||||
|
||||
```
|
||||
$ npm install @keyv/redis
|
||||
```
|
||||
|
||||
```js
|
||||
const got = require('got');
|
||||
const KeyvRedis = require('@keyv/redis');
|
||||
|
||||
const redis = new KeyvRedis('redis://user:pass@localhost:6379');
|
||||
|
||||
got('sindresorhus.com', {cache: redis});
|
||||
```
|
||||
|
||||
Got supports anything that follows the Map API, so it's easy to write your own storage adapter or use a third-party solution.
|
||||
|
||||
For example, the following are all valid storage adapters:
|
||||
|
||||
```js
|
||||
const storageAdapter = new Map();
|
||||
// or
|
||||
const storageAdapter = require('./my-storage-adapter');
|
||||
// or
|
||||
const QuickLRU = require('quick-lru');
|
||||
const storageAdapter = new QuickLRU({maxSize: 1000});
|
||||
|
||||
got('sindresorhus.com', {cache: storageAdapter});
|
||||
```
|
||||
|
||||
View the [Keyv docs](https://github.com/lukechilds/keyv) for more information on how to use storage adapters.
|
||||
|
||||
|
||||
## Proxies
|
||||
|
||||
You can use the [`tunnel`](https://github.com/koichik/node-tunnel) module with the `agent` option to work with proxies:
|
||||
|
||||
```js
|
||||
const got = require('got');
|
||||
const tunnel = require('tunnel');
|
||||
|
||||
got('sindresorhus.com', {
|
||||
agent: tunnel.httpOverHttp({
|
||||
proxy: {
|
||||
host: 'localhost'
|
||||
}
|
||||
})
|
||||
});
|
||||
```
|
||||
|
||||
If you require different agents for different protocols, you can pass a map of agents to the `agent` option. This is necessary because a request to one protocol might redirect to another. In such a scenario, `got` will switch over to the right protocol agent for you.
|
||||
|
||||
```js
|
||||
const got = require('got');
|
||||
const HttpAgent = require('agentkeepalive');
|
||||
const HttpsAgent = HttpAgent.HttpsAgent;
|
||||
|
||||
got('sindresorhus.com', {
|
||||
agent: {
|
||||
http: new HttpAgent(),
|
||||
https: new HttpsAgent()
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
## Cookies
|
||||
|
||||
You can use the [`cookie`](https://github.com/jshttp/cookie) module to include cookies in a request:
|
||||
|
||||
```js
|
||||
const got = require('got');
|
||||
const cookie = require('cookie');
|
||||
|
||||
got('google.com', {
|
||||
headers: {
|
||||
cookie: cookie.serialize('foo', 'bar')
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
## Form data
|
||||
|
||||
You can use the [`form-data`](https://github.com/form-data/form-data) module to create POST request with form data:
|
||||
|
||||
```js
|
||||
const fs = require('fs');
|
||||
const got = require('got');
|
||||
const FormData = require('form-data');
|
||||
const form = new FormData();
|
||||
|
||||
form.append('my_file', fs.createReadStream('/foo/bar.jpg'));
|
||||
|
||||
got.post('google.com', {
|
||||
body: form
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
## OAuth
|
||||
|
||||
You can use the [`oauth-1.0a`](https://github.com/ddo/oauth-1.0a) module to create a signed OAuth request:
|
||||
|
||||
```js
|
||||
const got = require('got');
|
||||
const crypto = require('crypto');
|
||||
const OAuth = require('oauth-1.0a');
|
||||
|
||||
const oauth = OAuth({
|
||||
consumer: {
|
||||
key: process.env.CONSUMER_KEY,
|
||||
secret: process.env.CONSUMER_SECRET
|
||||
},
|
||||
signature_method: 'HMAC-SHA1',
|
||||
hash_function: (baseString, key) => crypto.createHmac('sha1', key).update(baseString).digest('base64')
|
||||
});
|
||||
|
||||
const token = {
|
||||
key: process.env.ACCESS_TOKEN,
|
||||
secret: process.env.ACCESS_TOKEN_SECRET
|
||||
};
|
||||
|
||||
const url = 'https://api.twitter.com/1.1/statuses/home_timeline.json';
|
||||
|
||||
got(url, {
|
||||
headers: oauth.toHeader(oauth.authorize({url, method: 'GET'}, token)),
|
||||
json: true
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
## Unix Domain Sockets
|
||||
|
||||
Requests can also be sent via [unix domain sockets](http://serverfault.com/questions/124517/whats-the-difference-between-unix-socket-and-tcp-ip-socket). Use the following URL scheme: `PROTOCOL://unix:SOCKET:PATH`.
|
||||
|
||||
- `PROTOCOL` - `http` or `https` *(optional)*
|
||||
- `SOCKET` - absolute path to a unix domain socket, e.g. `/var/run/docker.sock`
|
||||
- `PATH` - request path, e.g. `/v2/keys`
|
||||
|
||||
```js
|
||||
got('http://unix:/var/run/docker.sock:/containers/json');
|
||||
|
||||
// or without protocol (http by default)
|
||||
got('unix:/var/run/docker.sock:/containers/json');
|
||||
```
|
||||
|
||||
## AWS
|
||||
|
||||
Requests to AWS services need to have their headers signed. This can be accomplished by using the [`aws4`](https://www.npmjs.com/package/aws4) package. This is an example for querying an ["Elasticsearch Service"](https://aws.amazon.com/elasticsearch-service/) host with a signed request.
|
||||
|
||||
```js
|
||||
const url = require('url');
|
||||
const AWS = require('aws-sdk');
|
||||
const aws4 = require('aws4');
|
||||
const got = require('got');
|
||||
const config = require('./config');
|
||||
|
||||
// Reads keys from the environment or `~/.aws/credentials`. Could be a plain object.
|
||||
const awsConfig = new AWS.Config({ region: config.region });
|
||||
|
||||
function request(uri, options) {
|
||||
const awsOpts = {
|
||||
region: awsConfig.region,
|
||||
headers: {
|
||||
accept: 'application/json',
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
method: 'GET',
|
||||
json: true
|
||||
};
|
||||
|
||||
// We need to parse the URL before passing it to `got` so `aws4` can sign the request
|
||||
const opts = Object.assign(url.parse(uri), awsOpts, options);
|
||||
aws4.sign(opts, awsConfig.credentials);
|
||||
|
||||
return got(opts);
|
||||
}
|
||||
|
||||
request(`https://${config.host}/production/users/1`);
|
||||
|
||||
request(`https://${config.host}/production/`, {
|
||||
// All usual `got` options
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
## Testing
|
||||
|
||||
You can test your requests by using the [`nock`](https://github.com/node-nock/nock) module to mock an endpoint:
|
||||
|
||||
```js
|
||||
const got = require('got');
|
||||
const nock = require('nock');
|
||||
|
||||
nock('https://sindresorhus.com')
|
||||
.get('/')
|
||||
.reply(200, 'Hello world!');
|
||||
|
||||
(async () => {
|
||||
const response = await got('sindresorhus.com');
|
||||
console.log(response.body);
|
||||
//=> 'Hello world!'
|
||||
})();
|
||||
```
|
||||
|
||||
If you need real integration tests you can use [`create-test-server`](https://github.com/lukechilds/create-test-server):
|
||||
|
||||
```js
|
||||
const got = require('got');
|
||||
const createTestServer = require('create-test-server');
|
||||
|
||||
(async () => {
|
||||
const server = await createTestServer();
|
||||
server.get('/', 'Hello world!');
|
||||
|
||||
const response = await got(server.url);
|
||||
console.log(response.body);
|
||||
//=> 'Hello world!'
|
||||
|
||||
await server.close();
|
||||
})();
|
||||
```
|
||||
|
||||
|
||||
## Tips
|
||||
|
||||
### User Agent
|
||||
|
||||
It's a good idea to set the `'user-agent'` header so the provider can more easily see how their resource is used. By default, it's the URL to this repo.
|
||||
|
||||
```js
|
||||
const got = require('got');
|
||||
const pkg = require('./package.json');
|
||||
|
||||
got('sindresorhus.com', {
|
||||
headers: {
|
||||
'user-agent': `my-module/${pkg.version} (https://github.com/username/my-module)`
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
### 304 Responses
|
||||
|
||||
Bear in mind, if you send an `if-modified-since` header and receive a `304 Not Modified` response, the body will be empty. It's your responsibility to cache and retrieve the body contents.
|
||||
|
||||
|
||||
## Related
|
||||
|
||||
- [gh-got](https://github.com/sindresorhus/gh-got) - Got convenience wrapper to interact with the GitHub API
|
||||
- [gl-got](https://github.com/singapore/gl-got) - Got convenience wrapper to interact with the GitLab API
|
||||
- [travis-got](https://github.com/samverschueren/travis-got) - Got convenience wrapper to interact with the Travis API
|
||||
- [graphql-got](https://github.com/kevva/graphql-got) - Got convenience wrapper to interact with GraphQL
|
||||
- [GotQL](https://github.com/khaosdoctor/gotql) - Got convenience wrapper to interact with GraphQL using JSON-parsed queries instead of strings
|
||||
|
||||
|
||||
## Created by
|
||||
|
||||
[](https://sindresorhus.com) | [](https://github.com/floatdrop) | [](https://github.com/AlexTes) | [](https://github.com/lukechilds)
|
||||
---|---|---|---
|
||||
[Sindre Sorhus](https://sindresorhus.com) | [Vsevolod Strukchinsky](https://github.com/floatdrop) | [Alexander Tesfamichael](https://alextes.me) | [Luke Childs](https://github.com/lukechilds)
|
||||
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
88
node_modules/bin-wrapper/node_modules/p-cancelable/index.js
generated
vendored
Normal file
88
node_modules/bin-wrapper/node_modules/p-cancelable/index.js
generated
vendored
Normal file
@@ -0,0 +1,88 @@
|
||||
'use strict';
|
||||
|
||||
class CancelError extends Error {
|
||||
constructor() {
|
||||
super('Promise was canceled');
|
||||
this.name = 'CancelError';
|
||||
}
|
||||
|
||||
get isCanceled() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
class PCancelable {
|
||||
static fn(userFn) {
|
||||
return function () {
|
||||
const args = [].slice.apply(arguments);
|
||||
return new PCancelable((resolve, reject, onCancel) => {
|
||||
args.push(onCancel);
|
||||
userFn.apply(null, args).then(resolve, reject);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
constructor(executor) {
|
||||
this._cancelHandlers = [];
|
||||
this._isPending = true;
|
||||
this._isCanceled = false;
|
||||
|
||||
this._promise = new Promise((resolve, reject) => {
|
||||
this._reject = reject;
|
||||
|
||||
return executor(
|
||||
value => {
|
||||
this._isPending = false;
|
||||
resolve(value);
|
||||
},
|
||||
error => {
|
||||
this._isPending = false;
|
||||
reject(error);
|
||||
},
|
||||
handler => {
|
||||
this._cancelHandlers.push(handler);
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
then(onFulfilled, onRejected) {
|
||||
return this._promise.then(onFulfilled, onRejected);
|
||||
}
|
||||
|
||||
catch(onRejected) {
|
||||
return this._promise.catch(onRejected);
|
||||
}
|
||||
|
||||
finally(onFinally) {
|
||||
return this._promise.finally(onFinally);
|
||||
}
|
||||
|
||||
cancel() {
|
||||
if (!this._isPending || this._isCanceled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this._cancelHandlers.length > 0) {
|
||||
try {
|
||||
for (const handler of this._cancelHandlers) {
|
||||
handler();
|
||||
}
|
||||
} catch (err) {
|
||||
this._reject(err);
|
||||
}
|
||||
}
|
||||
|
||||
this._isCanceled = true;
|
||||
this._reject(new CancelError());
|
||||
}
|
||||
|
||||
get isCanceled() {
|
||||
return this._isCanceled;
|
||||
}
|
||||
}
|
||||
|
||||
Object.setPrototypeOf(PCancelable.prototype, Promise.prototype);
|
||||
|
||||
module.exports = PCancelable;
|
||||
module.exports.CancelError = CancelError;
|
||||
9
node_modules/bin-wrapper/node_modules/p-cancelable/license
generated
vendored
Normal file
9
node_modules/bin-wrapper/node_modules/p-cancelable/license
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
||||
|
||||
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.
|
||||
47
node_modules/bin-wrapper/node_modules/p-cancelable/package.json
generated
vendored
Normal file
47
node_modules/bin-wrapper/node_modules/p-cancelable/package.json
generated
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
{
|
||||
"name": "p-cancelable",
|
||||
"version": "0.4.1",
|
||||
"description": "Create a promise that can be canceled",
|
||||
"license": "MIT",
|
||||
"repository": "sindresorhus/p-cancelable",
|
||||
"author": {
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
"url": "sindresorhus.com"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && ava"
|
||||
},
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"keywords": [
|
||||
"promise",
|
||||
"cancelable",
|
||||
"cancel",
|
||||
"canceled",
|
||||
"canceling",
|
||||
"cancellable",
|
||||
"cancellation",
|
||||
"abort",
|
||||
"abortable",
|
||||
"aborting",
|
||||
"cleanup",
|
||||
"task",
|
||||
"token",
|
||||
"async",
|
||||
"function",
|
||||
"await",
|
||||
"promises",
|
||||
"bluebird"
|
||||
],
|
||||
"devDependencies": {
|
||||
"ava": "*",
|
||||
"delay": "^2.0.0",
|
||||
"promise.prototype.finally": "^3.1.0",
|
||||
"xo": "*"
|
||||
}
|
||||
}
|
||||
135
node_modules/bin-wrapper/node_modules/p-cancelable/readme.md
generated
vendored
Normal file
135
node_modules/bin-wrapper/node_modules/p-cancelable/readme.md
generated
vendored
Normal file
@@ -0,0 +1,135 @@
|
||||
# p-cancelable [](https://travis-ci.org/sindresorhus/p-cancelable)
|
||||
|
||||
> Create a promise that can be canceled
|
||||
|
||||
Useful for animation, loading resources, long-running async computations, async iteration, etc.
|
||||
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install p-cancelable
|
||||
```
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const PCancelable = require('p-cancelable');
|
||||
|
||||
const cancelablePromise = new PCancelable((resolve, reject, onCancel) => {
|
||||
const worker = new SomeLongRunningOperation();
|
||||
|
||||
onCancel(() => {
|
||||
worker.close();
|
||||
});
|
||||
|
||||
worker.on('finish', resolve);
|
||||
worker.on('error', reject);
|
||||
});
|
||||
|
||||
cancelablePromise
|
||||
.then(value => {
|
||||
console.log('Operation finished successfully:', value);
|
||||
})
|
||||
.catch(error => {
|
||||
if (cancelablePromise.isCanceled) {
|
||||
// Handle the cancelation here
|
||||
console.log('Operation was canceled');
|
||||
return;
|
||||
}
|
||||
|
||||
throw error;
|
||||
});
|
||||
|
||||
// Cancel the operation after 10 seconds
|
||||
setTimeout(() => {
|
||||
cancelablePromise.cancel();
|
||||
}, 10000);
|
||||
```
|
||||
|
||||
|
||||
## API
|
||||
|
||||
### new PCancelable(executor)
|
||||
|
||||
Same as the [`Promise` constructor](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise), but with an appended `onCancel` parameter in `executor`.
|
||||
|
||||
`PCancelable` is a subclass of `Promise`.
|
||||
|
||||
#### onCanceled(fn)
|
||||
|
||||
Type: `Function`
|
||||
|
||||
Accepts a function that is called when the promise is canceled.
|
||||
|
||||
You're not required to call this function. You can call this function multiple times to add multiple cancel handlers.
|
||||
|
||||
### PCancelable#cancel()
|
||||
|
||||
Type: `Function`
|
||||
|
||||
Cancel the promise.
|
||||
|
||||
The cancellation is synchronous. Calling it after the promise has settled or multiple times does nothing.
|
||||
|
||||
### PCancelable#isCanceled
|
||||
|
||||
Type: `boolean`
|
||||
|
||||
Whether the promise is canceled.
|
||||
|
||||
### PCancelable.CancelError
|
||||
|
||||
Type: `Error`
|
||||
|
||||
Rejection reason when `.cancel()` is called.
|
||||
|
||||
It includes a `.isCanceled` property for convenience.
|
||||
|
||||
### PCancelable.fn(fn)
|
||||
|
||||
Convenience method to make your promise-returning or async function cancelable.
|
||||
|
||||
The function you specify will have `onCancel` appended to its parameters.
|
||||
|
||||
```js
|
||||
const fn = PCancelable.fn((input, onCancel) => {
|
||||
const job = new Job();
|
||||
|
||||
onCancel(() => {
|
||||
job.cleanup();
|
||||
});
|
||||
|
||||
return job.start(); //=> Promise
|
||||
});
|
||||
|
||||
const promise = fn('input'); //=> PCancelable
|
||||
|
||||
// …
|
||||
|
||||
promise.cancel();
|
||||
```
|
||||
|
||||
|
||||
## FAQ
|
||||
|
||||
### Cancelable vs. Cancellable
|
||||
|
||||
[In American English, the verb cancel is usually inflected canceled and canceling—with one l.](http://grammarist.com/spelling/cancel/)<br>Both a [browser API](https://developer.mozilla.org/en-US/docs/Web/API/Event/cancelable) and the [Cancelable Promises proposal](https://github.com/tc39/proposal-cancelable-promises) use this spelling.
|
||||
|
||||
### What about the official [Cancelable Promises proposal](https://github.com/tc39/proposal-cancelable-promises)?
|
||||
|
||||
~~It's still an early draft and I don't really like its current direction. It complicates everything and will require deep changes in the ecosystem to adapt to it. And the way you have to use cancel tokens is verbose and convoluted. I much prefer the more pragmatic and less invasive approach in this module.~~ The proposal was withdrawn.
|
||||
|
||||
|
||||
## Related
|
||||
|
||||
- [p-progress](https://github.com/sindresorhus/p-progress) - Create a promise that reports progress
|
||||
- [p-lazy](https://github.com/sindresorhus/p-lazy) - Create a lazy promise that defers execution until `.then()` or `.catch()` is called
|
||||
- [More…](https://github.com/sindresorhus/promise-fun)
|
||||
|
||||
|
||||
## License
|
||||
|
||||
MIT © [Sindre Sorhus](https://sindresorhus.com)
|
||||
272
node_modules/bin-wrapper/node_modules/p-event/index.js
generated
vendored
Normal file
272
node_modules/bin-wrapper/node_modules/p-event/index.js
generated
vendored
Normal file
@@ -0,0 +1,272 @@
|
||||
'use strict';
|
||||
const pTimeout = require('p-timeout');
|
||||
|
||||
const symbolAsyncIterator = Symbol.asyncIterator || '@@asyncIterator';
|
||||
|
||||
const normalizeEmitter = emitter => {
|
||||
const addListener = emitter.on || emitter.addListener || emitter.addEventListener;
|
||||
const removeListener = emitter.off || emitter.removeListener || emitter.removeEventListener;
|
||||
|
||||
if (!addListener || !removeListener) {
|
||||
throw new TypeError('Emitter is not compatible');
|
||||
}
|
||||
|
||||
return {
|
||||
addListener: addListener.bind(emitter),
|
||||
removeListener: removeListener.bind(emitter)
|
||||
};
|
||||
};
|
||||
|
||||
const normalizeEvents = event => Array.isArray(event) ? event : [event];
|
||||
|
||||
const multiple = (emitter, event, options) => {
|
||||
let cancel;
|
||||
const ret = new Promise((resolve, reject) => {
|
||||
options = Object.assign({
|
||||
rejectionEvents: ['error'],
|
||||
multiArgs: false,
|
||||
resolveImmediately: false
|
||||
}, options);
|
||||
|
||||
if (!(options.count >= 0 && (options.count === Infinity || Number.isInteger(options.count)))) {
|
||||
throw new TypeError('The `count` option should be at least 0 or more');
|
||||
}
|
||||
|
||||
// Allow multiple events
|
||||
const events = normalizeEvents(event);
|
||||
|
||||
const items = [];
|
||||
const {addListener, removeListener} = normalizeEmitter(emitter);
|
||||
|
||||
const onItem = (...args) => {
|
||||
const value = options.multiArgs ? args : args[0];
|
||||
|
||||
if (options.filter && !options.filter(value)) {
|
||||
return;
|
||||
}
|
||||
|
||||
items.push(value);
|
||||
|
||||
if (options.count === items.length) {
|
||||
cancel();
|
||||
resolve(items);
|
||||
}
|
||||
};
|
||||
|
||||
const rejectHandler = error => {
|
||||
cancel();
|
||||
reject(error);
|
||||
};
|
||||
|
||||
cancel = () => {
|
||||
for (const event of events) {
|
||||
removeListener(event, onItem);
|
||||
}
|
||||
|
||||
for (const rejectionEvent of options.rejectionEvents) {
|
||||
removeListener(rejectionEvent, rejectHandler);
|
||||
}
|
||||
};
|
||||
|
||||
for (const event of events) {
|
||||
addListener(event, onItem);
|
||||
}
|
||||
|
||||
for (const rejectionEvent of options.rejectionEvents) {
|
||||
addListener(rejectionEvent, rejectHandler);
|
||||
}
|
||||
|
||||
if (options.resolveImmediately) {
|
||||
resolve(items);
|
||||
}
|
||||
});
|
||||
|
||||
ret.cancel = cancel;
|
||||
|
||||
if (typeof options.timeout === 'number') {
|
||||
const timeout = pTimeout(ret, options.timeout);
|
||||
timeout.cancel = cancel;
|
||||
return timeout;
|
||||
}
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
module.exports = (emitter, event, options) => {
|
||||
if (typeof options === 'function') {
|
||||
options = {filter: options};
|
||||
}
|
||||
|
||||
options = Object.assign({}, options, {
|
||||
count: 1,
|
||||
resolveImmediately: false
|
||||
});
|
||||
|
||||
const arrayPromise = multiple(emitter, event, options);
|
||||
|
||||
const promise = arrayPromise.then(array => array[0]);
|
||||
promise.cancel = arrayPromise.cancel;
|
||||
|
||||
return promise;
|
||||
};
|
||||
|
||||
module.exports.multiple = multiple;
|
||||
|
||||
module.exports.iterator = (emitter, event, options) => {
|
||||
if (typeof options === 'function') {
|
||||
options = {filter: options};
|
||||
}
|
||||
|
||||
// Allow multiple events
|
||||
const events = normalizeEvents(event);
|
||||
|
||||
options = Object.assign({
|
||||
rejectionEvents: ['error'],
|
||||
resolutionEvents: [],
|
||||
limit: Infinity,
|
||||
multiArgs: false
|
||||
}, options);
|
||||
|
||||
const {limit} = options;
|
||||
const isValidLimit = limit >= 0 && (limit === Infinity || Number.isInteger(limit));
|
||||
if (!isValidLimit) {
|
||||
throw new TypeError('The `limit` option should be a non-negative integer or Infinity');
|
||||
}
|
||||
|
||||
if (limit === 0) {
|
||||
// Return an empty async iterator to avoid any further cost
|
||||
return {
|
||||
[Symbol.asyncIterator]() {
|
||||
return this;
|
||||
},
|
||||
next() {
|
||||
return Promise.resolve({done: true, value: undefined});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
let isLimitReached = false;
|
||||
|
||||
const {addListener, removeListener} = normalizeEmitter(emitter);
|
||||
|
||||
let done = false;
|
||||
let error;
|
||||
let hasPendingError = false;
|
||||
const nextQueue = [];
|
||||
const valueQueue = [];
|
||||
let eventCount = 0;
|
||||
|
||||
const valueHandler = (...args) => {
|
||||
eventCount++;
|
||||
isLimitReached = eventCount === limit;
|
||||
|
||||
const value = options.multiArgs ? args : args[0];
|
||||
|
||||
if (nextQueue.length > 0) {
|
||||
const {resolve} = nextQueue.shift();
|
||||
|
||||
resolve({done: false, value});
|
||||
|
||||
if (isLimitReached) {
|
||||
cancel();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
valueQueue.push(value);
|
||||
|
||||
if (isLimitReached) {
|
||||
cancel();
|
||||
}
|
||||
};
|
||||
|
||||
const cancel = () => {
|
||||
done = true;
|
||||
for (const event of events) {
|
||||
removeListener(event, valueHandler);
|
||||
}
|
||||
|
||||
for (const rejectionEvent of options.rejectionEvents) {
|
||||
removeListener(rejectionEvent, rejectHandler);
|
||||
}
|
||||
|
||||
for (const resolutionEvent of options.resolutionEvents) {
|
||||
removeListener(resolutionEvent, resolveHandler);
|
||||
}
|
||||
|
||||
while (nextQueue.length > 0) {
|
||||
const {resolve} = nextQueue.shift();
|
||||
resolve({done: true, value: undefined});
|
||||
}
|
||||
};
|
||||
|
||||
const rejectHandler = (...args) => {
|
||||
error = options.multiArgs ? args : args[0];
|
||||
|
||||
if (nextQueue.length > 0) {
|
||||
const {reject} = nextQueue.shift();
|
||||
reject(error);
|
||||
} else {
|
||||
hasPendingError = true;
|
||||
}
|
||||
|
||||
cancel();
|
||||
};
|
||||
|
||||
const resolveHandler = (...args) => {
|
||||
const value = options.multiArgs ? args : args[0];
|
||||
|
||||
if (options.filter && !options.filter(value)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (nextQueue.length > 0) {
|
||||
const {resolve} = nextQueue.shift();
|
||||
resolve({done: true, value});
|
||||
} else {
|
||||
valueQueue.push(value);
|
||||
}
|
||||
|
||||
cancel();
|
||||
};
|
||||
|
||||
for (const event of events) {
|
||||
addListener(event, valueHandler);
|
||||
}
|
||||
|
||||
for (const rejectionEvent of options.rejectionEvents) {
|
||||
addListener(rejectionEvent, rejectHandler);
|
||||
}
|
||||
|
||||
for (const resolutionEvent of options.resolutionEvents) {
|
||||
addListener(resolutionEvent, resolveHandler);
|
||||
}
|
||||
|
||||
return {
|
||||
[symbolAsyncIterator]() {
|
||||
return this;
|
||||
},
|
||||
next() {
|
||||
if (valueQueue.length > 0) {
|
||||
const value = valueQueue.shift();
|
||||
return Promise.resolve({done: done && valueQueue.length === 0 && !isLimitReached, value});
|
||||
}
|
||||
|
||||
if (hasPendingError) {
|
||||
hasPendingError = false;
|
||||
return Promise.reject(error);
|
||||
}
|
||||
|
||||
if (done) {
|
||||
return Promise.resolve({done: true, value: undefined});
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => nextQueue.push({resolve, reject}));
|
||||
},
|
||||
return(value) {
|
||||
cancel();
|
||||
return Promise.resolve({done, value});
|
||||
}
|
||||
};
|
||||
};
|
||||
9
node_modules/bin-wrapper/node_modules/p-event/license
generated
vendored
Normal file
9
node_modules/bin-wrapper/node_modules/p-event/license
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
||||
|
||||
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.
|
||||
52
node_modules/bin-wrapper/node_modules/p-event/package.json
generated
vendored
Normal file
52
node_modules/bin-wrapper/node_modules/p-event/package.json
generated
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
{
|
||||
"name": "p-event",
|
||||
"version": "2.3.1",
|
||||
"description": "Promisify an event by waiting for it to be emitted",
|
||||
"license": "MIT",
|
||||
"repository": "sindresorhus/p-event",
|
||||
"author": {
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
"url": "sindresorhus.com"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && ava"
|
||||
},
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"keywords": [
|
||||
"promise",
|
||||
"events",
|
||||
"event",
|
||||
"emitter",
|
||||
"eventemitter",
|
||||
"event-emitter",
|
||||
"emit",
|
||||
"emits",
|
||||
"listener",
|
||||
"promisify",
|
||||
"addlistener",
|
||||
"addeventlistener",
|
||||
"wait",
|
||||
"waits",
|
||||
"on",
|
||||
"browser",
|
||||
"dom",
|
||||
"async",
|
||||
"await",
|
||||
"promises",
|
||||
"bluebird"
|
||||
],
|
||||
"dependencies": {
|
||||
"p-timeout": "^2.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"ava": "^1.2.1",
|
||||
"delay": "^4.1.0",
|
||||
"xo": "^0.24.0"
|
||||
}
|
||||
}
|
||||
315
node_modules/bin-wrapper/node_modules/p-event/readme.md
generated
vendored
Normal file
315
node_modules/bin-wrapper/node_modules/p-event/readme.md
generated
vendored
Normal file
@@ -0,0 +1,315 @@
|
||||
# p-event [](https://travis-ci.org/sindresorhus/p-event)
|
||||
|
||||
> Promisify an event by waiting for it to be emitted
|
||||
|
||||
Useful when you need only one event emission and want to use it with promises or await it in an async function.
|
||||
|
||||
It's works with any event API in Node.js and the browser (using a bundler).
|
||||
|
||||
If you want multiple individual events as they are emitted, you can use the `pEvent.iterator()` method. [Observables](https://medium.com/@benlesh/learning-observable-by-building-observable-d5da57405d87) can be useful too.
|
||||
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install p-event
|
||||
```
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
In Node.js:
|
||||
|
||||
```js
|
||||
const pEvent = require('p-event');
|
||||
const emitter = require('./some-event-emitter');
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
const result = await pEvent(emitter, 'finish');
|
||||
|
||||
// `emitter` emitted a `finish` event
|
||||
console.log(result);
|
||||
} catch (error) {
|
||||
// `emitter` emitted an `error` event
|
||||
console.error(error);
|
||||
}
|
||||
})();
|
||||
```
|
||||
|
||||
In the browser:
|
||||
|
||||
```js
|
||||
const pEvent = require('p-event');
|
||||
|
||||
(async () => {
|
||||
await pEvent(document, 'DOMContentLoaded');
|
||||
console.log('😎');
|
||||
})();
|
||||
```
|
||||
|
||||
Async iteration:
|
||||
|
||||
```js
|
||||
const pEvent = require('p-event');
|
||||
const emitter = require('./some-event-emitter');
|
||||
|
||||
(async () => {
|
||||
const asyncIterator = pEvent.iterator(emitter, 'data', {
|
||||
resolutionEvents: ['finish']
|
||||
});
|
||||
|
||||
for await (const event of asyncIterator) {
|
||||
console.log(event);
|
||||
}
|
||||
})();
|
||||
```
|
||||
|
||||
|
||||
## API
|
||||
|
||||
### pEvent(emitter, event, [options])
|
||||
### pEvent(emitter, event, filter)
|
||||
|
||||
Returns a `Promise` that is fulfilled when `emitter` emits an event matching `event`, or rejects if `emitter` emits any of the events defined in the `rejectionEvents` option.
|
||||
|
||||
**Note**: `event` is a string for a single event type, for example, `'data'`. To listen on multiple
|
||||
events, pass an array of strings, such as `['started', 'stopped']`.
|
||||
|
||||
The returned promise has a `.cancel()` method, which when called, removes the event listeners and causes the promise to never be settled.
|
||||
|
||||
#### emitter
|
||||
|
||||
Type: `Object`
|
||||
|
||||
Event emitter object.
|
||||
|
||||
Should have either a `.on()`/`.addListener()`/`.addEventListener()` and `.off()`/`.removeListener()`/`.removeEventListener()` method, like the [Node.js `EventEmitter`](https://nodejs.org/api/events.html) and [DOM events](https://developer.mozilla.org/en-US/docs/Web/Events).
|
||||
|
||||
#### event
|
||||
|
||||
Type: `string | string[]`
|
||||
|
||||
Name of the event or events to listen to.
|
||||
|
||||
If the same event is defined both here and in `rejectionEvents`, this one takes priority.
|
||||
|
||||
#### options
|
||||
|
||||
Type: `Object`
|
||||
|
||||
##### rejectionEvents
|
||||
|
||||
Type: `string[]`<br>
|
||||
Default: `['error']`
|
||||
|
||||
Events that will reject the promise.
|
||||
|
||||
##### multiArgs
|
||||
|
||||
Type: `boolean`<br>
|
||||
Default: `false`
|
||||
|
||||
By default, the promisified function will only return the first argument from the event callback, which works fine for most APIs. This option can be useful for APIs that return multiple arguments in the callback. Turning this on will make it return an array of all arguments from the callback, instead of just the first argument. This also applies to rejections.
|
||||
|
||||
Example:
|
||||
|
||||
```js
|
||||
const pEvent = require('p-event');
|
||||
const emitter = require('./some-event-emitter');
|
||||
|
||||
(async () => {
|
||||
const [foo, bar] = await pEvent(emitter, 'finish', {multiArgs: true});
|
||||
})();
|
||||
```
|
||||
|
||||
##### timeout
|
||||
|
||||
Type: `number`<br>
|
||||
Default: `Infinity`
|
||||
|
||||
Time in milliseconds before timing out.
|
||||
|
||||
##### filter
|
||||
|
||||
Type: `Function`
|
||||
|
||||
Filter function for accepting an event.
|
||||
|
||||
```js
|
||||
const pEvent = require('p-event');
|
||||
const emitter = require('./some-event-emitter');
|
||||
|
||||
(async () => {
|
||||
const result = await pEvent(emitter, '🦄', value => value > 3);
|
||||
// Do something with first 🦄 event with a value greater than 3
|
||||
})();
|
||||
```
|
||||
|
||||
### pEvent.multiple(emitter, event, options)
|
||||
|
||||
Wait for multiple event emissions. Returns an array.
|
||||
|
||||
This method has the same arguments and options as `pEvent()` with the addition of the following options:
|
||||
|
||||
#### options
|
||||
|
||||
Type: `Object`
|
||||
|
||||
##### count
|
||||
|
||||
*Required*<br>
|
||||
Type: `number`
|
||||
|
||||
The number of times the event needs to be emitted before the promise resolves.
|
||||
|
||||
##### resolveImmediately
|
||||
|
||||
Type: `boolean`<br>
|
||||
Default: `false`
|
||||
|
||||
Whether to resolve the promise immediately. Emitting one of the `rejectionEvents` won't throw an error.
|
||||
|
||||
**Note**: The returned array will be mutated when an event is emitted.
|
||||
|
||||
Example:
|
||||
|
||||
```js
|
||||
const emitter = new EventEmitter();
|
||||
|
||||
const promise = pEvent.multiple(emitter, 'hello', {
|
||||
resolveImmediately: true,
|
||||
count: Infinity
|
||||
});
|
||||
|
||||
const result = await promise;
|
||||
console.log(result);
|
||||
//=> []
|
||||
|
||||
emitter.emit('hello', 'Jack');
|
||||
console.log(result);
|
||||
//=> ['Jack']
|
||||
|
||||
emitter.emit('hello', 'Mark');
|
||||
console.log(result);
|
||||
//=> ['Jack', 'Mark']
|
||||
|
||||
// Stops listening
|
||||
emitter.emit('error', new Error('😿'));
|
||||
|
||||
emitter.emit('hello', 'John');
|
||||
console.log(result);
|
||||
//=> ['Jack', 'Mark']
|
||||
```
|
||||
|
||||
### pEvent.iterator(emitter, event, [options])
|
||||
### pEvent.iterator(emitter, event, filter)
|
||||
|
||||
Returns an [async iterator](http://2ality.com/2016/10/asynchronous-iteration.html) that lets you asynchronously iterate over events of `event` emitted from `emitter`. The iterator ends when `emitter` emits an event matching any of the events defined in `resolutionEvents`, or rejects if `emitter` emits any of the events defined in the `rejectionEvents` option.
|
||||
|
||||
This method has the same arguments and options as `pEvent()` with the addition of the following options:
|
||||
|
||||
#### options
|
||||
|
||||
Type: `Object`
|
||||
|
||||
##### limit
|
||||
|
||||
Type: `number` *(non-negative integer)*<br>
|
||||
Default: `Infinity`
|
||||
|
||||
Maximum number of events for the iterator before it ends. When the limit is reached, the iterator will be marked as `done`. This option is useful to paginate events, for example, fetching 10 events per page.
|
||||
|
||||
##### resolutionEvents
|
||||
|
||||
Type: `string[]`<br>
|
||||
Default: `[]`
|
||||
|
||||
Events that will end the iterator.
|
||||
|
||||
|
||||
## Before and after
|
||||
|
||||
```js
|
||||
const fs = require('fs');
|
||||
|
||||
function getOpenReadStream(file, callback) {
|
||||
const stream = fs.createReadStream(file);
|
||||
|
||||
stream.on('open', () => {
|
||||
callback(null, stream);
|
||||
});
|
||||
|
||||
stream.on('error', error => {
|
||||
callback(error);
|
||||
});
|
||||
}
|
||||
|
||||
getOpenReadStream('unicorn.txt', (error, stream) => {
|
||||
if (error) {
|
||||
console.error(error);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('File descriptor:', stream.fd);
|
||||
stream.pipe(process.stdout);
|
||||
});
|
||||
```
|
||||
|
||||
```js
|
||||
const fs = require('fs');
|
||||
const pEvent = require('p-event');
|
||||
|
||||
async function getOpenReadStream(file) {
|
||||
const stream = fs.createReadStream(file);
|
||||
await pEvent(stream, 'open');
|
||||
return stream;
|
||||
}
|
||||
|
||||
(async () => {
|
||||
const stream = await getOpenReadStream('unicorn.txt');
|
||||
console.log('File descriptor:', stream.fd);
|
||||
stream.pipe(process.stdout);
|
||||
})().catch(console.error);
|
||||
```
|
||||
|
||||
|
||||
## Tip
|
||||
|
||||
### Dealing with calls that resolve with an error code
|
||||
|
||||
Some functions might use a single event for success and for certain errors. Promises make it easy to have combined error handler for both error events and successes containing values which represent errors.
|
||||
|
||||
```js
|
||||
const pEvent = require('p-event');
|
||||
const emitter = require('./some-event-emitter');
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
const result = await pEvent(emitter, 'finish');
|
||||
|
||||
if (result === 'unwanted result') {
|
||||
throw new Error('Emitter finished with an error');
|
||||
}
|
||||
|
||||
// `emitter` emitted a `finish` event with an acceptable value
|
||||
console.log(result);
|
||||
} catch (error) {
|
||||
// `emitter` emitted an `error` event or
|
||||
// emitted a `finish` with 'unwanted result'
|
||||
console.error(error);
|
||||
}
|
||||
})();
|
||||
```
|
||||
|
||||
|
||||
## Related
|
||||
|
||||
- [pify](https://github.com/sindresorhus/pify) - Promisify a callback-style function
|
||||
- [p-map](https://github.com/sindresorhus/p-map) - Map over promises concurrently
|
||||
- [More…](https://github.com/sindresorhus/promise-fun)
|
||||
|
||||
|
||||
## License
|
||||
|
||||
MIT © [Sindre Sorhus](https://sindresorhus.com)
|
||||
44
node_modules/bin-wrapper/node_modules/p-timeout/index.js
generated
vendored
Normal file
44
node_modules/bin-wrapper/node_modules/p-timeout/index.js
generated
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
'use strict';
|
||||
const pFinally = require('p-finally');
|
||||
|
||||
class TimeoutError extends Error {
|
||||
constructor(message) {
|
||||
super(message);
|
||||
this.name = 'TimeoutError';
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = (promise, ms, fallback) => new Promise((resolve, reject) => {
|
||||
if (typeof ms !== 'number' || ms < 0) {
|
||||
throw new TypeError('Expected `ms` to be a positive number');
|
||||
}
|
||||
|
||||
const timer = setTimeout(() => {
|
||||
if (typeof fallback === 'function') {
|
||||
try {
|
||||
resolve(fallback());
|
||||
} catch (err) {
|
||||
reject(err);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const message = typeof fallback === 'string' ? fallback : `Promise timed out after ${ms} milliseconds`;
|
||||
const err = fallback instanceof Error ? fallback : new TimeoutError(message);
|
||||
|
||||
if (typeof promise.cancel === 'function') {
|
||||
promise.cancel();
|
||||
}
|
||||
|
||||
reject(err);
|
||||
}, ms);
|
||||
|
||||
pFinally(
|
||||
promise.then(resolve, reject),
|
||||
() => {
|
||||
clearTimeout(timer);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
module.exports.TimeoutError = TimeoutError;
|
||||
9
node_modules/bin-wrapper/node_modules/p-timeout/license
generated
vendored
Normal file
9
node_modules/bin-wrapper/node_modules/p-timeout/license
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
||||
|
||||
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.
|
||||
43
node_modules/bin-wrapper/node_modules/p-timeout/package.json
generated
vendored
Normal file
43
node_modules/bin-wrapper/node_modules/p-timeout/package.json
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
{
|
||||
"name": "p-timeout",
|
||||
"version": "2.0.1",
|
||||
"description": "Timeout a promise after a specified amount of time",
|
||||
"license": "MIT",
|
||||
"repository": "sindresorhus/p-timeout",
|
||||
"author": {
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
"url": "sindresorhus.com"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && ava"
|
||||
},
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"keywords": [
|
||||
"promise",
|
||||
"timeout",
|
||||
"error",
|
||||
"invalidate",
|
||||
"async",
|
||||
"await",
|
||||
"promises",
|
||||
"time",
|
||||
"out",
|
||||
"cancel",
|
||||
"bluebird"
|
||||
],
|
||||
"dependencies": {
|
||||
"p-finally": "^1.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"ava": "*",
|
||||
"delay": "^2.0.0",
|
||||
"p-cancelable": "^0.3.0",
|
||||
"xo": "*"
|
||||
}
|
||||
}
|
||||
89
node_modules/bin-wrapper/node_modules/p-timeout/readme.md
generated
vendored
Normal file
89
node_modules/bin-wrapper/node_modules/p-timeout/readme.md
generated
vendored
Normal file
@@ -0,0 +1,89 @@
|
||||
# p-timeout [](https://travis-ci.org/sindresorhus/p-timeout)
|
||||
|
||||
> Timeout a promise after a specified amount of time
|
||||
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install p-timeout
|
||||
```
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const delay = require('delay');
|
||||
const pTimeout = require('p-timeout');
|
||||
|
||||
const delayedPromise = delay(200);
|
||||
|
||||
pTimeout(delayedPromise, 50).then(() => 'foo');
|
||||
//=> [TimeoutError: Promise timed out after 50 milliseconds]
|
||||
```
|
||||
|
||||
|
||||
## API
|
||||
|
||||
### pTimeout(input, ms, [message | fallback])
|
||||
|
||||
Returns a decorated `input` that times out after `ms` time.
|
||||
|
||||
If you pass in a cancelable promise, specifically a promise with a `.cancel()` method, that method will be called when the `pTimeout` promise times out.
|
||||
|
||||
#### input
|
||||
|
||||
Type: `Promise`
|
||||
|
||||
Promise to decorate.
|
||||
|
||||
#### ms
|
||||
|
||||
Type: `number`
|
||||
|
||||
Milliseconds before timing out.
|
||||
|
||||
#### message
|
||||
|
||||
Type: `string` `Error`<br>
|
||||
Default: `'Promise timed out after 50 milliseconds'`
|
||||
|
||||
Specify a custom error message or error.
|
||||
|
||||
If you do a custom error, it's recommended to sub-class `pTimeout.TimeoutError`.
|
||||
|
||||
#### fallback
|
||||
|
||||
Type: `Function`
|
||||
|
||||
Do something other than rejecting with an error on timeout.
|
||||
|
||||
You could for example retry:
|
||||
|
||||
```js
|
||||
const delay = require('delay');
|
||||
const pTimeout = require('p-timeout');
|
||||
|
||||
const delayedPromise = () => delay(200);
|
||||
|
||||
pTimeout(delayedPromise(), 50, () => {
|
||||
return pTimeout(delayedPromise(), 300);
|
||||
});
|
||||
```
|
||||
|
||||
### pTimeout.TimeoutError
|
||||
|
||||
Exposed for instance checking and sub-classing.
|
||||
|
||||
|
||||
## Related
|
||||
|
||||
- [delay](https://github.com/sindresorhus/delay) - Delay a promise a specified amount of time
|
||||
- [p-min-delay](https://github.com/sindresorhus/p-min-delay) - Delay a promise a minimum amount of time
|
||||
- [p-retry](https://github.com/sindresorhus/p-retry) - Retry a promise-returning function
|
||||
- [More…](https://github.com/sindresorhus/promise-fun)
|
||||
|
||||
|
||||
## License
|
||||
|
||||
MIT © [Sindre Sorhus](https://sindresorhus.com)
|
||||
15
node_modules/bin-wrapper/node_modules/prepend-http/index.js
generated
vendored
Normal file
15
node_modules/bin-wrapper/node_modules/prepend-http/index.js
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
'use strict';
|
||||
module.exports = (url, opts) => {
|
||||
if (typeof url !== 'string') {
|
||||
throw new TypeError(`Expected \`url\` to be of type \`string\`, got \`${typeof url}\``);
|
||||
}
|
||||
|
||||
url = url.trim();
|
||||
opts = Object.assign({https: false}, opts);
|
||||
|
||||
if (/^\.*\/|^(?!localhost)\w+:/.test(url)) {
|
||||
return url;
|
||||
}
|
||||
|
||||
return url.replace(/^(?!(?:\w+:)?\/\/)/, opts.https ? 'https://' : 'http://');
|
||||
};
|
||||
9
node_modules/bin-wrapper/node_modules/prepend-http/license
generated
vendored
Normal file
9
node_modules/bin-wrapper/node_modules/prepend-http/license
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
||||
|
||||
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.
|
||||
35
node_modules/bin-wrapper/node_modules/prepend-http/package.json
generated
vendored
Normal file
35
node_modules/bin-wrapper/node_modules/prepend-http/package.json
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"name": "prepend-http",
|
||||
"version": "2.0.0",
|
||||
"description": "Prepend `http://` to humanized URLs like todomvc.com and localhost",
|
||||
"license": "MIT",
|
||||
"repository": "sindresorhus/prepend-http",
|
||||
"author": {
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
"url": "sindresorhus.com"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && ava"
|
||||
},
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"keywords": [
|
||||
"prepend",
|
||||
"protocol",
|
||||
"scheme",
|
||||
"url",
|
||||
"uri",
|
||||
"http",
|
||||
"https",
|
||||
"humanized"
|
||||
],
|
||||
"devDependencies": {
|
||||
"ava": "*",
|
||||
"xo": "*"
|
||||
}
|
||||
}
|
||||
56
node_modules/bin-wrapper/node_modules/prepend-http/readme.md
generated
vendored
Normal file
56
node_modules/bin-wrapper/node_modules/prepend-http/readme.md
generated
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
# prepend-http [](https://travis-ci.org/sindresorhus/prepend-http)
|
||||
|
||||
> Prepend `http://` to humanized URLs like `todomvc.com` and `localhost`
|
||||
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install prepend-http
|
||||
```
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const prependHttp = require('prepend-http');
|
||||
|
||||
prependHttp('todomvc.com');
|
||||
//=> 'http://todomvc.com'
|
||||
|
||||
prependHttp('localhost');
|
||||
//=> 'http://localhost'
|
||||
|
||||
prependHttp('http://todomvc.com');
|
||||
//=> 'http://todomvc.com'
|
||||
|
||||
prependHttp('todomvc.com', {https: true});
|
||||
//=> 'https://todomvc.com'
|
||||
```
|
||||
|
||||
|
||||
## API
|
||||
|
||||
### prependHttp(url, [options])
|
||||
|
||||
#### url
|
||||
|
||||
Type: `string`
|
||||
|
||||
URL to prepend `http://` on.
|
||||
|
||||
#### options
|
||||
|
||||
Type: `Object`
|
||||
|
||||
##### https
|
||||
|
||||
Type: `boolean`<br>
|
||||
Default: `false`
|
||||
|
||||
Prepend `https://` instead of `http://`.
|
||||
|
||||
|
||||
## License
|
||||
|
||||
MIT © [Sindre Sorhus](https://sindresorhus.com)
|
||||
12
node_modules/bin-wrapper/node_modules/url-parse-lax/index.js
generated
vendored
Normal file
12
node_modules/bin-wrapper/node_modules/url-parse-lax/index.js
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
'use strict';
|
||||
const url = require('url');
|
||||
const prependHttp = require('prepend-http');
|
||||
|
||||
module.exports = (input, options) => {
|
||||
if (typeof input !== 'string') {
|
||||
throw new TypeError(`Expected \`url\` to be of type \`string\`, got \`${typeof input}\` instead.`);
|
||||
}
|
||||
|
||||
const finalUrl = prependHttp(input, Object.assign({https: true}, options));
|
||||
return url.parse(finalUrl);
|
||||
};
|
||||
9
node_modules/bin-wrapper/node_modules/url-parse-lax/license
generated
vendored
Normal file
9
node_modules/bin-wrapper/node_modules/url-parse-lax/license
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
||||
|
||||
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.
|
||||
42
node_modules/bin-wrapper/node_modules/url-parse-lax/package.json
generated
vendored
Normal file
42
node_modules/bin-wrapper/node_modules/url-parse-lax/package.json
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
{
|
||||
"name": "url-parse-lax",
|
||||
"version": "3.0.0",
|
||||
"description": "Lax url.parse() with support for protocol-less URLs & IPs",
|
||||
"license": "MIT",
|
||||
"repository": "sindresorhus/url-parse-lax",
|
||||
"author": {
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
"url": "sindresorhus.com"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && ava"
|
||||
},
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"keywords": [
|
||||
"url",
|
||||
"uri",
|
||||
"parse",
|
||||
"parser",
|
||||
"loose",
|
||||
"lax",
|
||||
"protocol",
|
||||
"less",
|
||||
"protocol-less",
|
||||
"ip",
|
||||
"ipv4",
|
||||
"ipv6"
|
||||
],
|
||||
"dependencies": {
|
||||
"prepend-http": "^2.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"ava": "*",
|
||||
"xo": "*"
|
||||
}
|
||||
}
|
||||
127
node_modules/bin-wrapper/node_modules/url-parse-lax/readme.md
generated
vendored
Normal file
127
node_modules/bin-wrapper/node_modules/url-parse-lax/readme.md
generated
vendored
Normal file
@@ -0,0 +1,127 @@
|
||||
# url-parse-lax [](https://travis-ci.org/sindresorhus/url-parse-lax)
|
||||
|
||||
> Lax [`url.parse()`](https://nodejs.org/docs/latest/api/url.html#url_url_parse_urlstr_parsequerystring_slashesdenotehost) with support for protocol-less URLs & IPs
|
||||
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install url-parse-lax
|
||||
```
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const urlParseLax = require('url-parse-lax');
|
||||
|
||||
urlParseLax('sindresorhus.com');
|
||||
/*
|
||||
{
|
||||
protocol: 'https:',
|
||||
slashes: true,
|
||||
auth: null,
|
||||
host: 'sindresorhus.com',
|
||||
port: null,
|
||||
hostname: 'sindresorhus.com',
|
||||
hash: null,
|
||||
search: null,
|
||||
query: null,
|
||||
pathname: '/',
|
||||
path: '/',
|
||||
href: 'https://sindresorhus.com/'
|
||||
}
|
||||
*/
|
||||
|
||||
urlParseLax('[2001:db8::]:8000');
|
||||
/*
|
||||
{
|
||||
protocol: null,
|
||||
slashes: true,
|
||||
auth: null,
|
||||
host: '[2001:db8::]:8000',
|
||||
port: '8000',
|
||||
hostname: '2001:db8::',
|
||||
hash: null,
|
||||
search: null,
|
||||
query: null,
|
||||
pathname: '/',
|
||||
path: '/',
|
||||
href: 'http://[2001:db8::]:8000/'
|
||||
}
|
||||
*/
|
||||
```
|
||||
|
||||
And with the built-in `url.parse()`:
|
||||
|
||||
```js
|
||||
const url = require('url');
|
||||
|
||||
url.parse('sindresorhus.com');
|
||||
/*
|
||||
{
|
||||
protocol: null,
|
||||
slashes: null,
|
||||
auth: null,
|
||||
host: null,
|
||||
port: null,
|
||||
hostname: null,
|
||||
hash: null,
|
||||
search: null,
|
||||
query: null,
|
||||
pathname: 'sindresorhus',
|
||||
path: 'sindresorhus',
|
||||
href: 'sindresorhus'
|
||||
}
|
||||
*/
|
||||
|
||||
url.parse('[2001:db8::]:8000');
|
||||
/*
|
||||
{
|
||||
protocol: null,
|
||||
slashes: null,
|
||||
auth: null,
|
||||
host: null,
|
||||
port: null,
|
||||
hostname: null,
|
||||
hash: null,
|
||||
search: null,
|
||||
query: null,
|
||||
pathname: '[2001:db8::]:8000',
|
||||
path: '[2001:db8::]:8000',
|
||||
href: '[2001:db8::]:8000'
|
||||
}
|
||||
*/
|
||||
```
|
||||
|
||||
|
||||
## API
|
||||
|
||||
### urlParseLax(url, [options])
|
||||
|
||||
#### url
|
||||
|
||||
Type: `string`
|
||||
|
||||
URL to parse.
|
||||
|
||||
#### options
|
||||
|
||||
Type: `Object`
|
||||
|
||||
##### https
|
||||
|
||||
Type: `boolean`<br>
|
||||
Default: `true`
|
||||
|
||||
Prepend `https://` instead of `http://` to protocol-less URLs.
|
||||
|
||||
|
||||
## Related
|
||||
|
||||
- [url-format-lax](https://github.com/sindresorhus/url-format-lax) - Lax `url.format()` that formats a hostname and port into IPv6-compatible socket form of `hostname:port`
|
||||
|
||||
|
||||
## License
|
||||
|
||||
MIT © [Sindre Sorhus](https://sindresorhus.com)
|
||||
80
node_modules/bin-wrapper/package.json
generated
vendored
80
node_modules/bin-wrapper/package.json
generated
vendored
@@ -1,40 +1,44 @@
|
||||
{
|
||||
"name": "bin-wrapper",
|
||||
"version": "3.0.2",
|
||||
"description": "Binary wrapper that makes your programs seamlessly available as local dependencies",
|
||||
"license": "MIT",
|
||||
"repository": "kevva/bin-wrapper",
|
||||
"author": {
|
||||
"name": "Kevin Mårtensson",
|
||||
"email": "kevinmartensson@gmail.com",
|
||||
"url": "https://github.com/kevva"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "node test/test.js"
|
||||
},
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"keywords": [
|
||||
"bin",
|
||||
"check",
|
||||
"local",
|
||||
"wrapper"
|
||||
],
|
||||
"dependencies": {
|
||||
"bin-check": "^2.0.0",
|
||||
"bin-version-check": "^2.1.0",
|
||||
"download": "^4.0.0",
|
||||
"each-async": "^1.1.1",
|
||||
"lazy-req": "^1.0.0",
|
||||
"os-filter-obj": "^1.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"ava": "^0.0.4",
|
||||
"nock": "^2.6.0",
|
||||
"rimraf": "^2.2.8"
|
||||
}
|
||||
"name": "bin-wrapper",
|
||||
"version": "4.1.0",
|
||||
"description": "Binary wrapper that makes your programs seamlessly available as local dependencies",
|
||||
"license": "MIT",
|
||||
"repository": "kevva/bin-wrapper",
|
||||
"author": {
|
||||
"name": "Kevin Mårtensson",
|
||||
"email": "kevinmartensson@gmail.com",
|
||||
"url": "https://github.com/kevva"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && ava"
|
||||
},
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"keywords": [
|
||||
"bin",
|
||||
"check",
|
||||
"local",
|
||||
"wrapper"
|
||||
],
|
||||
"dependencies": {
|
||||
"bin-check": "^4.1.0",
|
||||
"bin-version-check": "^4.0.0",
|
||||
"download": "^7.1.0",
|
||||
"import-lazy": "^3.1.0",
|
||||
"os-filter-obj": "^2.0.0",
|
||||
"pify": "^4.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"ava": "*",
|
||||
"executable": "^4.1.1",
|
||||
"nock": "^10.0.2",
|
||||
"path-exists": "^3.0.0",
|
||||
"rimraf": "^2.6.2",
|
||||
"tempy": "^0.2.1",
|
||||
"xo": "*"
|
||||
}
|
||||
}
|
||||
|
||||
64
node_modules/bin-wrapper/readme.md
generated
vendored
64
node_modules/bin-wrapper/readme.md
generated
vendored
@@ -1,4 +1,4 @@
|
||||
# bin-wrapper [](https://travis-ci.org/kevva/bin-wrapper)
|
||||
# bin-wrapper [](https://travis-ci.org/kevva/bin-wrapper)
|
||||
|
||||
> Binary wrapper that makes your programs seamlessly available as local dependencies
|
||||
|
||||
@@ -6,52 +6,58 @@
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install --save bin-wrapper
|
||||
$ npm install bin-wrapper
|
||||
```
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
var BinWrapper = require('bin-wrapper');
|
||||
const BinWrapper = require('bin-wrapper');
|
||||
|
||||
var base = 'https://github.com/imagemin/gifsicle-bin/raw/master/vendor';
|
||||
var bin = new BinWrapper()
|
||||
.src(base + '/osx/gifsicle', 'darwin')
|
||||
.src(base + '/linux/x64/gifsicle', 'linux', 'x64')
|
||||
.src(base + '/win/x64/gifsicle.exe', 'win32', 'x64')
|
||||
const base = 'https://github.com/imagemin/gifsicle-bin/raw/master/vendor';
|
||||
const bin = new BinWrapper()
|
||||
.src(`${base}/macos/gifsicle`, 'darwin')
|
||||
.src(`${base}/linux/x64/gifsicle`, 'linux', 'x64')
|
||||
.src(`${base}/win/x64/gifsicle.exe`, 'win32', 'x64')
|
||||
.dest(path.join('vendor'))
|
||||
.use(process.platform === 'win32' ? 'gifsicle.exe' : 'gifsicle')
|
||||
.version('>=1.71');
|
||||
|
||||
bin.run(['--version'], function (err) {
|
||||
(async () => {
|
||||
await bin.run(['--version']);
|
||||
console.log('gifsicle is working');
|
||||
});
|
||||
})();
|
||||
```
|
||||
|
||||
Get the path to your binary with `bin.path()`:
|
||||
|
||||
```js
|
||||
console.log(bin.path()); // => path/to/vendor/gifsicle
|
||||
console.log(bin.path());
|
||||
//=> 'path/to/vendor/gifsicle'
|
||||
```
|
||||
|
||||
|
||||
## API
|
||||
|
||||
### new BinWrapper(options)
|
||||
### `new BinWrapper(options)`
|
||||
|
||||
Creates a new `BinWrapper` instance.
|
||||
|
||||
#### options.skipCheck
|
||||
#### options
|
||||
|
||||
Type: `boolean`
|
||||
Type: `Object`
|
||||
|
||||
##### skipCheck
|
||||
|
||||
Type: `boolean`<br>
|
||||
Default: `false`
|
||||
|
||||
Whether to skip the binary check or not.
|
||||
|
||||
#### options.strip
|
||||
##### strip
|
||||
|
||||
Type: `number`
|
||||
Type: `number`<br>
|
||||
Default: `1`
|
||||
|
||||
Strip a number of leading paths from file names on extraction.
|
||||
@@ -78,17 +84,17 @@ Type: `string`
|
||||
|
||||
Tie the source to a specific arch.
|
||||
|
||||
### .dest(dest)
|
||||
### .dest(destination)
|
||||
|
||||
#### dest
|
||||
#### destination
|
||||
|
||||
Type: `string`
|
||||
|
||||
Accepts a path which the files will be downloaded to.
|
||||
|
||||
### .use(bin)
|
||||
### .use(binary)
|
||||
|
||||
#### bin
|
||||
#### binary
|
||||
|
||||
Type: `string`
|
||||
|
||||
@@ -104,28 +110,22 @@ Returns the full path to your binary.
|
||||
|
||||
Type: `string`
|
||||
|
||||
Define a [semver range](https://github.com/isaacs/node-semver#ranges) to check
|
||||
Define a [semver range](https://github.com/isaacs/node-semver#ranges) to check
|
||||
the binary against.
|
||||
|
||||
### .run([cmd], callback)
|
||||
### .run([arguments])
|
||||
|
||||
Runs the search for the binary. If no binary is found it will download the file
|
||||
Runs the search for the binary. If no binary is found it will download the file
|
||||
using the URL provided in `.src()`.
|
||||
|
||||
#### cmd
|
||||
#### arguments
|
||||
|
||||
Type: `array`
|
||||
Type: `Array`<br>
|
||||
Default: `['--version']`
|
||||
|
||||
Command to run the binary with. If it exits with code `0` it means that the
|
||||
Command to run the binary with. If it exits with code `0` it means that the
|
||||
binary is working.
|
||||
|
||||
#### callback(err)
|
||||
|
||||
Type: `function`
|
||||
|
||||
Returns nothing but a possible error.
|
||||
|
||||
|
||||
## License
|
||||
|
||||
|
||||
Reference in New Issue
Block a user