Removing Current
This commit is contained in:
1 parent
d6c5e91290
commit
a4ed878fcd
4379 files changed
No files matched your search
+51
@@ -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
@@ -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}));
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
{
|
||||
"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
|
||||
}
|
||||
|
||||
,"_resolved": "https://registry.npmjs.org/get-stream/-/get-stream-3.0.0.tgz"
|
||||
,"_integrity": "sha1-jpQ9E1jcN1VQVOy+LtsFqhdO3hQ="
|
||||
,"_from": "get-stream@^3.0.0"
|
||||
}
|
||||
+479
@@ -0,0 +1,479 @@
|
||||
'use strict';
|
||||
const EventEmitter = require('events');
|
||||
const http = require('http');
|
||||
const https = require('https');
|
||||
const PassThrough = require('stream').PassThrough;
|
||||
const urlLib = require('url');
|
||||
const querystring = require('querystring');
|
||||
const duplexer3 = require('duplexer3');
|
||||
const isStream = require('is-stream');
|
||||
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 isRetryAllowed = require('is-retry-allowed');
|
||||
const Buffer = require('safe-buffer').Buffer;
|
||||
const isURL = require('isurl');
|
||||
const isPlainObj = require('is-plain-obj');
|
||||
const PCancelable = require('p-cancelable');
|
||||
const pTimeout = require('p-timeout');
|
||||
const pkg = require('./package');
|
||||
|
||||
const getMethodRedirectCodes = new Set([300, 301, 302, 303, 304, 305, 307, 308]);
|
||||
const allMethodRedirectCodes = new Set([300, 303, 307, 308]);
|
||||
|
||||
function requestAsEventEmitter(opts) {
|
||||
opts = opts || {};
|
||||
|
||||
const ee = new EventEmitter();
|
||||
const requestUrl = opts.href || urlLib.resolve(urlLib.format(opts), opts.path);
|
||||
const redirects = [];
|
||||
let retryCount = 0;
|
||||
let redirectUrl;
|
||||
|
||||
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 (opts.useElectronNet && process.versions.electron) {
|
||||
const electron = require('electron');
|
||||
fn = electron.net || electron.remote.net;
|
||||
}
|
||||
|
||||
const req = fn.request(opts, res => {
|
||||
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(() => {
|
||||
const response = opts.decompress === true &&
|
||||
typeof decompressResponse === 'function' &&
|
||||
req.method !== 'HEAD' ? decompressResponse(res) : res;
|
||||
|
||||
if (!opts.decompress && ['gzip', 'deflate'].indexOf(res.headers['content-encoding']) !== -1) {
|
||||
opts.encoding = null;
|
||||
}
|
||||
|
||||
response.redirectUrls = redirects;
|
||||
|
||||
ee.emit('response', response);
|
||||
});
|
||||
});
|
||||
|
||||
req.once('error', err => {
|
||||
const backoff = opts.retries(++retryCount, err);
|
||||
|
||||
if (backoff) {
|
||||
setTimeout(get, backoff, opts);
|
||||
return;
|
||||
}
|
||||
|
||||
ee.emit('error', new got.RequestError(err, opts));
|
||||
});
|
||||
|
||||
if (opts.gotTimeout) {
|
||||
timedOut(req, opts.gotTimeout);
|
||||
}
|
||||
|
||||
setImmediate(() => {
|
||||
ee.emit('request', req);
|
||||
});
|
||||
};
|
||||
|
||||
setImmediate(() => {
|
||||
get(opts);
|
||||
});
|
||||
return ee;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
return timeoutFn(new PCancelable((onCancel, resolve, reject) => {
|
||||
const ee = requestAsEventEmitter(opts);
|
||||
let cancelOnRequest = false;
|
||||
|
||||
onCancel(() => {
|
||||
cancelOnRequest = true;
|
||||
});
|
||||
|
||||
ee.on('request', req => {
|
||||
if (cancelOnRequest) {
|
||||
req.abort();
|
||||
}
|
||||
|
||||
onCancel(() => {
|
||||
req.abort();
|
||||
});
|
||||
|
||||
if (isStream(opts.body)) {
|
||||
opts.body.pipe(req);
|
||||
opts.body = undefined;
|
||||
return;
|
||||
}
|
||||
|
||||
req.end(opts.body);
|
||||
});
|
||||
|
||||
ee.on('response', res => {
|
||||
const stream = opts.encoding === null ? 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 (e) {
|
||||
if (statusCode >= 200 && statusCode < 300) {
|
||||
throw new got.ParseError(e, statusCode, opts, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (statusCode !== 304 && (statusCode < 200 || statusCode > limitStatusCode)) {
|
||||
throw new got.HTTPError(statusCode, res.headers, opts);
|
||||
}
|
||||
|
||||
resolve(res);
|
||||
})
|
||||
.catch(err => {
|
||||
Object.defineProperty(err, 'response', {value: res});
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
|
||||
ee.on('error', reject);
|
||||
}));
|
||||
}
|
||||
|
||||
function asStream(opts) {
|
||||
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 stream when options.json is used');
|
||||
}
|
||||
|
||||
if (opts.body) {
|
||||
proxy.write = () => {
|
||||
throw new Error('got\'s stream is not writable when options.body is used');
|
||||
};
|
||||
}
|
||||
|
||||
const ee = requestAsEventEmitter(opts);
|
||||
|
||||
ee.on('request', req => {
|
||||
proxy.emit('request', req);
|
||||
|
||||
if (isStream(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.pipe(output);
|
||||
|
||||
if (statusCode !== 304 && (statusCode < 200 || statusCode > 299)) {
|
||||
proxy.emit('error', new got.HTTPError(statusCode, res.headers, opts), null, res);
|
||||
return;
|
||||
}
|
||||
|
||||
proxy.emit('response', res);
|
||||
});
|
||||
|
||||
ee.on('redirect', proxy.emit.bind(proxy, 'redirect'));
|
||||
ee.on('error', proxy.emit.bind(proxy, 'error'));
|
||||
|
||||
return proxy;
|
||||
}
|
||||
|
||||
function normalizeArguments(url, opts) {
|
||||
if (typeof url !== 'string' && typeof url !== 'object') {
|
||||
throw new TypeError(`Parameter \`url\` must be a string or object, not ${typeof url}`);
|
||||
} else if (typeof url === 'string') {
|
||||
url = url.replace(/^unix:/, 'http://$&');
|
||||
url = urlParseLax(url);
|
||||
} else if (isURL.lenient(url)) {
|
||||
url = urlToOptions(url);
|
||||
}
|
||||
|
||||
if (url.auth) {
|
||||
throw new Error('Basic authentication must be done with auth option');
|
||||
}
|
||||
|
||||
opts = Object.assign(
|
||||
{
|
||||
path: '',
|
||||
retries: 2,
|
||||
decompress: true,
|
||||
useElectronNet: true
|
||||
},
|
||||
url,
|
||||
{
|
||||
protocol: url.protocol || 'http:' // Override both null/undefined with default protocol
|
||||
},
|
||||
opts
|
||||
);
|
||||
|
||||
opts.headers = Object.assign({
|
||||
'user-agent': `${pkg.name}/${pkg.version} (https://github.com/sindresorhus/got)`,
|
||||
'accept-encoding': 'gzip,deflate'
|
||||
}, lowercaseKeys(opts.headers));
|
||||
|
||||
const query = opts.query;
|
||||
|
||||
if (query) {
|
||||
if (typeof query !== 'string') {
|
||||
opts.query = querystring.stringify(query);
|
||||
}
|
||||
|
||||
opts.path = `${opts.path.split('?')[0]}?${opts.query}`;
|
||||
delete opts.query;
|
||||
}
|
||||
|
||||
if (opts.json && opts.headers.accept === undefined) {
|
||||
opts.headers.accept = 'application/json';
|
||||
}
|
||||
|
||||
const body = opts.body;
|
||||
if (body !== null && body !== undefined) {
|
||||
const headers = opts.headers;
|
||||
if (!isStream(body) && typeof body !== 'string' && !Buffer.isBuffer(body) && !(opts.form || opts.json)) {
|
||||
throw new TypeError('options.body must be a ReadableStream, string, Buffer or plain Object');
|
||||
}
|
||||
|
||||
const canBodyBeStringified = isPlainObj(body) || Array.isArray(body);
|
||||
if ((opts.form || opts.json) && !canBodyBeStringified) {
|
||||
throw new TypeError('options.body must be a plain Object or Array when options.form or options.json is used');
|
||||
}
|
||||
|
||||
if (isStream(body) && typeof body.getBoundary === 'function') {
|
||||
// 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 (headers['content-length'] === undefined && headers['transfer-encoding'] === undefined && !isStream(body)) {
|
||||
const length = typeof opts.body === 'string' ? Buffer.byteLength(opts.body) : opts.body.length;
|
||||
headers['content-length'] = length;
|
||||
}
|
||||
|
||||
opts.method = (opts.method || 'POST').toUpperCase();
|
||||
} else {
|
||||
opts.method = (opts.method || 'GET').toUpperCase();
|
||||
}
|
||||
|
||||
if (opts.hostname === 'unix') {
|
||||
const matches = /(.+?):(.+)/.exec(opts.path);
|
||||
|
||||
if (matches) {
|
||||
opts.socketPath = matches[1];
|
||||
opts.path = matches[2];
|
||||
opts.host = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof opts.retries !== 'function') {
|
||||
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 (opts.followRedirect === undefined) {
|
||||
opts.followRedirect = true;
|
||||
}
|
||||
|
||||
if (opts.timeout) {
|
||||
if (typeof opts.timeout === 'number') {
|
||||
opts.gotTimeout = {request: opts.timeout};
|
||||
} else {
|
||||
opts.gotTimeout = opts.timeout;
|
||||
}
|
||||
delete opts.timeout;
|
||||
}
|
||||
|
||||
return opts;
|
||||
}
|
||||
|
||||
function got(url, opts) {
|
||||
try {
|
||||
return asPromise(normalizeArguments(url, opts));
|
||||
} 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}));
|
||||
}
|
||||
|
||||
class StdError extends Error {
|
||||
constructor(message, error, opts) {
|
||||
super(message);
|
||||
this.name = 'StdError';
|
||||
|
||||
if (error.code !== undefined) {
|
||||
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
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
got.RequestError = class extends StdError {
|
||||
constructor(error, opts) {
|
||||
super(error.message, error, opts);
|
||||
this.name = 'RequestError';
|
||||
}
|
||||
};
|
||||
|
||||
got.ReadError = class extends StdError {
|
||||
constructor(error, opts) {
|
||||
super(error.message, error, opts);
|
||||
this.name = 'ReadError';
|
||||
}
|
||||
};
|
||||
|
||||
got.ParseError = class extends StdError {
|
||||
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];
|
||||
}
|
||||
};
|
||||
|
||||
got.HTTPError = class extends StdError {
|
||||
constructor(statusCode, headers, opts) {
|
||||
const statusMessage = http.STATUS_CODES[statusCode];
|
||||
super(`Response code ${statusCode} (${statusMessage})`, {}, opts);
|
||||
this.name = 'HTTPError';
|
||||
this.statusCode = statusCode;
|
||||
this.statusMessage = statusMessage;
|
||||
this.headers = headers;
|
||||
}
|
||||
};
|
||||
|
||||
got.MaxRedirectsError = class extends StdError {
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
got.UnsupportedProtocolError = class extends StdError {
|
||||
constructor(opts) {
|
||||
super(`Unsupported protocol "${opts.protocol}"`, {}, opts);
|
||||
this.name = 'UnsupportedProtocolError';
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = got;
|
||||
+120
@@ -0,0 +1,120 @@
|
||||
{
|
||||
"_from": "got@^7.1.0",
|
||||
"_id": "got@7.1.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-Y5WMo7xKKq1muPsxD+KmrR8DH5auG7fBdDVueZwETwV6VytKyU9OX/ddpq2/1hp1vIPvVb4T81dKQz3BivkNLw==",
|
||||
"_location": "/swarm-js/got",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "got@^7.1.0",
|
||||
"name": "got",
|
||||
"escapedName": "got",
|
||||
"rawSpec": "^7.1.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^7.1.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/swarm-js"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/got/-/got-7.1.0.tgz",
|
||||
"_shasum": "05450fd84094e6bbea56f451a43a9c289166385a",
|
||||
"_spec": "got@^7.1.0",
|
||||
"_where": "C:\\Users\\Luis\\source\\repos\\AAMasters\\BackendServers\\node_modules\\swarm-js",
|
||||
"ava": {
|
||||
"concurrency": 4
|
||||
},
|
||||
"browser": {
|
||||
"decompress-response": false
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/sindresorhus/got/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"decompress-response": "^3.2.0",
|
||||
"duplexer3": "^0.1.4",
|
||||
"get-stream": "^3.0.0",
|
||||
"is-plain-obj": "^1.1.0",
|
||||
"is-retry-allowed": "^1.0.0",
|
||||
"is-stream": "^1.0.0",
|
||||
"isurl": "^1.0.0-alpha5",
|
||||
"lowercase-keys": "^1.0.0",
|
||||
"p-cancelable": "^0.3.0",
|
||||
"p-timeout": "^1.1.1",
|
||||
"safe-buffer": "^5.0.1",
|
||||
"timed-out": "^4.0.0",
|
||||
"url-parse-lax": "^1.0.0",
|
||||
"url-to-options": "^1.0.1"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "Simplified HTTP requests",
|
||||
"devDependencies": {
|
||||
"ava": "^0.20.0",
|
||||
"coveralls": "^2.11.4",
|
||||
"form-data": "^2.1.1",
|
||||
"get-port": "^3.0.0",
|
||||
"into-stream": "^3.0.0",
|
||||
"nyc": "^11.0.2",
|
||||
"pem": "^1.4.4",
|
||||
"pify": "^3.0.0",
|
||||
"tempfile": "^2.0.0",
|
||||
"tempy": "^0.1.0",
|
||||
"universal-url": "^1.0.0-alpha",
|
||||
"xo": "^0.18.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
},
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"homepage": "https://github.com/sindresorhus/got#readme",
|
||||
"keywords": [
|
||||
"http",
|
||||
"https",
|
||||
"get",
|
||||
"got",
|
||||
"url",
|
||||
"uri",
|
||||
"request",
|
||||
"util",
|
||||
"utility",
|
||||
"simple",
|
||||
"curl",
|
||||
"wget",
|
||||
"fetch",
|
||||
"net",
|
||||
"network",
|
||||
"electron"
|
||||
],
|
||||
"license": "MIT",
|
||||
"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"
|
||||
}
|
||||
],
|
||||
"name": "got",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/sindresorhus/got.git"
|
||||
},
|
||||
"scripts": {
|
||||
"coveralls": "nyc report --reporter=text-lcov | coveralls",
|
||||
"test": "xo && nyc ava"
|
||||
},
|
||||
"version": "7.1.0"
|
||||
}
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
'use strict';
|
||||
|
||||
class CancelError extends Error {
|
||||
constructor() {
|
||||
super('Promise was canceled');
|
||||
this.name = 'CancelError';
|
||||
}
|
||||
}
|
||||
|
||||
class PCancelable {
|
||||
static fn(fn) {
|
||||
return function () {
|
||||
const args = [].slice.apply(arguments);
|
||||
return new PCancelable((onCancel, resolve, reject) => {
|
||||
args.unshift(onCancel);
|
||||
fn.apply(null, args).then(resolve, reject);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
constructor(executor) {
|
||||
this._pending = true;
|
||||
this._canceled = false;
|
||||
|
||||
this._promise = new Promise((resolve, reject) => {
|
||||
this._reject = reject;
|
||||
|
||||
return executor(
|
||||
fn => {
|
||||
this._cancel = fn;
|
||||
},
|
||||
val => {
|
||||
this._pending = false;
|
||||
resolve(val);
|
||||
},
|
||||
err => {
|
||||
this._pending = false;
|
||||
reject(err);
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
then() {
|
||||
return this._promise.then.apply(this._promise, arguments);
|
||||
}
|
||||
|
||||
catch() {
|
||||
return this._promise.catch.apply(this._promise, arguments);
|
||||
}
|
||||
|
||||
cancel() {
|
||||
if (!this._pending || this._canceled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof this._cancel === 'function') {
|
||||
try {
|
||||
this._cancel();
|
||||
} catch (err) {
|
||||
this._reject(err);
|
||||
}
|
||||
}
|
||||
|
||||
this._canceled = true;
|
||||
this._reject(new CancelError());
|
||||
}
|
||||
|
||||
get canceled() {
|
||||
return this._canceled;
|
||||
}
|
||||
}
|
||||
|
||||
Object.setPrototypeOf(PCancelable.prototype, Promise.prototype);
|
||||
|
||||
module.exports = PCancelable;
|
||||
module.exports.CancelError = CancelError;
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
{
|
||||
"name": "p-cancelable",
|
||||
"version": "0.3.0",
|
||||
"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",
|
||||
"xo": "*"
|
||||
}
|
||||
|
||||
,"_resolved": "https://registry.npmjs.org/p-cancelable/-/p-cancelable-0.3.0.tgz"
|
||||
,"_integrity": "sha512-RVbZPLso8+jFeq1MfNvgXtCRED2raz/dKpacfTNxsx6pLEpEomM7gah6VeHSYV3+vo0OAi4MkArtQcWWXuQoyw=="
|
||||
,"_from": "p-cancelable@^0.3.0"
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
'use strict';
|
||||
module.exports = function (url) {
|
||||
if (typeof url !== 'string') {
|
||||
throw new TypeError('Expected a string, got ' + typeof url);
|
||||
}
|
||||
|
||||
url = url.trim();
|
||||
|
||||
if (/^\.*\/|^(?!localhost)\w+:/.test(url)) {
|
||||
return url;
|
||||
}
|
||||
|
||||
return url.replace(/^(?!(?:\w+:)?\/\/)/, 'http://');
|
||||
};
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
{
|
||||
"name": "prepend-http",
|
||||
"version": "1.0.4",
|
||||
"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": ">=0.10.0"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && ava"
|
||||
},
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"keywords": [
|
||||
"prepend",
|
||||
"protocol",
|
||||
"scheme",
|
||||
"url",
|
||||
"uri",
|
||||
"http",
|
||||
"https",
|
||||
"humanized"
|
||||
],
|
||||
"devDependencies": {
|
||||
"ava": "*",
|
||||
"xo": "*"
|
||||
}
|
||||
|
||||
,"_resolved": "https://registry.npmjs.org/prepend-http/-/prepend-http-1.0.4.tgz"
|
||||
,"_integrity": "sha1-1PRWKwzjaW5BrFLQ4ALlemNdxtw="
|
||||
,"_from": "prepend-http@^1.0.1"
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
'use strict';
|
||||
var url = require('url');
|
||||
var prependHttp = require('prepend-http');
|
||||
|
||||
module.exports = function (x) {
|
||||
var withProtocol = prependHttp(x);
|
||||
var parsed = url.parse(withProtocol);
|
||||
|
||||
if (withProtocol !== x) {
|
||||
parsed.protocol = null;
|
||||
}
|
||||
|
||||
return parsed;
|
||||
};
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
{
|
||||
"name": "url-parse-lax",
|
||||
"version": "1.0.0",
|
||||
"description": "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": ">=0.10.0"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "node test.js"
|
||||
},
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"keywords": [
|
||||
"url",
|
||||
"uri",
|
||||
"parse",
|
||||
"parser",
|
||||
"loose",
|
||||
"lax",
|
||||
"protocol",
|
||||
"less",
|
||||
"protocol-less",
|
||||
"ip",
|
||||
"ipv4",
|
||||
"ipv6"
|
||||
],
|
||||
"dependencies": {
|
||||
"prepend-http": "^1.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"ava": "0.0.4"
|
||||
}
|
||||
|
||||
,"_resolved": "https://registry.npmjs.org/url-parse-lax/-/url-parse-lax-1.0.0.tgz"
|
||||
,"_integrity": "sha1-evjzA2Rem9eaJy56FKxovAYJ2nM="
|
||||
,"_from": "url-parse-lax@^1.0.0"
|
||||
}
|
||||
Reference in new issue
Block a user