Dep update
This commit is contained in:
42
node_modules/axios/lib/helpers/AxiosURLSearchParams.js
generated
vendored
Normal file
42
node_modules/axios/lib/helpers/AxiosURLSearchParams.js
generated
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
'use strict';
|
||||
|
||||
var toFormData = require('./toFormData');
|
||||
|
||||
function encode(str) {
|
||||
var charMap = {
|
||||
'!': '%21',
|
||||
"'": '%27',
|
||||
'(': '%28',
|
||||
')': '%29',
|
||||
'~': '%7E',
|
||||
'%20': '+',
|
||||
'%00': '\x00'
|
||||
};
|
||||
return encodeURIComponent(str).replace(/[!'\(\)~]|%20|%00/g, function replacer(match) {
|
||||
return charMap[match];
|
||||
});
|
||||
}
|
||||
|
||||
function AxiosURLSearchParams(params, options) {
|
||||
this._pairs = [];
|
||||
|
||||
params && toFormData(params, this, options);
|
||||
}
|
||||
|
||||
var prototype = AxiosURLSearchParams.prototype;
|
||||
|
||||
prototype.append = function append(name, value) {
|
||||
this._pairs.push([name, value]);
|
||||
};
|
||||
|
||||
prototype.toString = function toString(encoder) {
|
||||
var _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('&');
|
||||
};
|
||||
|
||||
module.exports = AxiosURLSearchParams;
|
7
node_modules/axios/lib/helpers/README.md
generated
vendored
Normal file
7
node_modules/axios/lib/helpers/README.md
generated
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
# axios // helpers
|
||||
|
||||
The modules found in `helpers/` should be generic modules that are _not_ specific to the domain logic of axios. These modules could theoretically be published to npm on their own and consumed by other modules or apps. Some examples of generic modules are things like:
|
||||
|
||||
- Browser polyfills
|
||||
- Managing cookies
|
||||
- Parsing HTTP headers
|
7
node_modules/axios/lib/helpers/bind.js
generated
vendored
Normal file
7
node_modules/axios/lib/helpers/bind.js
generated
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function bind(fn, thisArg) {
|
||||
return function wrap() {
|
||||
return fn.apply(thisArg, arguments);
|
||||
};
|
||||
};
|
55
node_modules/axios/lib/helpers/buildURL.js
generated
vendored
Normal file
55
node_modules/axios/lib/helpers/buildURL.js
generated
vendored
Normal file
@ -0,0 +1,55 @@
|
||||
'use strict';
|
||||
|
||||
var utils = require('../utils');
|
||||
var AxiosURLSearchParams = require('../helpers/AxiosURLSearchParams');
|
||||
|
||||
function encode(val) {
|
||||
return encodeURIComponent(val).
|
||||
replace(/%3A/gi, ':').
|
||||
replace(/%24/g, '$').
|
||||
replace(/%2C/gi, ',').
|
||||
replace(/%20/g, '+').
|
||||
replace(/%5B/gi, '[').
|
||||
replace(/%5D/gi, ']');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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} options
|
||||
* @returns {string} The formatted url
|
||||
*/
|
||||
module.exports = function buildURL(url, params, options) {
|
||||
/*eslint no-param-reassign:0*/
|
||||
if (!params) {
|
||||
return url;
|
||||
}
|
||||
|
||||
var hashmarkIndex = url.indexOf('#');
|
||||
|
||||
if (hashmarkIndex !== -1) {
|
||||
url = url.slice(0, hashmarkIndex);
|
||||
}
|
||||
|
||||
var _encode = options && options.encode || encode;
|
||||
|
||||
var serializeFn = options && options.serialize;
|
||||
|
||||
var serializedParams;
|
||||
|
||||
if (serializeFn) {
|
||||
serializedParams = serializeFn(params, options);
|
||||
} else {
|
||||
serializedParams = utils.isURLSearchParams(params) ?
|
||||
params.toString() :
|
||||
new AxiosURLSearchParams(params, options).toString(_encode);
|
||||
}
|
||||
|
||||
if (serializedParams) {
|
||||
url += (url.indexOf('?') === -1 ? '?' : '&') + serializedParams;
|
||||
}
|
||||
|
||||
return url;
|
||||
};
|
14
node_modules/axios/lib/helpers/combineURLs.js
generated
vendored
Normal file
14
node_modules/axios/lib/helpers/combineURLs.js
generated
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
'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
|
||||
*/
|
||||
module.exports = function combineURLs(baseURL, relativeURL) {
|
||||
return relativeURL
|
||||
? baseURL.replace(/\/+$/, '') + '/' + relativeURL.replace(/^\/+/, '')
|
||||
: baseURL;
|
||||
};
|
53
node_modules/axios/lib/helpers/cookies.js
generated
vendored
Normal file
53
node_modules/axios/lib/helpers/cookies.js
generated
vendored
Normal file
@ -0,0 +1,53 @@
|
||||
'use strict';
|
||||
|
||||
var utils = require('./../utils');
|
||||
|
||||
module.exports = (
|
||||
utils.isStandardBrowserEnv() ?
|
||||
|
||||
// Standard browser envs support document.cookie
|
||||
(function standardBrowserEnv() {
|
||||
return {
|
||||
write: function write(name, value, expires, path, domain, secure) {
|
||||
var cookie = [];
|
||||
cookie.push(name + '=' + encodeURIComponent(value));
|
||||
|
||||
if (utils.isNumber(expires)) {
|
||||
cookie.push('expires=' + new Date(expires).toGMTString());
|
||||
}
|
||||
|
||||
if (utils.isString(path)) {
|
||||
cookie.push('path=' + path);
|
||||
}
|
||||
|
||||
if (utils.isString(domain)) {
|
||||
cookie.push('domain=' + domain);
|
||||
}
|
||||
|
||||
if (secure === true) {
|
||||
cookie.push('secure');
|
||||
}
|
||||
|
||||
document.cookie = cookie.join('; ');
|
||||
},
|
||||
|
||||
read: function read(name) {
|
||||
var match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
|
||||
return (match ? decodeURIComponent(match[3]) : null);
|
||||
},
|
||||
|
||||
remove: function remove(name) {
|
||||
this.write(name, '', Date.now() - 86400000);
|
||||
}
|
||||
};
|
||||
})() :
|
||||
|
||||
// Non standard browser env (web workers, react-native) lack needed support.
|
||||
(function nonStandardBrowserEnv() {
|
||||
return {
|
||||
write: function write() {},
|
||||
read: function read() { return null; },
|
||||
remove: function remove() {}
|
||||
};
|
||||
})()
|
||||
);
|
24
node_modules/axios/lib/helpers/deprecatedMethod.js
generated
vendored
Normal file
24
node_modules/axios/lib/helpers/deprecatedMethod.js
generated
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
'use strict';
|
||||
|
||||
/*eslint no-console:0*/
|
||||
|
||||
/**
|
||||
* Supply a warning to the developer that a method they are using
|
||||
* has been deprecated.
|
||||
*
|
||||
* @param {string} method The name of the deprecated method
|
||||
* @param {string} [instead] The alternate method to use if applicable
|
||||
* @param {string} [docs] The documentation URL to get further details
|
||||
*/
|
||||
module.exports = function deprecatedMethod(method, instead, docs) {
|
||||
try {
|
||||
console.warn(
|
||||
'DEPRECATED method `' + method + '`.' +
|
||||
(instead ? ' Use `' + instead + '` instead.' : '') +
|
||||
' This method will be removed in a future release.');
|
||||
|
||||
if (docs) {
|
||||
console.warn('For more information about usage see ' + docs);
|
||||
}
|
||||
} catch (e) { /* Ignore */ }
|
||||
};
|
71
node_modules/axios/lib/helpers/formDataToJSON.js
generated
vendored
Normal file
71
node_modules/axios/lib/helpers/formDataToJSON.js
generated
vendored
Normal file
@ -0,0 +1,71 @@
|
||||
'use strict';
|
||||
|
||||
var utils = require('../utils');
|
||||
|
||||
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(function(match) {
|
||||
return match[0] === '[]' ? '' : match[1] || match[0];
|
||||
});
|
||||
}
|
||||
|
||||
function arrayToObject(arr) {
|
||||
var obj = {};
|
||||
var keys = Object.keys(arr);
|
||||
var i;
|
||||
var len = keys.length;
|
||||
var key;
|
||||
for (i = 0; i < len; i++) {
|
||||
key = keys[i];
|
||||
obj[key] = arr[key];
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
function formDataToJSON(formData) {
|
||||
function buildPath(path, value, target, index) {
|
||||
var name = path[index++];
|
||||
var isNumericKey = Number.isFinite(+name);
|
||||
var isLast = index >= path.length;
|
||||
name = !name && utils.isArray(target) ? target.length : name;
|
||||
|
||||
if (isLast) {
|
||||
if (utils.hasOwnProperty(target, name)) {
|
||||
target[name] = [target[name], value];
|
||||
} else {
|
||||
target[name] = value;
|
||||
}
|
||||
|
||||
return !isNumericKey;
|
||||
}
|
||||
|
||||
if (!target[name] || !utils.isObject(target[name])) {
|
||||
target[name] = [];
|
||||
}
|
||||
|
||||
var 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)) {
|
||||
var obj = {};
|
||||
|
||||
utils.forEachEntry(formData, function(name, value) {
|
||||
buildPath(parsePropPath(name), value, obj, 0);
|
||||
});
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
module.exports = formDataToJSON;
|
51
node_modules/axios/lib/helpers/fromDataURI.js
generated
vendored
Normal file
51
node_modules/axios/lib/helpers/fromDataURI.js
generated
vendored
Normal file
@ -0,0 +1,51 @@
|
||||
'use strict';
|
||||
|
||||
var AxiosError = require('../core/AxiosError');
|
||||
var parseProtocol = require('./parseProtocol');
|
||||
var platform = require('../platform');
|
||||
|
||||
var 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}
|
||||
*/
|
||||
module.exports = function fromDataURI(uri, asBlob, options) {
|
||||
var _Blob = options && options.Blob || platform.classes.Blob;
|
||||
var protocol = parseProtocol(uri);
|
||||
|
||||
if (asBlob === undefined && _Blob) {
|
||||
asBlob = true;
|
||||
}
|
||||
|
||||
if (protocol === 'data') {
|
||||
uri = protocol.length ? uri.slice(protocol.length + 1) : uri;
|
||||
|
||||
var match = DATA_URL_PATTERN.exec(uri);
|
||||
|
||||
if (!match) {
|
||||
throw new AxiosError('Invalid URL', AxiosError.ERR_INVALID_URL);
|
||||
}
|
||||
|
||||
var mime = match[1];
|
||||
var isBase64 = match[2];
|
||||
var body = match[3];
|
||||
var 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);
|
||||
};
|
14
node_modules/axios/lib/helpers/isAbsoluteURL.js
generated
vendored
Normal file
14
node_modules/axios/lib/helpers/isAbsoluteURL.js
generated
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
'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
|
||||
*/
|
||||
module.exports = 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.
|
||||
return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url);
|
||||
};
|
13
node_modules/axios/lib/helpers/isAxiosError.js
generated
vendored
Normal file
13
node_modules/axios/lib/helpers/isAxiosError.js
generated
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
var utils = require('./../utils');
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
module.exports = function isAxiosError(payload) {
|
||||
return utils.isObject(payload) && (payload.isAxiosError === true);
|
||||
};
|
68
node_modules/axios/lib/helpers/isURLSameOrigin.js
generated
vendored
Normal file
68
node_modules/axios/lib/helpers/isURLSameOrigin.js
generated
vendored
Normal file
@ -0,0 +1,68 @@
|
||||
'use strict';
|
||||
|
||||
var utils = require('./../utils');
|
||||
|
||||
module.exports = (
|
||||
utils.isStandardBrowserEnv() ?
|
||||
|
||||
// Standard browser envs have full support of the APIs needed to test
|
||||
// whether the request URL is of the same origin as current location.
|
||||
(function standardBrowserEnv() {
|
||||
var msie = /(msie|trident)/i.test(navigator.userAgent);
|
||||
var urlParsingNode = document.createElement('a');
|
||||
var originURL;
|
||||
|
||||
/**
|
||||
* Parse a URL to discover it's components
|
||||
*
|
||||
* @param {String} url The URL to be parsed
|
||||
* @returns {Object}
|
||||
*/
|
||||
function resolveURL(url) {
|
||||
var href = url;
|
||||
|
||||
if (msie) {
|
||||
// IE needs attribute set twice to normalize properties
|
||||
urlParsingNode.setAttribute('href', href);
|
||||
href = urlParsingNode.href;
|
||||
}
|
||||
|
||||
urlParsingNode.setAttribute('href', href);
|
||||
|
||||
// urlParsingNode provides the UrlUtils interface - http://url.spec.whatwg.org/#urlutils
|
||||
return {
|
||||
href: urlParsingNode.href,
|
||||
protocol: urlParsingNode.protocol ? urlParsingNode.protocol.replace(/:$/, '') : '',
|
||||
host: urlParsingNode.host,
|
||||
search: urlParsingNode.search ? urlParsingNode.search.replace(/^\?/, '') : '',
|
||||
hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, '') : '',
|
||||
hostname: urlParsingNode.hostname,
|
||||
port: urlParsingNode.port,
|
||||
pathname: (urlParsingNode.pathname.charAt(0) === '/') ?
|
||||
urlParsingNode.pathname :
|
||||
'/' + urlParsingNode.pathname
|
||||
};
|
||||
}
|
||||
|
||||
originURL = resolveURL(window.location.href);
|
||||
|
||||
/**
|
||||
* Determine if a URL shares the same origin as the current location
|
||||
*
|
||||
* @param {String} requestURL The URL to test
|
||||
* @returns {boolean} True if URL shares the same origin, otherwise false
|
||||
*/
|
||||
return function isURLSameOrigin(requestURL) {
|
||||
var parsed = (utils.isString(requestURL)) ? resolveURL(requestURL) : requestURL;
|
||||
return (parsed.protocol === originURL.protocol &&
|
||||
parsed.host === originURL.host);
|
||||
};
|
||||
})() :
|
||||
|
||||
// Non standard browser envs (web workers, react-native) lack needed support.
|
||||
(function nonStandardBrowserEnv() {
|
||||
return function isURLSameOrigin() {
|
||||
return true;
|
||||
};
|
||||
})()
|
||||
);
|
12
node_modules/axios/lib/helpers/normalizeHeaderName.js
generated
vendored
Normal file
12
node_modules/axios/lib/helpers/normalizeHeaderName.js
generated
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
'use strict';
|
||||
|
||||
var utils = require('../utils');
|
||||
|
||||
module.exports = function normalizeHeaderName(headers, normalizedName) {
|
||||
utils.forEach(headers, function processHeader(value, name) {
|
||||
if (name !== normalizedName && name.toUpperCase() === normalizedName.toUpperCase()) {
|
||||
headers[normalizedName] = value;
|
||||
delete headers[name];
|
||||
}
|
||||
});
|
||||
};
|
2
node_modules/axios/lib/helpers/null.js
generated
vendored
Normal file
2
node_modules/axios/lib/helpers/null.js
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
// eslint-disable-next-line strict
|
||||
module.exports = null;
|
53
node_modules/axios/lib/helpers/parseHeaders.js
generated
vendored
Normal file
53
node_modules/axios/lib/helpers/parseHeaders.js
generated
vendored
Normal file
@ -0,0 +1,53 @@
|
||||
'use strict';
|
||||
|
||||
var utils = require('./../utils');
|
||||
|
||||
// Headers whose duplicates are ignored by node
|
||||
// c.f. https://nodejs.org/api/http.html#http_message_headers
|
||||
var ignoreDuplicateOf = [
|
||||
'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} headers Headers needing to be parsed
|
||||
* @returns {Object} Headers parsed into an object
|
||||
*/
|
||||
module.exports = function parseHeaders(headers) {
|
||||
var parsed = {};
|
||||
var key;
|
||||
var val;
|
||||
var i;
|
||||
|
||||
if (!headers) { return parsed; }
|
||||
|
||||
utils.forEach(headers.split('\n'), function parser(line) {
|
||||
i = line.indexOf(':');
|
||||
key = utils.trim(line.slice(0, i)).toLowerCase();
|
||||
val = utils.trim(line.slice(i + 1));
|
||||
|
||||
if (key) {
|
||||
if (parsed[key] && ignoreDuplicateOf.indexOf(key) >= 0) {
|
||||
return;
|
||||
}
|
||||
if (key === 'set-cookie') {
|
||||
parsed[key] = (parsed[key] ? parsed[key] : []).concat([val]);
|
||||
} else {
|
||||
parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return parsed;
|
||||
};
|
6
node_modules/axios/lib/helpers/parseProtocol.js
generated
vendored
Normal file
6
node_modules/axios/lib/helpers/parseProtocol.js
generated
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function parseProtocol(url) {
|
||||
var match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url);
|
||||
return match && match[1] || '';
|
||||
};
|
27
node_modules/axios/lib/helpers/spread.js
generated
vendored
Normal file
27
node_modules/axios/lib/helpers/spread.js
generated
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
'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) {}
|
||||
* var 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}
|
||||
*/
|
||||
module.exports = function spread(callback) {
|
||||
return function wrap(arr) {
|
||||
return callback.apply(null, arr);
|
||||
};
|
||||
};
|
179
node_modules/axios/lib/helpers/toFormData.js
generated
vendored
Normal file
179
node_modules/axios/lib/helpers/toFormData.js
generated
vendored
Normal file
@ -0,0 +1,179 @@
|
||||
'use strict';
|
||||
|
||||
var utils = require('../utils');
|
||||
var AxiosError = require('../core/AxiosError');
|
||||
var envFormData = require('../env/classes/FormData');
|
||||
|
||||
function isVisitable(thing) {
|
||||
return utils.isPlainObject(thing) || utils.isArray(thing);
|
||||
}
|
||||
|
||||
function removeBrackets(key) {
|
||||
return utils.endsWith(key, '[]') ? key.slice(0, -2) : 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 ? '.' : '');
|
||||
}
|
||||
|
||||
function isFlatArray(arr) {
|
||||
return utils.isArray(arr) && !arr.some(isVisitable);
|
||||
}
|
||||
|
||||
var predicates = utils.toFlatObject(utils, {}, null, function filter(prop) {
|
||||
return /^is[A-Z]/.test(prop);
|
||||
});
|
||||
|
||||
function isSpecCompliant(thing) {
|
||||
return thing && utils.isFunction(thing.append) && thing[Symbol.toStringTag] === 'FormData' && thing[Symbol.iterator];
|
||||
}
|
||||
|
||||
/**
|
||||
* 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}
|
||||
**/
|
||||
|
||||
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 (envFormData || 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]);
|
||||
});
|
||||
|
||||
var metaTokens = options.metaTokens;
|
||||
// eslint-disable-next-line no-use-before-define
|
||||
var visitor = options.visitor || defaultVisitor;
|
||||
var dots = options.dots;
|
||||
var indexes = options.indexes;
|
||||
var _Blob = options.Blob || typeof Blob !== 'undefined' && Blob;
|
||||
var useBlob = _Blob && isSpecCompliant(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 (!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;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @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) {
|
||||
var arr = value;
|
||||
|
||||
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) && 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;
|
||||
}
|
||||
|
||||
var stack = [];
|
||||
|
||||
var exposedHelpers = Object.assign(predicates, {
|
||||
defaultVisitor: defaultVisitor,
|
||||
convertValue: convertValue,
|
||||
isVisitable: 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) {
|
||||
var result = !utils.isUndefined(el) && 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;
|
||||
}
|
||||
|
||||
module.exports = toFormData;
|
18
node_modules/axios/lib/helpers/toURLEncodedForm.js
generated
vendored
Normal file
18
node_modules/axios/lib/helpers/toURLEncodedForm.js
generated
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
'use strict';
|
||||
|
||||
var utils = require('../utils');
|
||||
var toFormData = require('./toFormData');
|
||||
var platform = require('../platform/');
|
||||
|
||||
module.exports = function toURLEncodedForm(data, options) {
|
||||
return toFormData(data, new platform.classes.URLSearchParams(), Object.assign({
|
||||
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));
|
||||
};
|
86
node_modules/axios/lib/helpers/validator.js
generated
vendored
Normal file
86
node_modules/axios/lib/helpers/validator.js
generated
vendored
Normal file
@ -0,0 +1,86 @@
|
||||
'use strict';
|
||||
|
||||
var VERSION = require('../env/data').version;
|
||||
var AxiosError = require('../core/AxiosError');
|
||||
|
||||
var validators = {};
|
||||
|
||||
// eslint-disable-next-line func-names
|
||||
['object', 'boolean', 'number', 'function', 'string', 'symbol'].forEach(function(type, i) {
|
||||
validators[type] = function validator(thing) {
|
||||
return typeof thing === type || 'a' + (i < 1 ? 'n ' : ' ') + type;
|
||||
};
|
||||
});
|
||||
|
||||
var 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 function(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;
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Assert object's properties type
|
||||
* @param {object} options
|
||||
* @param {object} schema
|
||||
* @param {boolean?} allowUnknown
|
||||
*/
|
||||
|
||||
function assertOptions(options, schema, allowUnknown) {
|
||||
if (typeof options !== 'object') {
|
||||
throw new AxiosError('options must be an object', AxiosError.ERR_BAD_OPTION_VALUE);
|
||||
}
|
||||
var keys = Object.keys(options);
|
||||
var i = keys.length;
|
||||
while (i-- > 0) {
|
||||
var opt = keys[i];
|
||||
var validator = schema[opt];
|
||||
if (validator) {
|
||||
var value = options[opt];
|
||||
var 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
assertOptions: assertOptions,
|
||||
validators: validators
|
||||
};
|
Reference in New Issue
Block a user