mirror of
https://github.com/tvytlx/ai-agent-deep-dive.git
synced 2026-04-09 10:34:48 +08:00
Add extracted source directory and README navigation
This commit is contained in:
156
extracted-source/node_modules/axios/lib/helpers/AxiosTransformStream.js
generated
vendored
Normal file
156
extracted-source/node_modules/axios/lib/helpers/AxiosTransformStream.js
generated
vendored
Normal file
@@ -0,0 +1,156 @@
|
||||
'use strict';
|
||||
|
||||
import stream from 'stream';
|
||||
import utils from '../utils.js';
|
||||
|
||||
const kInternals = Symbol('internals');
|
||||
|
||||
class AxiosTransformStream extends stream.Transform {
|
||||
constructor(options) {
|
||||
options = utils.toFlatObject(
|
||||
options,
|
||||
{
|
||||
maxRate: 0,
|
||||
chunkSize: 64 * 1024,
|
||||
minChunkSize: 100,
|
||||
timeWindow: 500,
|
||||
ticksRate: 2,
|
||||
samplesCount: 15,
|
||||
},
|
||||
null,
|
||||
(prop, source) => {
|
||||
return !utils.isUndefined(source[prop]);
|
||||
}
|
||||
);
|
||||
|
||||
super({
|
||||
readableHighWaterMark: options.chunkSize,
|
||||
});
|
||||
|
||||
const internals = (this[kInternals] = {
|
||||
timeWindow: options.timeWindow,
|
||||
chunkSize: options.chunkSize,
|
||||
maxRate: options.maxRate,
|
||||
minChunkSize: options.minChunkSize,
|
||||
bytesSeen: 0,
|
||||
isCaptured: false,
|
||||
notifiedBytesLoaded: 0,
|
||||
ts: Date.now(),
|
||||
bytes: 0,
|
||||
onReadCallback: null,
|
||||
});
|
||||
|
||||
this.on('newListener', (event) => {
|
||||
if (event === 'progress') {
|
||||
if (!internals.isCaptured) {
|
||||
internals.isCaptured = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
_read(size) {
|
||||
const internals = this[kInternals];
|
||||
|
||||
if (internals.onReadCallback) {
|
||||
internals.onReadCallback();
|
||||
}
|
||||
|
||||
return super._read(size);
|
||||
}
|
||||
|
||||
_transform(chunk, encoding, callback) {
|
||||
const internals = this[kInternals];
|
||||
const maxRate = internals.maxRate;
|
||||
|
||||
const readableHighWaterMark = this.readableHighWaterMark;
|
||||
|
||||
const timeWindow = internals.timeWindow;
|
||||
|
||||
const divider = 1000 / timeWindow;
|
||||
const bytesThreshold = maxRate / divider;
|
||||
const minChunkSize =
|
||||
internals.minChunkSize !== false
|
||||
? Math.max(internals.minChunkSize, bytesThreshold * 0.01)
|
||||
: 0;
|
||||
|
||||
const pushChunk = (_chunk, _callback) => {
|
||||
const bytes = Buffer.byteLength(_chunk);
|
||||
internals.bytesSeen += bytes;
|
||||
internals.bytes += bytes;
|
||||
|
||||
internals.isCaptured && this.emit('progress', internals.bytesSeen);
|
||||
|
||||
if (this.push(_chunk)) {
|
||||
process.nextTick(_callback);
|
||||
} else {
|
||||
internals.onReadCallback = () => {
|
||||
internals.onReadCallback = null;
|
||||
process.nextTick(_callback);
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
const transformChunk = (_chunk, _callback) => {
|
||||
const chunkSize = Buffer.byteLength(_chunk);
|
||||
let chunkRemainder = null;
|
||||
let maxChunkSize = readableHighWaterMark;
|
||||
let bytesLeft;
|
||||
let passed = 0;
|
||||
|
||||
if (maxRate) {
|
||||
const now = Date.now();
|
||||
|
||||
if (!internals.ts || (passed = now - internals.ts) >= timeWindow) {
|
||||
internals.ts = now;
|
||||
bytesLeft = bytesThreshold - internals.bytes;
|
||||
internals.bytes = bytesLeft < 0 ? -bytesLeft : 0;
|
||||
passed = 0;
|
||||
}
|
||||
|
||||
bytesLeft = bytesThreshold - internals.bytes;
|
||||
}
|
||||
|
||||
if (maxRate) {
|
||||
if (bytesLeft <= 0) {
|
||||
// next time window
|
||||
return setTimeout(() => {
|
||||
_callback(null, _chunk);
|
||||
}, timeWindow - passed);
|
||||
}
|
||||
|
||||
if (bytesLeft < maxChunkSize) {
|
||||
maxChunkSize = bytesLeft;
|
||||
}
|
||||
}
|
||||
|
||||
if (maxChunkSize && chunkSize > maxChunkSize && chunkSize - maxChunkSize > minChunkSize) {
|
||||
chunkRemainder = _chunk.subarray(maxChunkSize);
|
||||
_chunk = _chunk.subarray(0, maxChunkSize);
|
||||
}
|
||||
|
||||
pushChunk(
|
||||
_chunk,
|
||||
chunkRemainder
|
||||
? () => {
|
||||
process.nextTick(_callback, null, chunkRemainder);
|
||||
}
|
||||
: _callback
|
||||
);
|
||||
};
|
||||
|
||||
transformChunk(chunk, function transformNextChunk(err, _chunk) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if (_chunk) {
|
||||
transformChunk(_chunk, transformNextChunk);
|
||||
} else {
|
||||
callback(null);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default AxiosTransformStream;
|
||||
62
extracted-source/node_modules/axios/lib/helpers/AxiosURLSearchParams.js
generated
vendored
Normal file
62
extracted-source/node_modules/axios/lib/helpers/AxiosURLSearchParams.js
generated
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
'use strict';
|
||||
|
||||
import toFormData from './toFormData.js';
|
||||
|
||||
/**
|
||||
* It encodes a string by replacing all characters that are not in the unreserved set with
|
||||
* their percent-encoded equivalents
|
||||
*
|
||||
* @param {string} str - The string to encode.
|
||||
*
|
||||
* @returns {string} The encoded string.
|
||||
*/
|
||||
function encode(str) {
|
||||
const charMap = {
|
||||
'!': '%21',
|
||||
"'": '%27',
|
||||
'(': '%28',
|
||||
')': '%29',
|
||||
'~': '%7E',
|
||||
'%20': '+',
|
||||
'%00': '\x00',
|
||||
};
|
||||
return encodeURIComponent(str).replace(/[!'()~]|%20|%00/g, function replacer(match) {
|
||||
return charMap[match];
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* It takes a params object and converts it to a FormData object
|
||||
*
|
||||
* @param {Object<string, any>} params - The parameters to be converted to a FormData object.
|
||||
* @param {Object<string, any>} options - The options object passed to the Axios constructor.
|
||||
*
|
||||
* @returns {void}
|
||||
*/
|
||||
function AxiosURLSearchParams(params, options) {
|
||||
this._pairs = [];
|
||||
|
||||
params && toFormData(params, this, options);
|
||||
}
|
||||
|
||||
const prototype = AxiosURLSearchParams.prototype;
|
||||
|
||||
prototype.append = function append(name, value) {
|
||||
this._pairs.push([name, value]);
|
||||
};
|
||||
|
||||
prototype.toString = function toString(encoder) {
|
||||
const _encode = encoder
|
||||
? function (value) {
|
||||
return encoder.call(this, value, encode);
|
||||
}
|
||||
: encode;
|
||||
|
||||
return this._pairs
|
||||
.map(function each(pair) {
|
||||
return _encode(pair[0]) + '=' + _encode(pair[1]);
|
||||
}, '')
|
||||
.join('&');
|
||||
};
|
||||
|
||||
export default AxiosURLSearchParams;
|
||||
77
extracted-source/node_modules/axios/lib/helpers/HttpStatusCode.js
generated
vendored
Normal file
77
extracted-source/node_modules/axios/lib/helpers/HttpStatusCode.js
generated
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
const HttpStatusCode = {
|
||||
Continue: 100,
|
||||
SwitchingProtocols: 101,
|
||||
Processing: 102,
|
||||
EarlyHints: 103,
|
||||
Ok: 200,
|
||||
Created: 201,
|
||||
Accepted: 202,
|
||||
NonAuthoritativeInformation: 203,
|
||||
NoContent: 204,
|
||||
ResetContent: 205,
|
||||
PartialContent: 206,
|
||||
MultiStatus: 207,
|
||||
AlreadyReported: 208,
|
||||
ImUsed: 226,
|
||||
MultipleChoices: 300,
|
||||
MovedPermanently: 301,
|
||||
Found: 302,
|
||||
SeeOther: 303,
|
||||
NotModified: 304,
|
||||
UseProxy: 305,
|
||||
Unused: 306,
|
||||
TemporaryRedirect: 307,
|
||||
PermanentRedirect: 308,
|
||||
BadRequest: 400,
|
||||
Unauthorized: 401,
|
||||
PaymentRequired: 402,
|
||||
Forbidden: 403,
|
||||
NotFound: 404,
|
||||
MethodNotAllowed: 405,
|
||||
NotAcceptable: 406,
|
||||
ProxyAuthenticationRequired: 407,
|
||||
RequestTimeout: 408,
|
||||
Conflict: 409,
|
||||
Gone: 410,
|
||||
LengthRequired: 411,
|
||||
PreconditionFailed: 412,
|
||||
PayloadTooLarge: 413,
|
||||
UriTooLong: 414,
|
||||
UnsupportedMediaType: 415,
|
||||
RangeNotSatisfiable: 416,
|
||||
ExpectationFailed: 417,
|
||||
ImATeapot: 418,
|
||||
MisdirectedRequest: 421,
|
||||
UnprocessableEntity: 422,
|
||||
Locked: 423,
|
||||
FailedDependency: 424,
|
||||
TooEarly: 425,
|
||||
UpgradeRequired: 426,
|
||||
PreconditionRequired: 428,
|
||||
TooManyRequests: 429,
|
||||
RequestHeaderFieldsTooLarge: 431,
|
||||
UnavailableForLegalReasons: 451,
|
||||
InternalServerError: 500,
|
||||
NotImplemented: 501,
|
||||
BadGateway: 502,
|
||||
ServiceUnavailable: 503,
|
||||
GatewayTimeout: 504,
|
||||
HttpVersionNotSupported: 505,
|
||||
VariantAlsoNegotiates: 506,
|
||||
InsufficientStorage: 507,
|
||||
LoopDetected: 508,
|
||||
NotExtended: 510,
|
||||
NetworkAuthenticationRequired: 511,
|
||||
WebServerIsDown: 521,
|
||||
ConnectionTimedOut: 522,
|
||||
OriginIsUnreachable: 523,
|
||||
TimeoutOccurred: 524,
|
||||
SslHandshakeFailed: 525,
|
||||
InvalidSslCertificate: 526,
|
||||
};
|
||||
|
||||
Object.entries(HttpStatusCode).forEach(([key, value]) => {
|
||||
HttpStatusCode[value] = key;
|
||||
});
|
||||
|
||||
export default HttpStatusCode;
|
||||
29
extracted-source/node_modules/axios/lib/helpers/ZlibHeaderTransformStream.js
generated
vendored
Normal file
29
extracted-source/node_modules/axios/lib/helpers/ZlibHeaderTransformStream.js
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
'use strict';
|
||||
|
||||
import stream from 'stream';
|
||||
|
||||
class ZlibHeaderTransformStream extends stream.Transform {
|
||||
__transform(chunk, encoding, callback) {
|
||||
this.push(chunk);
|
||||
callback();
|
||||
}
|
||||
|
||||
_transform(chunk, encoding, callback) {
|
||||
if (chunk.length !== 0) {
|
||||
this._transform = this.__transform;
|
||||
|
||||
// Add Default Compression headers if no zlib headers are present
|
||||
if (chunk[0] !== 120) {
|
||||
// Hex: 78
|
||||
const header = Buffer.alloc(2);
|
||||
header[0] = 120; // Hex: 78
|
||||
header[1] = 156; // Hex: 9C
|
||||
this.push(header, encoding);
|
||||
}
|
||||
}
|
||||
|
||||
this.__transform(chunk, encoding, callback);
|
||||
}
|
||||
}
|
||||
|
||||
export default ZlibHeaderTransformStream;
|
||||
14
extracted-source/node_modules/axios/lib/helpers/bind.js
generated
vendored
Normal file
14
extracted-source/node_modules/axios/lib/helpers/bind.js
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Create a bound version of a function with a specified `this` context
|
||||
*
|
||||
* @param {Function} fn - The function to bind
|
||||
* @param {*} thisArg - The value to be passed as the `this` parameter
|
||||
* @returns {Function} A new function that will call the original function with the specified `this` context
|
||||
*/
|
||||
export default function bind(fn, thisArg) {
|
||||
return function wrap() {
|
||||
return fn.apply(thisArg, arguments);
|
||||
};
|
||||
}
|
||||
66
extracted-source/node_modules/axios/lib/helpers/buildURL.js
generated
vendored
Normal file
66
extracted-source/node_modules/axios/lib/helpers/buildURL.js
generated
vendored
Normal file
@@ -0,0 +1,66 @@
|
||||
'use strict';
|
||||
|
||||
import utils from '../utils.js';
|
||||
import AxiosURLSearchParams from '../helpers/AxiosURLSearchParams.js';
|
||||
|
||||
/**
|
||||
* It replaces all instances of the characters `:`, `$`, `,`, `+`, `[`, and `]` with their
|
||||
* URI encoded counterparts
|
||||
*
|
||||
* @param {string} val The value to be encoded.
|
||||
*
|
||||
* @returns {string} The encoded value.
|
||||
*/
|
||||
function encode(val) {
|
||||
return encodeURIComponent(val)
|
||||
.replace(/%3A/gi, ':')
|
||||
.replace(/%24/g, '$')
|
||||
.replace(/%2C/gi, ',')
|
||||
.replace(/%20/g, '+');
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a URL by appending params to the end
|
||||
*
|
||||
* @param {string} url The base of the url (e.g., http://www.google.com)
|
||||
* @param {object} [params] The params to be appended
|
||||
* @param {?(object|Function)} options
|
||||
*
|
||||
* @returns {string} The formatted url
|
||||
*/
|
||||
export default function buildURL(url, params, options) {
|
||||
if (!params) {
|
||||
return url;
|
||||
}
|
||||
|
||||
const _encode = (options && options.encode) || encode;
|
||||
|
||||
const _options = utils.isFunction(options)
|
||||
? {
|
||||
serialize: options,
|
||||
}
|
||||
: options;
|
||||
|
||||
const serializeFn = _options && _options.serialize;
|
||||
|
||||
let serializedParams;
|
||||
|
||||
if (serializeFn) {
|
||||
serializedParams = serializeFn(params, _options);
|
||||
} else {
|
||||
serializedParams = utils.isURLSearchParams(params)
|
||||
? params.toString()
|
||||
: new AxiosURLSearchParams(params, _options).toString(_encode);
|
||||
}
|
||||
|
||||
if (serializedParams) {
|
||||
const hashmarkIndex = url.indexOf('#');
|
||||
|
||||
if (hashmarkIndex !== -1) {
|
||||
url = url.slice(0, hashmarkIndex);
|
||||
}
|
||||
url += (url.indexOf('?') === -1 ? '?' : '&') + serializedParams;
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
18
extracted-source/node_modules/axios/lib/helpers/callbackify.js
generated
vendored
Normal file
18
extracted-source/node_modules/axios/lib/helpers/callbackify.js
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
import utils from '../utils.js';
|
||||
|
||||
const callbackify = (fn, reducer) => {
|
||||
return utils.isAsyncFn(fn)
|
||||
? function (...args) {
|
||||
const cb = args.pop();
|
||||
fn.apply(this, args).then((value) => {
|
||||
try {
|
||||
reducer ? cb(null, ...reducer(value)) : cb(null, value);
|
||||
} catch (err) {
|
||||
cb(err);
|
||||
}
|
||||
}, cb);
|
||||
}
|
||||
: fn;
|
||||
};
|
||||
|
||||
export default callbackify;
|
||||
15
extracted-source/node_modules/axios/lib/helpers/combineURLs.js
generated
vendored
Normal file
15
extracted-source/node_modules/axios/lib/helpers/combineURLs.js
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Creates a new URL by combining the specified URLs
|
||||
*
|
||||
* @param {string} baseURL The base URL
|
||||
* @param {string} relativeURL The relative URL
|
||||
*
|
||||
* @returns {string} The combined URL
|
||||
*/
|
||||
export default function combineURLs(baseURL, relativeURL) {
|
||||
return relativeURL
|
||||
? baseURL.replace(/\/?\/$/, '') + '/' + relativeURL.replace(/^\/+/, '')
|
||||
: baseURL;
|
||||
}
|
||||
56
extracted-source/node_modules/axios/lib/helpers/composeSignals.js
generated
vendored
Normal file
56
extracted-source/node_modules/axios/lib/helpers/composeSignals.js
generated
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
import CanceledError from '../cancel/CanceledError.js';
|
||||
import AxiosError from '../core/AxiosError.js';
|
||||
import utils from '../utils.js';
|
||||
|
||||
const composeSignals = (signals, timeout) => {
|
||||
const { length } = (signals = signals ? signals.filter(Boolean) : []);
|
||||
|
||||
if (timeout || length) {
|
||||
let controller = new AbortController();
|
||||
|
||||
let aborted;
|
||||
|
||||
const onabort = function (reason) {
|
||||
if (!aborted) {
|
||||
aborted = true;
|
||||
unsubscribe();
|
||||
const err = reason instanceof Error ? reason : this.reason;
|
||||
controller.abort(
|
||||
err instanceof AxiosError
|
||||
? err
|
||||
: new CanceledError(err instanceof Error ? err.message : err)
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
let timer =
|
||||
timeout &&
|
||||
setTimeout(() => {
|
||||
timer = null;
|
||||
onabort(new AxiosError(`timeout of ${timeout}ms exceeded`, AxiosError.ETIMEDOUT));
|
||||
}, timeout);
|
||||
|
||||
const unsubscribe = () => {
|
||||
if (signals) {
|
||||
timer && clearTimeout(timer);
|
||||
timer = null;
|
||||
signals.forEach((signal) => {
|
||||
signal.unsubscribe
|
||||
? signal.unsubscribe(onabort)
|
||||
: signal.removeEventListener('abort', onabort);
|
||||
});
|
||||
signals = null;
|
||||
}
|
||||
};
|
||||
|
||||
signals.forEach((signal) => signal.addEventListener('abort', onabort));
|
||||
|
||||
const { signal } = controller;
|
||||
|
||||
signal.unsubscribe = () => utils.asap(unsubscribe);
|
||||
|
||||
return signal;
|
||||
}
|
||||
};
|
||||
|
||||
export default composeSignals;
|
||||
48
extracted-source/node_modules/axios/lib/helpers/cookies.js
generated
vendored
Normal file
48
extracted-source/node_modules/axios/lib/helpers/cookies.js
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
import utils from '../utils.js';
|
||||
import platform from '../platform/index.js';
|
||||
|
||||
export default platform.hasStandardBrowserEnv
|
||||
? // Standard browser envs support document.cookie
|
||||
{
|
||||
write(name, value, expires, path, domain, secure, sameSite) {
|
||||
if (typeof document === 'undefined') return;
|
||||
|
||||
const cookie = [`${name}=${encodeURIComponent(value)}`];
|
||||
|
||||
if (utils.isNumber(expires)) {
|
||||
cookie.push(`expires=${new Date(expires).toUTCString()}`);
|
||||
}
|
||||
if (utils.isString(path)) {
|
||||
cookie.push(`path=${path}`);
|
||||
}
|
||||
if (utils.isString(domain)) {
|
||||
cookie.push(`domain=${domain}`);
|
||||
}
|
||||
if (secure === true) {
|
||||
cookie.push('secure');
|
||||
}
|
||||
if (utils.isString(sameSite)) {
|
||||
cookie.push(`SameSite=${sameSite}`);
|
||||
}
|
||||
|
||||
document.cookie = cookie.join('; ');
|
||||
},
|
||||
|
||||
read(name) {
|
||||
if (typeof document === 'undefined') return null;
|
||||
const match = document.cookie.match(new RegExp('(?:^|; )' + name + '=([^;]*)'));
|
||||
return match ? decodeURIComponent(match[1]) : null;
|
||||
},
|
||||
|
||||
remove(name) {
|
||||
this.write(name, '', Date.now() - 86400000, '/');
|
||||
},
|
||||
}
|
||||
: // Non-standard browser env (web workers, react-native) lack needed support.
|
||||
{
|
||||
write() {},
|
||||
read() {
|
||||
return null;
|
||||
},
|
||||
remove() {},
|
||||
};
|
||||
73
extracted-source/node_modules/axios/lib/helpers/estimateDataURLDecodedBytes.js
generated
vendored
Normal file
73
extracted-source/node_modules/axios/lib/helpers/estimateDataURLDecodedBytes.js
generated
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
/**
|
||||
* Estimate decoded byte length of a data:// URL *without* allocating large buffers.
|
||||
* - For base64: compute exact decoded size using length and padding;
|
||||
* handle %XX at the character-count level (no string allocation).
|
||||
* - For non-base64: use UTF-8 byteLength of the encoded body as a safe upper bound.
|
||||
*
|
||||
* @param {string} url
|
||||
* @returns {number}
|
||||
*/
|
||||
export default function estimateDataURLDecodedBytes(url) {
|
||||
if (!url || typeof url !== 'string') return 0;
|
||||
if (!url.startsWith('data:')) return 0;
|
||||
|
||||
const comma = url.indexOf(',');
|
||||
if (comma < 0) return 0;
|
||||
|
||||
const meta = url.slice(5, comma);
|
||||
const body = url.slice(comma + 1);
|
||||
const isBase64 = /;base64/i.test(meta);
|
||||
|
||||
if (isBase64) {
|
||||
let effectiveLen = body.length;
|
||||
const len = body.length; // cache length
|
||||
|
||||
for (let i = 0; i < len; i++) {
|
||||
if (body.charCodeAt(i) === 37 /* '%' */ && i + 2 < len) {
|
||||
const a = body.charCodeAt(i + 1);
|
||||
const b = body.charCodeAt(i + 2);
|
||||
const isHex =
|
||||
((a >= 48 && a <= 57) || (a >= 65 && a <= 70) || (a >= 97 && a <= 102)) &&
|
||||
((b >= 48 && b <= 57) || (b >= 65 && b <= 70) || (b >= 97 && b <= 102));
|
||||
|
||||
if (isHex) {
|
||||
effectiveLen -= 2;
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let pad = 0;
|
||||
let idx = len - 1;
|
||||
|
||||
const tailIsPct3D = (j) =>
|
||||
j >= 2 &&
|
||||
body.charCodeAt(j - 2) === 37 && // '%'
|
||||
body.charCodeAt(j - 1) === 51 && // '3'
|
||||
(body.charCodeAt(j) === 68 || body.charCodeAt(j) === 100); // 'D' or 'd'
|
||||
|
||||
if (idx >= 0) {
|
||||
if (body.charCodeAt(idx) === 61 /* '=' */) {
|
||||
pad++;
|
||||
idx--;
|
||||
} else if (tailIsPct3D(idx)) {
|
||||
pad++;
|
||||
idx -= 3;
|
||||
}
|
||||
}
|
||||
|
||||
if (pad === 1 && idx >= 0) {
|
||||
if (body.charCodeAt(idx) === 61 /* '=' */) {
|
||||
pad++;
|
||||
} else if (tailIsPct3D(idx)) {
|
||||
pad++;
|
||||
}
|
||||
}
|
||||
|
||||
const groups = Math.floor(effectiveLen / 4);
|
||||
const bytes = groups * 3 - (pad || 0);
|
||||
return bytes > 0 ? bytes : 0;
|
||||
}
|
||||
|
||||
return Buffer.byteLength(body, 'utf8');
|
||||
}
|
||||
95
extracted-source/node_modules/axios/lib/helpers/formDataToJSON.js
generated
vendored
Normal file
95
extracted-source/node_modules/axios/lib/helpers/formDataToJSON.js
generated
vendored
Normal file
@@ -0,0 +1,95 @@
|
||||
'use strict';
|
||||
|
||||
import utils from '../utils.js';
|
||||
|
||||
/**
|
||||
* It takes a string like `foo[x][y][z]` and returns an array like `['foo', 'x', 'y', 'z']
|
||||
*
|
||||
* @param {string} name - The name of the property to get.
|
||||
*
|
||||
* @returns An array of strings.
|
||||
*/
|
||||
function parsePropPath(name) {
|
||||
// foo[x][y][z]
|
||||
// foo.x.y.z
|
||||
// foo-x-y-z
|
||||
// foo x y z
|
||||
return utils.matchAll(/\w+|\[(\w*)]/g, name).map((match) => {
|
||||
return match[0] === '[]' ? '' : match[1] || match[0];
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert an array to an object.
|
||||
*
|
||||
* @param {Array<any>} arr - The array to convert to an object.
|
||||
*
|
||||
* @returns An object with the same keys and values as the array.
|
||||
*/
|
||||
function arrayToObject(arr) {
|
||||
const obj = {};
|
||||
const keys = Object.keys(arr);
|
||||
let i;
|
||||
const len = keys.length;
|
||||
let key;
|
||||
for (i = 0; i < len; i++) {
|
||||
key = keys[i];
|
||||
obj[key] = arr[key];
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* It takes a FormData object and returns a JavaScript object
|
||||
*
|
||||
* @param {string} formData The FormData object to convert to JSON.
|
||||
*
|
||||
* @returns {Object<string, any> | null} The converted object.
|
||||
*/
|
||||
function formDataToJSON(formData) {
|
||||
function buildPath(path, value, target, index) {
|
||||
let name = path[index++];
|
||||
|
||||
if (name === '__proto__') return true;
|
||||
|
||||
const isNumericKey = Number.isFinite(+name);
|
||||
const isLast = index >= path.length;
|
||||
name = !name && utils.isArray(target) ? target.length : name;
|
||||
|
||||
if (isLast) {
|
||||
if (utils.hasOwnProp(target, name)) {
|
||||
target[name] = [target[name], value];
|
||||
} else {
|
||||
target[name] = value;
|
||||
}
|
||||
|
||||
return !isNumericKey;
|
||||
}
|
||||
|
||||
if (!target[name] || !utils.isObject(target[name])) {
|
||||
target[name] = [];
|
||||
}
|
||||
|
||||
const result = buildPath(path, value, target[name], index);
|
||||
|
||||
if (result && utils.isArray(target[name])) {
|
||||
target[name] = arrayToObject(target[name]);
|
||||
}
|
||||
|
||||
return !isNumericKey;
|
||||
}
|
||||
|
||||
if (utils.isFormData(formData) && utils.isFunction(formData.entries)) {
|
||||
const obj = {};
|
||||
|
||||
utils.forEachEntry(formData, (name, value) => {
|
||||
buildPath(parsePropPath(name), value, obj, 0);
|
||||
});
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export default formDataToJSON;
|
||||
118
extracted-source/node_modules/axios/lib/helpers/formDataToStream.js
generated
vendored
Normal file
118
extracted-source/node_modules/axios/lib/helpers/formDataToStream.js
generated
vendored
Normal file
@@ -0,0 +1,118 @@
|
||||
import util from 'util';
|
||||
import { Readable } from 'stream';
|
||||
import utils from '../utils.js';
|
||||
import readBlob from './readBlob.js';
|
||||
import platform from '../platform/index.js';
|
||||
|
||||
const BOUNDARY_ALPHABET = platform.ALPHABET.ALPHA_DIGIT + '-_';
|
||||
|
||||
const textEncoder = typeof TextEncoder === 'function' ? new TextEncoder() : new util.TextEncoder();
|
||||
|
||||
const CRLF = '\r\n';
|
||||
const CRLF_BYTES = textEncoder.encode(CRLF);
|
||||
const CRLF_BYTES_COUNT = 2;
|
||||
|
||||
class FormDataPart {
|
||||
constructor(name, value) {
|
||||
const { escapeName } = this.constructor;
|
||||
const isStringValue = utils.isString(value);
|
||||
|
||||
let headers = `Content-Disposition: form-data; name="${escapeName(name)}"${
|
||||
!isStringValue && value.name ? `; filename="${escapeName(value.name)}"` : ''
|
||||
}${CRLF}`;
|
||||
|
||||
if (isStringValue) {
|
||||
value = textEncoder.encode(String(value).replace(/\r?\n|\r\n?/g, CRLF));
|
||||
} else {
|
||||
headers += `Content-Type: ${value.type || 'application/octet-stream'}${CRLF}`;
|
||||
}
|
||||
|
||||
this.headers = textEncoder.encode(headers + CRLF);
|
||||
|
||||
this.contentLength = isStringValue ? value.byteLength : value.size;
|
||||
|
||||
this.size = this.headers.byteLength + this.contentLength + CRLF_BYTES_COUNT;
|
||||
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
async *encode() {
|
||||
yield this.headers;
|
||||
|
||||
const { value } = this;
|
||||
|
||||
if (utils.isTypedArray(value)) {
|
||||
yield value;
|
||||
} else {
|
||||
yield* readBlob(value);
|
||||
}
|
||||
|
||||
yield CRLF_BYTES;
|
||||
}
|
||||
|
||||
static escapeName(name) {
|
||||
return String(name).replace(
|
||||
/[\r\n"]/g,
|
||||
(match) =>
|
||||
({
|
||||
'\r': '%0D',
|
||||
'\n': '%0A',
|
||||
'"': '%22',
|
||||
})[match]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const formDataToStream = (form, headersHandler, options) => {
|
||||
const {
|
||||
tag = 'form-data-boundary',
|
||||
size = 25,
|
||||
boundary = tag + '-' + platform.generateString(size, BOUNDARY_ALPHABET),
|
||||
} = options || {};
|
||||
|
||||
if (!utils.isFormData(form)) {
|
||||
throw TypeError('FormData instance required');
|
||||
}
|
||||
|
||||
if (boundary.length < 1 || boundary.length > 70) {
|
||||
throw Error('boundary must be 10-70 characters long');
|
||||
}
|
||||
|
||||
const boundaryBytes = textEncoder.encode('--' + boundary + CRLF);
|
||||
const footerBytes = textEncoder.encode('--' + boundary + '--' + CRLF);
|
||||
let contentLength = footerBytes.byteLength;
|
||||
|
||||
const parts = Array.from(form.entries()).map(([name, value]) => {
|
||||
const part = new FormDataPart(name, value);
|
||||
contentLength += part.size;
|
||||
return part;
|
||||
});
|
||||
|
||||
contentLength += boundaryBytes.byteLength * parts.length;
|
||||
|
||||
contentLength = utils.toFiniteNumber(contentLength);
|
||||
|
||||
const computedHeaders = {
|
||||
'Content-Type': `multipart/form-data; boundary=${boundary}`,
|
||||
};
|
||||
|
||||
if (Number.isFinite(contentLength)) {
|
||||
computedHeaders['Content-Length'] = contentLength;
|
||||
}
|
||||
|
||||
headersHandler && headersHandler(computedHeaders);
|
||||
|
||||
return Readable.from(
|
||||
(async function* () {
|
||||
for (const part of parts) {
|
||||
yield boundaryBytes;
|
||||
yield* part.encode();
|
||||
}
|
||||
|
||||
yield footerBytes;
|
||||
})()
|
||||
);
|
||||
};
|
||||
|
||||
export default formDataToStream;
|
||||
53
extracted-source/node_modules/axios/lib/helpers/fromDataURI.js
generated
vendored
Normal file
53
extracted-source/node_modules/axios/lib/helpers/fromDataURI.js
generated
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
'use strict';
|
||||
|
||||
import AxiosError from '../core/AxiosError.js';
|
||||
import parseProtocol from './parseProtocol.js';
|
||||
import platform from '../platform/index.js';
|
||||
|
||||
const DATA_URL_PATTERN = /^(?:([^;]+);)?(?:[^;]+;)?(base64|),([\s\S]*)$/;
|
||||
|
||||
/**
|
||||
* Parse data uri to a Buffer or Blob
|
||||
*
|
||||
* @param {String} uri
|
||||
* @param {?Boolean} asBlob
|
||||
* @param {?Object} options
|
||||
* @param {?Function} options.Blob
|
||||
*
|
||||
* @returns {Buffer|Blob}
|
||||
*/
|
||||
export default function fromDataURI(uri, asBlob, options) {
|
||||
const _Blob = (options && options.Blob) || platform.classes.Blob;
|
||||
const protocol = parseProtocol(uri);
|
||||
|
||||
if (asBlob === undefined && _Blob) {
|
||||
asBlob = true;
|
||||
}
|
||||
|
||||
if (protocol === 'data') {
|
||||
uri = protocol.length ? uri.slice(protocol.length + 1) : uri;
|
||||
|
||||
const match = DATA_URL_PATTERN.exec(uri);
|
||||
|
||||
if (!match) {
|
||||
throw new AxiosError('Invalid URL', AxiosError.ERR_INVALID_URL);
|
||||
}
|
||||
|
||||
const mime = match[1];
|
||||
const isBase64 = match[2];
|
||||
const body = match[3];
|
||||
const buffer = Buffer.from(decodeURIComponent(body), isBase64 ? 'base64' : 'utf8');
|
||||
|
||||
if (asBlob) {
|
||||
if (!_Blob) {
|
||||
throw new AxiosError('Blob is not supported', AxiosError.ERR_NOT_SUPPORT);
|
||||
}
|
||||
|
||||
return new _Blob([buffer], { type: mime });
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
throw new AxiosError('Unsupported protocol ' + protocol, AxiosError.ERR_NOT_SUPPORT);
|
||||
}
|
||||
19
extracted-source/node_modules/axios/lib/helpers/isAbsoluteURL.js
generated
vendored
Normal file
19
extracted-source/node_modules/axios/lib/helpers/isAbsoluteURL.js
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Determines whether the specified URL is absolute
|
||||
*
|
||||
* @param {string} url The URL to test
|
||||
*
|
||||
* @returns {boolean} True if the specified URL is absolute, otherwise false
|
||||
*/
|
||||
export default function isAbsoluteURL(url) {
|
||||
// A URL is considered absolute if it begins with "<scheme>://" or "//" (protocol-relative URL).
|
||||
// RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed
|
||||
// by any combination of letters, digits, plus, period, or hyphen.
|
||||
if (typeof url !== 'string') {
|
||||
return false;
|
||||
}
|
||||
|
||||
return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url);
|
||||
}
|
||||
14
extracted-source/node_modules/axios/lib/helpers/isAxiosError.js
generated
vendored
Normal file
14
extracted-source/node_modules/axios/lib/helpers/isAxiosError.js
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
import utils from '../utils.js';
|
||||
|
||||
/**
|
||||
* Determines whether the payload is an error thrown by Axios
|
||||
*
|
||||
* @param {*} payload The value to test
|
||||
*
|
||||
* @returns {boolean} True if the payload is an error thrown by Axios, otherwise false
|
||||
*/
|
||||
export default function isAxiosError(payload) {
|
||||
return utils.isObject(payload) && payload.isAxiosError === true;
|
||||
}
|
||||
16
extracted-source/node_modules/axios/lib/helpers/isURLSameOrigin.js
generated
vendored
Normal file
16
extracted-source/node_modules/axios/lib/helpers/isURLSameOrigin.js
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
import platform from '../platform/index.js';
|
||||
|
||||
export default platform.hasStandardBrowserEnv
|
||||
? ((origin, isMSIE) => (url) => {
|
||||
url = new URL(url, platform.origin);
|
||||
|
||||
return (
|
||||
origin.protocol === url.protocol &&
|
||||
origin.host === url.host &&
|
||||
(isMSIE || origin.port === url.port)
|
||||
);
|
||||
})(
|
||||
new URL(platform.origin),
|
||||
platform.navigator && /(msie|trident)/i.test(platform.navigator.userAgent)
|
||||
)
|
||||
: () => true;
|
||||
69
extracted-source/node_modules/axios/lib/helpers/parseHeaders.js
generated
vendored
Normal file
69
extracted-source/node_modules/axios/lib/helpers/parseHeaders.js
generated
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
'use strict';
|
||||
|
||||
import utils from '../utils.js';
|
||||
|
||||
// RawAxiosHeaders whose duplicates are ignored by node
|
||||
// c.f. https://nodejs.org/api/http.html#http_message_headers
|
||||
const ignoreDuplicateOf = utils.toObjectSet([
|
||||
'age',
|
||||
'authorization',
|
||||
'content-length',
|
||||
'content-type',
|
||||
'etag',
|
||||
'expires',
|
||||
'from',
|
||||
'host',
|
||||
'if-modified-since',
|
||||
'if-unmodified-since',
|
||||
'last-modified',
|
||||
'location',
|
||||
'max-forwards',
|
||||
'proxy-authorization',
|
||||
'referer',
|
||||
'retry-after',
|
||||
'user-agent',
|
||||
]);
|
||||
|
||||
/**
|
||||
* Parse headers into an object
|
||||
*
|
||||
* ```
|
||||
* Date: Wed, 27 Aug 2014 08:58:49 GMT
|
||||
* Content-Type: application/json
|
||||
* Connection: keep-alive
|
||||
* Transfer-Encoding: chunked
|
||||
* ```
|
||||
*
|
||||
* @param {String} rawHeaders Headers needing to be parsed
|
||||
*
|
||||
* @returns {Object} Headers parsed into an object
|
||||
*/
|
||||
export default (rawHeaders) => {
|
||||
const parsed = {};
|
||||
let key;
|
||||
let val;
|
||||
let i;
|
||||
|
||||
rawHeaders &&
|
||||
rawHeaders.split('\n').forEach(function parser(line) {
|
||||
i = line.indexOf(':');
|
||||
key = line.substring(0, i).trim().toLowerCase();
|
||||
val = line.substring(i + 1).trim();
|
||||
|
||||
if (!key || (parsed[key] && ignoreDuplicateOf[key])) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (key === 'set-cookie') {
|
||||
if (parsed[key]) {
|
||||
parsed[key].push(val);
|
||||
} else {
|
||||
parsed[key] = [val];
|
||||
}
|
||||
} else {
|
||||
parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val;
|
||||
}
|
||||
});
|
||||
|
||||
return parsed;
|
||||
};
|
||||
6
extracted-source/node_modules/axios/lib/helpers/parseProtocol.js
generated
vendored
Normal file
6
extracted-source/node_modules/axios/lib/helpers/parseProtocol.js
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
export default function parseProtocol(url) {
|
||||
const match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url);
|
||||
return (match && match[1]) || '';
|
||||
}
|
||||
51
extracted-source/node_modules/axios/lib/helpers/progressEventReducer.js
generated
vendored
Normal file
51
extracted-source/node_modules/axios/lib/helpers/progressEventReducer.js
generated
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
import speedometer from './speedometer.js';
|
||||
import throttle from './throttle.js';
|
||||
import utils from '../utils.js';
|
||||
|
||||
export const progressEventReducer = (listener, isDownloadStream, freq = 3) => {
|
||||
let bytesNotified = 0;
|
||||
const _speedometer = speedometer(50, 250);
|
||||
|
||||
return throttle((e) => {
|
||||
const loaded = e.loaded;
|
||||
const total = e.lengthComputable ? e.total : undefined;
|
||||
const progressBytes = loaded - bytesNotified;
|
||||
const rate = _speedometer(progressBytes);
|
||||
const inRange = loaded <= total;
|
||||
|
||||
bytesNotified = loaded;
|
||||
|
||||
const data = {
|
||||
loaded,
|
||||
total,
|
||||
progress: total ? loaded / total : undefined,
|
||||
bytes: progressBytes,
|
||||
rate: rate ? rate : undefined,
|
||||
estimated: rate && total && inRange ? (total - loaded) / rate : undefined,
|
||||
event: e,
|
||||
lengthComputable: total != null,
|
||||
[isDownloadStream ? 'download' : 'upload']: true,
|
||||
};
|
||||
|
||||
listener(data);
|
||||
}, freq);
|
||||
};
|
||||
|
||||
export const progressEventDecorator = (total, throttled) => {
|
||||
const lengthComputable = total != null;
|
||||
|
||||
return [
|
||||
(loaded) =>
|
||||
throttled[0]({
|
||||
lengthComputable,
|
||||
total,
|
||||
loaded,
|
||||
}),
|
||||
throttled[1],
|
||||
];
|
||||
};
|
||||
|
||||
export const asyncDecorator =
|
||||
(fn) =>
|
||||
(...args) =>
|
||||
utils.asap(() => fn(...args));
|
||||
15
extracted-source/node_modules/axios/lib/helpers/readBlob.js
generated
vendored
Normal file
15
extracted-source/node_modules/axios/lib/helpers/readBlob.js
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
const { asyncIterator } = Symbol;
|
||||
|
||||
const readBlob = async function* (blob) {
|
||||
if (blob.stream) {
|
||||
yield* blob.stream();
|
||||
} else if (blob.arrayBuffer) {
|
||||
yield await blob.arrayBuffer();
|
||||
} else if (blob[asyncIterator]) {
|
||||
yield* blob[asyncIterator]();
|
||||
} else {
|
||||
yield blob;
|
||||
}
|
||||
};
|
||||
|
||||
export default readBlob;
|
||||
70
extracted-source/node_modules/axios/lib/helpers/resolveConfig.js
generated
vendored
Normal file
70
extracted-source/node_modules/axios/lib/helpers/resolveConfig.js
generated
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
import platform from '../platform/index.js';
|
||||
import utils from '../utils.js';
|
||||
import isURLSameOrigin from './isURLSameOrigin.js';
|
||||
import cookies from './cookies.js';
|
||||
import buildFullPath from '../core/buildFullPath.js';
|
||||
import mergeConfig from '../core/mergeConfig.js';
|
||||
import AxiosHeaders from '../core/AxiosHeaders.js';
|
||||
import buildURL from './buildURL.js';
|
||||
|
||||
export default (config) => {
|
||||
const newConfig = mergeConfig({}, config);
|
||||
|
||||
let { data, withXSRFToken, xsrfHeaderName, xsrfCookieName, headers, auth } = newConfig;
|
||||
|
||||
newConfig.headers = headers = AxiosHeaders.from(headers);
|
||||
|
||||
newConfig.url = buildURL(
|
||||
buildFullPath(newConfig.baseURL, newConfig.url, newConfig.allowAbsoluteUrls),
|
||||
config.params,
|
||||
config.paramsSerializer
|
||||
);
|
||||
|
||||
// HTTP basic authentication
|
||||
if (auth) {
|
||||
headers.set(
|
||||
'Authorization',
|
||||
'Basic ' +
|
||||
btoa(
|
||||
(auth.username || '') +
|
||||
':' +
|
||||
(auth.password ? unescape(encodeURIComponent(auth.password)) : '')
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (utils.isFormData(data)) {
|
||||
if (platform.hasStandardBrowserEnv || platform.hasStandardBrowserWebWorkerEnv) {
|
||||
headers.setContentType(undefined); // browser handles it
|
||||
} else if (utils.isFunction(data.getHeaders)) {
|
||||
// Node.js FormData (like form-data package)
|
||||
const formHeaders = data.getHeaders();
|
||||
// Only set safe headers to avoid overwriting security headers
|
||||
const allowedHeaders = ['content-type', 'content-length'];
|
||||
Object.entries(formHeaders).forEach(([key, val]) => {
|
||||
if (allowedHeaders.includes(key.toLowerCase())) {
|
||||
headers.set(key, val);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Add xsrf header
|
||||
// This is only done if running in a standard browser environment.
|
||||
// Specifically not if we're in a web worker, or react-native.
|
||||
|
||||
if (platform.hasStandardBrowserEnv) {
|
||||
withXSRFToken && utils.isFunction(withXSRFToken) && (withXSRFToken = withXSRFToken(newConfig));
|
||||
|
||||
if (withXSRFToken || (withXSRFToken !== false && isURLSameOrigin(newConfig.url))) {
|
||||
// Add xsrf header
|
||||
const xsrfValue = xsrfHeaderName && xsrfCookieName && cookies.read(xsrfCookieName);
|
||||
|
||||
if (xsrfValue) {
|
||||
headers.set(xsrfHeaderName, xsrfValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return newConfig;
|
||||
};
|
||||
55
extracted-source/node_modules/axios/lib/helpers/speedometer.js
generated
vendored
Normal file
55
extracted-source/node_modules/axios/lib/helpers/speedometer.js
generated
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Calculate data maxRate
|
||||
* @param {Number} [samplesCount= 10]
|
||||
* @param {Number} [min= 1000]
|
||||
* @returns {Function}
|
||||
*/
|
||||
function speedometer(samplesCount, min) {
|
||||
samplesCount = samplesCount || 10;
|
||||
const bytes = new Array(samplesCount);
|
||||
const timestamps = new Array(samplesCount);
|
||||
let head = 0;
|
||||
let tail = 0;
|
||||
let firstSampleTS;
|
||||
|
||||
min = min !== undefined ? min : 1000;
|
||||
|
||||
return function push(chunkLength) {
|
||||
const now = Date.now();
|
||||
|
||||
const startedAt = timestamps[tail];
|
||||
|
||||
if (!firstSampleTS) {
|
||||
firstSampleTS = now;
|
||||
}
|
||||
|
||||
bytes[head] = chunkLength;
|
||||
timestamps[head] = now;
|
||||
|
||||
let i = tail;
|
||||
let bytesCount = 0;
|
||||
|
||||
while (i !== head) {
|
||||
bytesCount += bytes[i++];
|
||||
i = i % samplesCount;
|
||||
}
|
||||
|
||||
head = (head + 1) % samplesCount;
|
||||
|
||||
if (head === tail) {
|
||||
tail = (tail + 1) % samplesCount;
|
||||
}
|
||||
|
||||
if (now - firstSampleTS < min) {
|
||||
return;
|
||||
}
|
||||
|
||||
const passed = startedAt && now - startedAt;
|
||||
|
||||
return passed ? Math.round((bytesCount * 1000) / passed) : undefined;
|
||||
};
|
||||
}
|
||||
|
||||
export default speedometer;
|
||||
28
extracted-source/node_modules/axios/lib/helpers/spread.js
generated
vendored
Normal file
28
extracted-source/node_modules/axios/lib/helpers/spread.js
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Syntactic sugar for invoking a function and expanding an array for arguments.
|
||||
*
|
||||
* Common use case would be to use `Function.prototype.apply`.
|
||||
*
|
||||
* ```js
|
||||
* function f(x, y, z) {}
|
||||
* const args = [1, 2, 3];
|
||||
* f.apply(null, args);
|
||||
* ```
|
||||
*
|
||||
* With `spread` this example can be re-written.
|
||||
*
|
||||
* ```js
|
||||
* spread(function(x, y, z) {})([1, 2, 3]);
|
||||
* ```
|
||||
*
|
||||
* @param {Function} callback
|
||||
*
|
||||
* @returns {Function}
|
||||
*/
|
||||
export default function spread(callback) {
|
||||
return function wrap(arr) {
|
||||
return callback.apply(null, arr);
|
||||
};
|
||||
}
|
||||
44
extracted-source/node_modules/axios/lib/helpers/throttle.js
generated
vendored
Normal file
44
extracted-source/node_modules/axios/lib/helpers/throttle.js
generated
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* Throttle decorator
|
||||
* @param {Function} fn
|
||||
* @param {Number} freq
|
||||
* @return {Function}
|
||||
*/
|
||||
function throttle(fn, freq) {
|
||||
let timestamp = 0;
|
||||
let threshold = 1000 / freq;
|
||||
let lastArgs;
|
||||
let timer;
|
||||
|
||||
const invoke = (args, now = Date.now()) => {
|
||||
timestamp = now;
|
||||
lastArgs = null;
|
||||
if (timer) {
|
||||
clearTimeout(timer);
|
||||
timer = null;
|
||||
}
|
||||
fn(...args);
|
||||
};
|
||||
|
||||
const throttled = (...args) => {
|
||||
const now = Date.now();
|
||||
const passed = now - timestamp;
|
||||
if (passed >= threshold) {
|
||||
invoke(args, now);
|
||||
} else {
|
||||
lastArgs = args;
|
||||
if (!timer) {
|
||||
timer = setTimeout(() => {
|
||||
timer = null;
|
||||
invoke(lastArgs);
|
||||
}, threshold - passed);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const flush = () => lastArgs && invoke(lastArgs);
|
||||
|
||||
return [throttled, flush];
|
||||
}
|
||||
|
||||
export default throttle;
|
||||
241
extracted-source/node_modules/axios/lib/helpers/toFormData.js
generated
vendored
Normal file
241
extracted-source/node_modules/axios/lib/helpers/toFormData.js
generated
vendored
Normal file
@@ -0,0 +1,241 @@
|
||||
'use strict';
|
||||
|
||||
import utils from '../utils.js';
|
||||
import AxiosError from '../core/AxiosError.js';
|
||||
// temporary hotfix to avoid circular references until AxiosURLSearchParams is refactored
|
||||
import PlatformFormData from '../platform/node/classes/FormData.js';
|
||||
|
||||
/**
|
||||
* Determines if the given thing is a array or js object.
|
||||
*
|
||||
* @param {string} thing - The object or array to be visited.
|
||||
*
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function isVisitable(thing) {
|
||||
return utils.isPlainObject(thing) || utils.isArray(thing);
|
||||
}
|
||||
|
||||
/**
|
||||
* It removes the brackets from the end of a string
|
||||
*
|
||||
* @param {string} key - The key of the parameter.
|
||||
*
|
||||
* @returns {string} the key without the brackets.
|
||||
*/
|
||||
function removeBrackets(key) {
|
||||
return utils.endsWith(key, '[]') ? key.slice(0, -2) : key;
|
||||
}
|
||||
|
||||
/**
|
||||
* It takes a path, a key, and a boolean, and returns a string
|
||||
*
|
||||
* @param {string} path - The path to the current key.
|
||||
* @param {string} key - The key of the current object being iterated over.
|
||||
* @param {string} dots - If true, the key will be rendered with dots instead of brackets.
|
||||
*
|
||||
* @returns {string} The path to the current key.
|
||||
*/
|
||||
function renderKey(path, key, dots) {
|
||||
if (!path) return key;
|
||||
return path
|
||||
.concat(key)
|
||||
.map(function each(token, i) {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
token = removeBrackets(token);
|
||||
return !dots && i ? '[' + token + ']' : token;
|
||||
})
|
||||
.join(dots ? '.' : '');
|
||||
}
|
||||
|
||||
/**
|
||||
* If the array is an array and none of its elements are visitable, then it's a flat array.
|
||||
*
|
||||
* @param {Array<any>} arr - The array to check
|
||||
*
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function isFlatArray(arr) {
|
||||
return utils.isArray(arr) && !arr.some(isVisitable);
|
||||
}
|
||||
|
||||
const predicates = utils.toFlatObject(utils, {}, null, function filter(prop) {
|
||||
return /^is[A-Z]/.test(prop);
|
||||
});
|
||||
|
||||
/**
|
||||
* Convert a data object to FormData
|
||||
*
|
||||
* @param {Object} obj
|
||||
* @param {?Object} [formData]
|
||||
* @param {?Object} [options]
|
||||
* @param {Function} [options.visitor]
|
||||
* @param {Boolean} [options.metaTokens = true]
|
||||
* @param {Boolean} [options.dots = false]
|
||||
* @param {?Boolean} [options.indexes = false]
|
||||
*
|
||||
* @returns {Object}
|
||||
**/
|
||||
|
||||
/**
|
||||
* It converts an object into a FormData object
|
||||
*
|
||||
* @param {Object<any, any>} obj - The object to convert to form data.
|
||||
* @param {string} formData - The FormData object to append to.
|
||||
* @param {Object<string, any>} options
|
||||
*
|
||||
* @returns
|
||||
*/
|
||||
function toFormData(obj, formData, options) {
|
||||
if (!utils.isObject(obj)) {
|
||||
throw new TypeError('target must be an object');
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
formData = formData || new (PlatformFormData || FormData)();
|
||||
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
options = utils.toFlatObject(
|
||||
options,
|
||||
{
|
||||
metaTokens: true,
|
||||
dots: false,
|
||||
indexes: false,
|
||||
},
|
||||
false,
|
||||
function defined(option, source) {
|
||||
// eslint-disable-next-line no-eq-null,eqeqeq
|
||||
return !utils.isUndefined(source[option]);
|
||||
}
|
||||
);
|
||||
|
||||
const metaTokens = options.metaTokens;
|
||||
// eslint-disable-next-line no-use-before-define
|
||||
const visitor = options.visitor || defaultVisitor;
|
||||
const dots = options.dots;
|
||||
const indexes = options.indexes;
|
||||
const _Blob = options.Blob || (typeof Blob !== 'undefined' && Blob);
|
||||
const useBlob = _Blob && utils.isSpecCompliantForm(formData);
|
||||
|
||||
if (!utils.isFunction(visitor)) {
|
||||
throw new TypeError('visitor must be a function');
|
||||
}
|
||||
|
||||
function convertValue(value) {
|
||||
if (value === null) return '';
|
||||
|
||||
if (utils.isDate(value)) {
|
||||
return value.toISOString();
|
||||
}
|
||||
|
||||
if (utils.isBoolean(value)) {
|
||||
return value.toString();
|
||||
}
|
||||
|
||||
if (!useBlob && utils.isBlob(value)) {
|
||||
throw new AxiosError('Blob is not supported. Use a Buffer instead.');
|
||||
}
|
||||
|
||||
if (utils.isArrayBuffer(value) || utils.isTypedArray(value)) {
|
||||
return useBlob && typeof Blob === 'function' ? new Blob([value]) : Buffer.from(value);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default visitor.
|
||||
*
|
||||
* @param {*} value
|
||||
* @param {String|Number} key
|
||||
* @param {Array<String|Number>} path
|
||||
* @this {FormData}
|
||||
*
|
||||
* @returns {boolean} return true to visit the each prop of the value recursively
|
||||
*/
|
||||
function defaultVisitor(value, key, path) {
|
||||
let arr = value;
|
||||
|
||||
if (utils.isReactNative(formData) && utils.isReactNativeBlob(value)) {
|
||||
formData.append(renderKey(path, key, dots), convertValue(value));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (value && !path && typeof value === 'object') {
|
||||
if (utils.endsWith(key, '{}')) {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
key = metaTokens ? key : key.slice(0, -2);
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
value = JSON.stringify(value);
|
||||
} else if (
|
||||
(utils.isArray(value) && isFlatArray(value)) ||
|
||||
((utils.isFileList(value) || utils.endsWith(key, '[]')) && (arr = utils.toArray(value)))
|
||||
) {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
key = removeBrackets(key);
|
||||
|
||||
arr.forEach(function each(el, index) {
|
||||
!(utils.isUndefined(el) || el === null) &&
|
||||
formData.append(
|
||||
// eslint-disable-next-line no-nested-ternary
|
||||
indexes === true
|
||||
? renderKey([key], index, dots)
|
||||
: indexes === null
|
||||
? key
|
||||
: key + '[]',
|
||||
convertValue(el)
|
||||
);
|
||||
});
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (isVisitable(value)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
formData.append(renderKey(path, key, dots), convertValue(value));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
const stack = [];
|
||||
|
||||
const exposedHelpers = Object.assign(predicates, {
|
||||
defaultVisitor,
|
||||
convertValue,
|
||||
isVisitable,
|
||||
});
|
||||
|
||||
function build(value, path) {
|
||||
if (utils.isUndefined(value)) return;
|
||||
|
||||
if (stack.indexOf(value) !== -1) {
|
||||
throw Error('Circular reference detected in ' + path.join('.'));
|
||||
}
|
||||
|
||||
stack.push(value);
|
||||
|
||||
utils.forEach(value, function each(el, key) {
|
||||
const result =
|
||||
!(utils.isUndefined(el) || el === null) &&
|
||||
visitor.call(formData, el, utils.isString(key) ? key.trim() : key, path, exposedHelpers);
|
||||
|
||||
if (result === true) {
|
||||
build(el, path ? path.concat(key) : [key]);
|
||||
}
|
||||
});
|
||||
|
||||
stack.pop();
|
||||
}
|
||||
|
||||
if (!utils.isObject(obj)) {
|
||||
throw new TypeError('data must be an object');
|
||||
}
|
||||
|
||||
build(obj);
|
||||
|
||||
return formData;
|
||||
}
|
||||
|
||||
export default toFormData;
|
||||
19
extracted-source/node_modules/axios/lib/helpers/toURLEncodedForm.js
generated
vendored
Normal file
19
extracted-source/node_modules/axios/lib/helpers/toURLEncodedForm.js
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
'use strict';
|
||||
|
||||
import utils from '../utils.js';
|
||||
import toFormData from './toFormData.js';
|
||||
import platform from '../platform/index.js';
|
||||
|
||||
export default function toURLEncodedForm(data, options) {
|
||||
return toFormData(data, new platform.classes.URLSearchParams(), {
|
||||
visitor: function (value, key, path, helpers) {
|
||||
if (platform.isNode && utils.isBuffer(value)) {
|
||||
this.append(key, value.toString('base64'));
|
||||
return false;
|
||||
}
|
||||
|
||||
return helpers.defaultVisitor.apply(this, arguments);
|
||||
},
|
||||
...options,
|
||||
});
|
||||
}
|
||||
89
extracted-source/node_modules/axios/lib/helpers/trackStream.js
generated
vendored
Normal file
89
extracted-source/node_modules/axios/lib/helpers/trackStream.js
generated
vendored
Normal file
@@ -0,0 +1,89 @@
|
||||
export const streamChunk = function* (chunk, chunkSize) {
|
||||
let len = chunk.byteLength;
|
||||
|
||||
if (!chunkSize || len < chunkSize) {
|
||||
yield chunk;
|
||||
return;
|
||||
}
|
||||
|
||||
let pos = 0;
|
||||
let end;
|
||||
|
||||
while (pos < len) {
|
||||
end = pos + chunkSize;
|
||||
yield chunk.slice(pos, end);
|
||||
pos = end;
|
||||
}
|
||||
};
|
||||
|
||||
export const readBytes = async function* (iterable, chunkSize) {
|
||||
for await (const chunk of readStream(iterable)) {
|
||||
yield* streamChunk(chunk, chunkSize);
|
||||
}
|
||||
};
|
||||
|
||||
const readStream = async function* (stream) {
|
||||
if (stream[Symbol.asyncIterator]) {
|
||||
yield* stream;
|
||||
return;
|
||||
}
|
||||
|
||||
const reader = stream.getReader();
|
||||
try {
|
||||
for (;;) {
|
||||
const { done, value } = await reader.read();
|
||||
if (done) {
|
||||
break;
|
||||
}
|
||||
yield value;
|
||||
}
|
||||
} finally {
|
||||
await reader.cancel();
|
||||
}
|
||||
};
|
||||
|
||||
export const trackStream = (stream, chunkSize, onProgress, onFinish) => {
|
||||
const iterator = readBytes(stream, chunkSize);
|
||||
|
||||
let bytes = 0;
|
||||
let done;
|
||||
let _onFinish = (e) => {
|
||||
if (!done) {
|
||||
done = true;
|
||||
onFinish && onFinish(e);
|
||||
}
|
||||
};
|
||||
|
||||
return new ReadableStream(
|
||||
{
|
||||
async pull(controller) {
|
||||
try {
|
||||
const { done, value } = await iterator.next();
|
||||
|
||||
if (done) {
|
||||
_onFinish();
|
||||
controller.close();
|
||||
return;
|
||||
}
|
||||
|
||||
let len = value.byteLength;
|
||||
if (onProgress) {
|
||||
let loadedBytes = (bytes += len);
|
||||
onProgress(loadedBytes);
|
||||
}
|
||||
controller.enqueue(new Uint8Array(value));
|
||||
} catch (err) {
|
||||
_onFinish(err);
|
||||
throw err;
|
||||
}
|
||||
},
|
||||
cancel(reason) {
|
||||
_onFinish(reason);
|
||||
return iterator.return();
|
||||
},
|
||||
},
|
||||
{
|
||||
highWaterMark: 2,
|
||||
}
|
||||
);
|
||||
};
|
||||
110
extracted-source/node_modules/axios/lib/helpers/validator.js
generated
vendored
Normal file
110
extracted-source/node_modules/axios/lib/helpers/validator.js
generated
vendored
Normal file
@@ -0,0 +1,110 @@
|
||||
'use strict';
|
||||
|
||||
import { VERSION } from '../env/data.js';
|
||||
import AxiosError from '../core/AxiosError.js';
|
||||
|
||||
const validators = {};
|
||||
|
||||
// eslint-disable-next-line func-names
|
||||
['object', 'boolean', 'number', 'function', 'string', 'symbol'].forEach((type, i) => {
|
||||
validators[type] = function validator(thing) {
|
||||
return typeof thing === type || 'a' + (i < 1 ? 'n ' : ' ') + type;
|
||||
};
|
||||
});
|
||||
|
||||
const deprecatedWarnings = {};
|
||||
|
||||
/**
|
||||
* Transitional option validator
|
||||
*
|
||||
* @param {function|boolean?} validator - set to false if the transitional option has been removed
|
||||
* @param {string?} version - deprecated version / removed since version
|
||||
* @param {string?} message - some message with additional info
|
||||
*
|
||||
* @returns {function}
|
||||
*/
|
||||
validators.transitional = function transitional(validator, version, message) {
|
||||
function formatMessage(opt, desc) {
|
||||
return (
|
||||
'[Axios v' +
|
||||
VERSION +
|
||||
"] Transitional option '" +
|
||||
opt +
|
||||
"'" +
|
||||
desc +
|
||||
(message ? '. ' + message : '')
|
||||
);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line func-names
|
||||
return (value, opt, opts) => {
|
||||
if (validator === false) {
|
||||
throw new AxiosError(
|
||||
formatMessage(opt, ' has been removed' + (version ? ' in ' + version : '')),
|
||||
AxiosError.ERR_DEPRECATED
|
||||
);
|
||||
}
|
||||
|
||||
if (version && !deprecatedWarnings[opt]) {
|
||||
deprecatedWarnings[opt] = true;
|
||||
// eslint-disable-next-line no-console
|
||||
console.warn(
|
||||
formatMessage(
|
||||
opt,
|
||||
' has been deprecated since v' + version + ' and will be removed in the near future'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return validator ? validator(value, opt, opts) : true;
|
||||
};
|
||||
};
|
||||
|
||||
validators.spelling = function spelling(correctSpelling) {
|
||||
return (value, opt) => {
|
||||
// eslint-disable-next-line no-console
|
||||
console.warn(`${opt} is likely a misspelling of ${correctSpelling}`);
|
||||
return true;
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Assert object's properties type
|
||||
*
|
||||
* @param {object} options
|
||||
* @param {object} schema
|
||||
* @param {boolean?} allowUnknown
|
||||
*
|
||||
* @returns {object}
|
||||
*/
|
||||
|
||||
function assertOptions(options, schema, allowUnknown) {
|
||||
if (typeof options !== 'object') {
|
||||
throw new AxiosError('options must be an object', AxiosError.ERR_BAD_OPTION_VALUE);
|
||||
}
|
||||
const keys = Object.keys(options);
|
||||
let i = keys.length;
|
||||
while (i-- > 0) {
|
||||
const opt = keys[i];
|
||||
const validator = schema[opt];
|
||||
if (validator) {
|
||||
const value = options[opt];
|
||||
const result = value === undefined || validator(value, opt, options);
|
||||
if (result !== true) {
|
||||
throw new AxiosError(
|
||||
'option ' + opt + ' must be ' + result,
|
||||
AxiosError.ERR_BAD_OPTION_VALUE
|
||||
);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (allowUnknown !== true) {
|
||||
throw new AxiosError('Unknown option ' + opt, AxiosError.ERR_BAD_OPTION);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
assertOptions,
|
||||
validators,
|
||||
};
|
||||
Reference in New Issue
Block a user