aboutsummaryrefslogtreecommitdiff
path: root/node_modules/axios/lib/helpers
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2022-04-09 16:39:03 +0200
committerMinteck <contact@minteck.org>2022-04-09 16:40:02 +0200
commit0f8967b9113d698cdeb2d05ca85d2d9a80461c24 (patch)
tree00664ddd9c55a2c33631fd1bd33e556cea9c67e5 /node_modules/axios/lib/helpers
parentdac03ac82bc0f8044a4b339c27b5390e4dcecf2f (diff)
downloadvoicer-trunk.tar.gz
voicer-trunk.tar.bz2
voicer-trunk.zip
CommitHEADtrunk
Diffstat (limited to 'node_modules/axios/lib/helpers')
-rw-r--r--node_modules/axios/lib/helpers/README.md7
-rw-r--r--node_modules/axios/lib/helpers/bind.js11
-rw-r--r--node_modules/axios/lib/helpers/buildURL.js70
-rw-r--r--node_modules/axios/lib/helpers/combineURLs.js14
-rw-r--r--node_modules/axios/lib/helpers/cookies.js53
-rw-r--r--node_modules/axios/lib/helpers/deprecatedMethod.js24
-rw-r--r--node_modules/axios/lib/helpers/isAbsoluteURL.js14
-rw-r--r--node_modules/axios/lib/helpers/isAxiosError.js13
-rw-r--r--node_modules/axios/lib/helpers/isURLSameOrigin.js68
-rw-r--r--node_modules/axios/lib/helpers/normalizeHeaderName.js12
-rw-r--r--node_modules/axios/lib/helpers/parseHeaders.js53
-rw-r--r--node_modules/axios/lib/helpers/spread.js27
-rw-r--r--node_modules/axios/lib/helpers/toFormData.js55
-rw-r--r--node_modules/axios/lib/helpers/validator.js82
14 files changed, 503 insertions, 0 deletions
diff --git a/node_modules/axios/lib/helpers/README.md b/node_modules/axios/lib/helpers/README.md
new file mode 100644
index 0000000..4ae3419
--- /dev/null
+++ b/node_modules/axios/lib/helpers/README.md
@@ -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
diff --git a/node_modules/axios/lib/helpers/bind.js b/node_modules/axios/lib/helpers/bind.js
new file mode 100644
index 0000000..6147c60
--- /dev/null
+++ b/node_modules/axios/lib/helpers/bind.js
@@ -0,0 +1,11 @@
+'use strict';
+
+module.exports = function bind(fn, thisArg) {
+ return function wrap() {
+ var args = new Array(arguments.length);
+ for (var i = 0; i < args.length; i++) {
+ args[i] = arguments[i];
+ }
+ return fn.apply(thisArg, args);
+ };
+};
diff --git a/node_modules/axios/lib/helpers/buildURL.js b/node_modules/axios/lib/helpers/buildURL.js
new file mode 100644
index 0000000..31595c3
--- /dev/null
+++ b/node_modules/axios/lib/helpers/buildURL.js
@@ -0,0 +1,70 @@
+'use strict';
+
+var utils = require('./../utils');
+
+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
+ * @returns {string} The formatted url
+ */
+module.exports = function buildURL(url, params, paramsSerializer) {
+ /*eslint no-param-reassign:0*/
+ if (!params) {
+ return url;
+ }
+
+ var serializedParams;
+ if (paramsSerializer) {
+ serializedParams = paramsSerializer(params);
+ } else if (utils.isURLSearchParams(params)) {
+ serializedParams = params.toString();
+ } else {
+ var parts = [];
+
+ utils.forEach(params, function serialize(val, key) {
+ if (val === null || typeof val === 'undefined') {
+ return;
+ }
+
+ if (utils.isArray(val)) {
+ key = key + '[]';
+ } else {
+ val = [val];
+ }
+
+ utils.forEach(val, function parseValue(v) {
+ if (utils.isDate(v)) {
+ v = v.toISOString();
+ } else if (utils.isObject(v)) {
+ v = JSON.stringify(v);
+ }
+ parts.push(encode(key) + '=' + encode(v));
+ });
+ });
+
+ serializedParams = parts.join('&');
+ }
+
+ if (serializedParams) {
+ var hashmarkIndex = url.indexOf('#');
+ if (hashmarkIndex !== -1) {
+ url = url.slice(0, hashmarkIndex);
+ }
+
+ url += (url.indexOf('?') === -1 ? '?' : '&') + serializedParams;
+ }
+
+ return url;
+};
diff --git a/node_modules/axios/lib/helpers/combineURLs.js b/node_modules/axios/lib/helpers/combineURLs.js
new file mode 100644
index 0000000..f1b58a5
--- /dev/null
+++ b/node_modules/axios/lib/helpers/combineURLs.js
@@ -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;
+};
diff --git a/node_modules/axios/lib/helpers/cookies.js b/node_modules/axios/lib/helpers/cookies.js
new file mode 100644
index 0000000..5a8a666
--- /dev/null
+++ b/node_modules/axios/lib/helpers/cookies.js
@@ -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() {}
+ };
+ })()
+);
diff --git a/node_modules/axios/lib/helpers/deprecatedMethod.js b/node_modules/axios/lib/helpers/deprecatedMethod.js
new file mode 100644
index 0000000..ed40965
--- /dev/null
+++ b/node_modules/axios/lib/helpers/deprecatedMethod.js
@@ -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 */ }
+};
diff --git a/node_modules/axios/lib/helpers/isAbsoluteURL.js b/node_modules/axios/lib/helpers/isAbsoluteURL.js
new file mode 100644
index 0000000..43fea78
--- /dev/null
+++ b/node_modules/axios/lib/helpers/isAbsoluteURL.js
@@ -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);
+};
diff --git a/node_modules/axios/lib/helpers/isAxiosError.js b/node_modules/axios/lib/helpers/isAxiosError.js
new file mode 100644
index 0000000..a037bec
--- /dev/null
+++ b/node_modules/axios/lib/helpers/isAxiosError.js
@@ -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);
+};
diff --git a/node_modules/axios/lib/helpers/isURLSameOrigin.js b/node_modules/axios/lib/helpers/isURLSameOrigin.js
new file mode 100644
index 0000000..f1d89ad
--- /dev/null
+++ b/node_modules/axios/lib/helpers/isURLSameOrigin.js
@@ -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;
+ };
+ })()
+);
diff --git a/node_modules/axios/lib/helpers/normalizeHeaderName.js b/node_modules/axios/lib/helpers/normalizeHeaderName.js
new file mode 100644
index 0000000..738c9fe
--- /dev/null
+++ b/node_modules/axios/lib/helpers/normalizeHeaderName.js
@@ -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];
+ }
+ });
+};
diff --git a/node_modules/axios/lib/helpers/parseHeaders.js b/node_modules/axios/lib/helpers/parseHeaders.js
new file mode 100644
index 0000000..8af2cc7
--- /dev/null
+++ b/node_modules/axios/lib/helpers/parseHeaders.js
@@ -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.substr(0, i)).toLowerCase();
+ val = utils.trim(line.substr(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;
+};
diff --git a/node_modules/axios/lib/helpers/spread.js b/node_modules/axios/lib/helpers/spread.js
new file mode 100644
index 0000000..25e3cdd
--- /dev/null
+++ b/node_modules/axios/lib/helpers/spread.js
@@ -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);
+ };
+};
diff --git a/node_modules/axios/lib/helpers/toFormData.js b/node_modules/axios/lib/helpers/toFormData.js
new file mode 100644
index 0000000..e21d0a7
--- /dev/null
+++ b/node_modules/axios/lib/helpers/toFormData.js
@@ -0,0 +1,55 @@
+'use strict';
+
+function combinedKey(parentKey, elKey) {
+ return parentKey + '.' + elKey;
+}
+
+function buildFormData(formData, data, parentKey) {
+ if (Array.isArray(data)) {
+ data.forEach(function buildArray(el, i) {
+ buildFormData(formData, el, combinedKey(parentKey, i));
+ });
+ } else if (
+ typeof data === 'object' &&
+ !(data instanceof File || data === null)
+ ) {
+ Object.keys(data).forEach(function buildObject(key) {
+ buildFormData(
+ formData,
+ data[key],
+ parentKey ? combinedKey(parentKey, key) : key
+ );
+ });
+ } else {
+ if (data === undefined) {
+ return;
+ }
+
+ var value =
+ typeof data === 'boolean' || typeof data === 'number'
+ ? data.toString()
+ : data;
+ formData.append(parentKey, value);
+ }
+}
+
+/**
+ * convert a data object to FormData
+ *
+ * type FormDataPrimitive = string | Blob | number | boolean
+ * interface FormDataNest {
+ * [x: string]: FormVal
+ * }
+ *
+ * type FormVal = FormDataNest | FormDataPrimitive
+ *
+ * @param {FormVal} data
+ */
+
+module.exports = function getFormData(data) {
+ var formData = new FormData();
+
+ buildFormData(formData, data);
+
+ return formData;
+};
diff --git a/node_modules/axios/lib/helpers/validator.js b/node_modules/axios/lib/helpers/validator.js
new file mode 100644
index 0000000..a4ec413
--- /dev/null
+++ b/node_modules/axios/lib/helpers/validator.js
@@ -0,0 +1,82 @@
+'use strict';
+
+var VERSION = require('../env/data').version;
+
+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 Error(formatMessage(opt, ' has been removed' + (version ? ' in ' + version : '')));
+ }
+
+ 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 TypeError('options must be an object');
+ }
+ 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 TypeError('option ' + opt + ' must be ' + result);
+ }
+ continue;
+ }
+ if (allowUnknown !== true) {
+ throw Error('Unknown option ' + opt);
+ }
+ }
+}
+
+module.exports = {
+ assertOptions: assertOptions,
+ validators: validators
+};