mirror of
https://github.com/tenrok/axios.git
synced 2026-06-08 17:22:34 +03:00
Fixed missed minified builds; (#4805)
* Fixed missed minified builds; Refactored utils.js; Refactored `utils.isStandardBrowserEnv()` as a `platform/browser` property; Added builds size log; * Replaced `rollup-plugin-filesize` with `rollup-plugin-bundle-size`; Co-authored-by: Jay <jasonsaayman@gmail.com>
This commit is contained in:
+36
-89
@@ -4,29 +4,20 @@ import bind from './helpers/bind.js';
|
||||
|
||||
// utils is a library of generic helper functions non-specific to axios
|
||||
|
||||
const toString = Object.prototype.toString;
|
||||
const {toString} = Object.prototype;
|
||||
const {getPrototypeOf} = Object;
|
||||
|
||||
// eslint-disable-next-line func-names
|
||||
const kindOf = (cache => {
|
||||
// eslint-disable-next-line func-names
|
||||
return thing => {
|
||||
const kindOf = (cache => thing => {
|
||||
const str = toString.call(thing);
|
||||
return cache[str] || (cache[str] = str.slice(8, -1).toLowerCase());
|
||||
};
|
||||
})(Object.create(null));
|
||||
|
||||
function kindOfTest(type) {
|
||||
const kindOfTest = (type) => {
|
||||
type = type.toLowerCase();
|
||||
return function isKindOf(thing) {
|
||||
return kindOf(thing) === type;
|
||||
};
|
||||
return (thing) => kindOf(thing) === type
|
||||
}
|
||||
|
||||
function typeOfTest(type) {
|
||||
return thing => {
|
||||
return typeof thing === type;
|
||||
};
|
||||
}
|
||||
const typeOfTest = type => thing => typeof thing === type;
|
||||
|
||||
/**
|
||||
* Determine if a value is an Array
|
||||
@@ -35,9 +26,7 @@ function typeOfTest(type) {
|
||||
*
|
||||
* @returns {boolean} True if value is an Array, otherwise false
|
||||
*/
|
||||
function isArray(val) {
|
||||
return Array.isArray(val);
|
||||
}
|
||||
const {isArray} = Array;
|
||||
|
||||
/**
|
||||
* Determine if a value is undefined
|
||||
@@ -57,7 +46,7 @@ const isUndefined = typeOfTest('undefined');
|
||||
*/
|
||||
function isBuffer(val) {
|
||||
return val !== null && !isUndefined(val) && val.constructor !== null && !isUndefined(val.constructor)
|
||||
&& typeof val.constructor.isBuffer === 'function' && val.constructor.isBuffer(val);
|
||||
&& isFunction(val.constructor.isBuffer) && val.constructor.isBuffer(val);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -120,9 +109,7 @@ const isNumber = typeOfTest('number');
|
||||
*
|
||||
* @returns {boolean} True if value is an Object, otherwise false
|
||||
*/
|
||||
function isObject(thing) {
|
||||
return thing !== null && typeof thing === 'object';
|
||||
}
|
||||
const isObject = (thing) => thing !== null && typeof thing === 'object';
|
||||
|
||||
/**
|
||||
* Determine if a value is a Boolean
|
||||
@@ -130,9 +117,7 @@ function isObject(thing) {
|
||||
* @param {*} thing The value to test
|
||||
* @returns {boolean} True if value is a Boolean, otherwise false
|
||||
*/
|
||||
const isBoolean = thing => {
|
||||
return thing === true || thing === false;
|
||||
};
|
||||
const isBoolean = thing => thing === true || thing === false;
|
||||
|
||||
/**
|
||||
* Determine if a value is a plain Object
|
||||
@@ -141,12 +126,12 @@ const isBoolean = thing => {
|
||||
*
|
||||
* @returns {boolean} True if value is a plain Object, otherwise false
|
||||
*/
|
||||
function isPlainObject(val) {
|
||||
const isPlainObject = (val) => {
|
||||
if (kindOf(val) !== 'object') {
|
||||
return false;
|
||||
}
|
||||
|
||||
const prototype = Object.getPrototypeOf(val);
|
||||
const prototype = getPrototypeOf(val);
|
||||
return prototype === null || prototype === Object.prototype;
|
||||
}
|
||||
|
||||
@@ -193,9 +178,7 @@ const isFileList = kindOfTest('FileList');
|
||||
*
|
||||
* @returns {boolean} True if value is a Stream, otherwise false
|
||||
*/
|
||||
function isStream(val) {
|
||||
return isObject(val) && isFunction(val.pipe);
|
||||
}
|
||||
const isStream = (val) => isObject(val) && isFunction(val.pipe);
|
||||
|
||||
/**
|
||||
* Determine if a value is a FormData
|
||||
@@ -204,7 +187,7 @@ function isStream(val) {
|
||||
*
|
||||
* @returns {boolean} True if value is an FormData, otherwise false
|
||||
*/
|
||||
function isFormData(thing) {
|
||||
const isFormData = (thing) => {
|
||||
const pattern = '[object FormData]';
|
||||
return thing && (
|
||||
(typeof FormData === 'function' && thing instanceof FormData) ||
|
||||
@@ -229,39 +212,8 @@ const isURLSearchParams = kindOfTest('URLSearchParams');
|
||||
*
|
||||
* @returns {String} The String freed of excess whitespace
|
||||
*/
|
||||
function trim(str) {
|
||||
return str.trim ? str.trim() : str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if we're running in a standard browser environment
|
||||
*
|
||||
* This allows axios to run in a web worker, and react-native.
|
||||
* Both environments support XMLHttpRequest, but not fully standard globals.
|
||||
*
|
||||
* web workers:
|
||||
* typeof window -> undefined
|
||||
* typeof document -> undefined
|
||||
*
|
||||
* react-native:
|
||||
* navigator.product -> 'ReactNative'
|
||||
* nativescript
|
||||
* navigator.product -> 'NativeScript' or 'NS'
|
||||
*
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function isStandardBrowserEnv() {
|
||||
let product;
|
||||
if (typeof navigator !== 'undefined' && (
|
||||
(product = navigator.product) === 'ReactNative' ||
|
||||
product === 'NativeScript' ||
|
||||
product === 'NS')
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return typeof window !== 'undefined' && typeof document !== 'undefined';
|
||||
}
|
||||
const trim = (str) => str.trim ?
|
||||
str.trim() : str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
|
||||
|
||||
/**
|
||||
* Iterate over an Array or an Object invoking a function for each item.
|
||||
@@ -331,7 +283,7 @@ function forEach(obj, fn, {allOwnKeys = false} = {}) {
|
||||
*/
|
||||
function merge(/* obj1, obj2, obj3, ... */) {
|
||||
const result = {};
|
||||
function assignValue(val, key) {
|
||||
const assignValue = (val, key) => {
|
||||
if (isPlainObject(result[key]) && isPlainObject(val)) {
|
||||
result[key] = merge(result[key], val);
|
||||
} else if (isPlainObject(val)) {
|
||||
@@ -359,9 +311,9 @@ function merge(/* obj1, obj2, obj3, ... */) {
|
||||
* @param {Boolean} [allOwnKeys]
|
||||
* @returns {Object} The resulting value of object a
|
||||
*/
|
||||
function extend(a, b, thisArg, {allOwnKeys}= {}) {
|
||||
forEach(b, function assignValue(val, key) {
|
||||
if (thisArg && typeof val === 'function') {
|
||||
const extend = (a, b, thisArg, {allOwnKeys}= {}) => {
|
||||
forEach(b, (val, key) => {
|
||||
if (thisArg && isFunction(val)) {
|
||||
a[key] = bind(val, thisArg);
|
||||
} else {
|
||||
a[key] = val;
|
||||
@@ -377,7 +329,7 @@ function extend(a, b, thisArg, {allOwnKeys}= {}) {
|
||||
*
|
||||
* @returns {string} content value without BOM
|
||||
*/
|
||||
function stripBOM(content) {
|
||||
const stripBOM = (content) => {
|
||||
if (content.charCodeAt(0) === 0xFEFF) {
|
||||
content = content.slice(1);
|
||||
}
|
||||
@@ -393,7 +345,7 @@ function stripBOM(content) {
|
||||
*
|
||||
* @returns {void}
|
||||
*/
|
||||
function inherits(constructor, superConstructor, props, descriptors) {
|
||||
const inherits = (constructor, superConstructor, props, descriptors) => {
|
||||
constructor.prototype = Object.create(superConstructor.prototype, descriptors);
|
||||
constructor.prototype.constructor = constructor;
|
||||
Object.defineProperty(constructor, 'super', {
|
||||
@@ -411,7 +363,7 @@ function inherits(constructor, superConstructor, props, descriptors) {
|
||||
*
|
||||
* @returns {Object}
|
||||
*/
|
||||
function toFlatObject(sourceObj, destObj, filter, propFilter) {
|
||||
const toFlatObject = (sourceObj, destObj, filter, propFilter) => {
|
||||
let props;
|
||||
let i;
|
||||
let prop;
|
||||
@@ -431,7 +383,7 @@ function toFlatObject(sourceObj, destObj, filter, propFilter) {
|
||||
merged[prop] = true;
|
||||
}
|
||||
}
|
||||
sourceObj = filter !== false && Object.getPrototypeOf(sourceObj);
|
||||
sourceObj = filter !== false && getPrototypeOf(sourceObj);
|
||||
} while (sourceObj && (!filter || filter(sourceObj, destObj)) && sourceObj !== Object.prototype);
|
||||
|
||||
return destObj;
|
||||
@@ -446,7 +398,7 @@ function toFlatObject(sourceObj, destObj, filter, propFilter) {
|
||||
*
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function endsWith(str, searchString, position) {
|
||||
const endsWith = (str, searchString, position) => {
|
||||
str = String(str);
|
||||
if (position === undefined || position > str.length) {
|
||||
position = str.length;
|
||||
@@ -464,7 +416,7 @@ function endsWith(str, searchString, position) {
|
||||
*
|
||||
* @returns {?Array}
|
||||
*/
|
||||
function toArray(thing) {
|
||||
const toArray = (thing) => {
|
||||
if (!thing) return null;
|
||||
if (isArray(thing)) return thing;
|
||||
let i = thing.length;
|
||||
@@ -490,7 +442,7 @@ const isTypedArray = (TypedArray => {
|
||||
return thing => {
|
||||
return TypedArray && thing instanceof TypedArray;
|
||||
};
|
||||
})(typeof Uint8Array !== 'undefined' && Object.getPrototypeOf(Uint8Array));
|
||||
})(typeof Uint8Array !== 'undefined' && getPrototypeOf(Uint8Array));
|
||||
|
||||
/**
|
||||
* For each entry in the object, call the function with the key and value.
|
||||
@@ -500,7 +452,7 @@ const isTypedArray = (TypedArray => {
|
||||
*
|
||||
* @returns {void}
|
||||
*/
|
||||
function forEachEntry(obj, fn) {
|
||||
const forEachEntry = (obj, fn) => {
|
||||
const generator = obj && obj[Symbol.iterator];
|
||||
|
||||
const iterator = generator.call(obj);
|
||||
@@ -521,7 +473,7 @@ function forEachEntry(obj, fn) {
|
||||
*
|
||||
* @returns {Array<boolean>}
|
||||
*/
|
||||
function matchAll(regExp, str) {
|
||||
const matchAll = (regExp, str) => {
|
||||
let matches;
|
||||
const arr = [];
|
||||
|
||||
@@ -544,11 +496,7 @@ const toCamelCase = str => {
|
||||
};
|
||||
|
||||
/* Creating a function that will check if an object has a property. */
|
||||
const hasOwnProperty = (function resolver(_hasOwnProperty) {
|
||||
return (obj, prop) => {
|
||||
return _hasOwnProperty.call(obj, prop);
|
||||
};
|
||||
})(Object.prototype.hasOwnProperty);
|
||||
const hasOwnProperty = (({hasOwnProperty}) => (obj, prop) => hasOwnProperty.call(obj, prop))(Object.prototype);
|
||||
|
||||
/**
|
||||
* Determine if a value is a RegExp object
|
||||
@@ -559,7 +507,7 @@ const hasOwnProperty = (function resolver(_hasOwnProperty) {
|
||||
*/
|
||||
const isRegExp = kindOfTest('RegExp');
|
||||
|
||||
function reduceDescriptors(obj, reducer) {
|
||||
const reduceDescriptors = (obj, reducer) => {
|
||||
const descriptors = Object.getOwnPropertyDescriptors(obj);
|
||||
const reducedDescriptors = {};
|
||||
|
||||
@@ -577,7 +525,7 @@ function reduceDescriptors(obj, reducer) {
|
||||
* @param {Object} obj
|
||||
*/
|
||||
|
||||
function freezeMethods(obj) {
|
||||
const freezeMethods = (obj) => {
|
||||
reduceDescriptors(obj, (descriptor, name) => {
|
||||
const value = obj[name];
|
||||
|
||||
@@ -598,10 +546,10 @@ function freezeMethods(obj) {
|
||||
});
|
||||
}
|
||||
|
||||
function toObjectSet(arrayOrString, delimiter) {
|
||||
const toObjectSet = (arrayOrString, delimiter) => {
|
||||
const obj = {};
|
||||
|
||||
function define(arr) {
|
||||
const define = (arr) => {
|
||||
arr.forEach(value => {
|
||||
obj[value] = true;
|
||||
});
|
||||
@@ -612,9 +560,9 @@ function toObjectSet(arrayOrString, delimiter) {
|
||||
return obj;
|
||||
}
|
||||
|
||||
function noop() {}
|
||||
const noop = () => {}
|
||||
|
||||
function toFiniteNumber(value, defaultValue) {
|
||||
const toFiniteNumber = (value, defaultValue) => {
|
||||
value = +value;
|
||||
return Number.isFinite(value) ? value : defaultValue;
|
||||
}
|
||||
@@ -640,7 +588,6 @@ export default {
|
||||
isURLSearchParams,
|
||||
isTypedArray,
|
||||
isFileList,
|
||||
isStandardBrowserEnv,
|
||||
forEach,
|
||||
merge,
|
||||
extend,
|
||||
|
||||
Reference in New Issue
Block a user