mirror of
https://github.com/tenrok/axios.git
synced 2026-06-17 19:21:29 +03:00
Fixed merge conflicts
This commit is contained in:
+100
-27
@@ -6,6 +6,22 @@ var bind = require('./helpers/bind');
|
||||
|
||||
var toString = Object.prototype.toString;
|
||||
|
||||
// eslint-disable-next-line func-names
|
||||
var kindOf = (function(cache) {
|
||||
// eslint-disable-next-line func-names
|
||||
return function(thing) {
|
||||
var str = toString.call(thing);
|
||||
return cache[str] || (cache[str] = str.slice(8, -1).toLowerCase());
|
||||
};
|
||||
})(Object.create(null));
|
||||
|
||||
function kindOfTest(type) {
|
||||
type = type.toLowerCase();
|
||||
return function isKindOf(thing) {
|
||||
return kindOf(thing) === type;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Array with axios supported protocols.
|
||||
*/
|
||||
@@ -56,22 +72,12 @@ function isBuffer(val) {
|
||||
/**
|
||||
* Determine if a value is an ArrayBuffer
|
||||
*
|
||||
* @function
|
||||
* @param {Object} val The value to test
|
||||
* @returns {boolean} True if value is an ArrayBuffer, otherwise false
|
||||
*/
|
||||
function isArrayBuffer(val) {
|
||||
return toString.call(val) === '[object ArrayBuffer]';
|
||||
}
|
||||
var isArrayBuffer = kindOfTest('ArrayBuffer');
|
||||
|
||||
/**
|
||||
* Determine if a value is a FormData
|
||||
*
|
||||
* @param {Object} val The value to test
|
||||
* @returns {boolean} True if value is an FormData, otherwise false
|
||||
*/
|
||||
function isFormData(val) {
|
||||
return toString.call(val) === '[object FormData]';
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a value is a view on an ArrayBuffer
|
||||
@@ -126,7 +132,7 @@ function isObject(val) {
|
||||
* @return {boolean} True if value is a plain Object, otherwise false
|
||||
*/
|
||||
function isPlainObject(val) {
|
||||
if (toString.call(val) !== '[object Object]') {
|
||||
if (kindOf(val) !== 'object') {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -137,32 +143,38 @@ function isPlainObject(val) {
|
||||
/**
|
||||
* Determine if a value is a Date
|
||||
*
|
||||
* @function
|
||||
* @param {Object} val The value to test
|
||||
* @returns {boolean} True if value is a Date, otherwise false
|
||||
*/
|
||||
function isDate(val) {
|
||||
return toString.call(val) === '[object Date]';
|
||||
}
|
||||
var isDate = kindOfTest('Date');
|
||||
|
||||
/**
|
||||
* Determine if a value is a File
|
||||
*
|
||||
* @function
|
||||
* @param {Object} val The value to test
|
||||
* @returns {boolean} True if value is a File, otherwise false
|
||||
*/
|
||||
function isFile(val) {
|
||||
return toString.call(val) === '[object File]';
|
||||
}
|
||||
var isFile = kindOfTest('File');
|
||||
|
||||
/**
|
||||
* Determine if a value is a Blob
|
||||
*
|
||||
* @function
|
||||
* @param {Object} val The value to test
|
||||
* @returns {boolean} True if value is a Blob, otherwise false
|
||||
*/
|
||||
function isBlob(val) {
|
||||
return toString.call(val) === '[object Blob]';
|
||||
}
|
||||
var isBlob = kindOfTest('Blob');
|
||||
|
||||
/**
|
||||
* Determine if a value is a FileList
|
||||
*
|
||||
* @function
|
||||
* @param {Object} val The value to test
|
||||
* @returns {boolean} True if value is a File, otherwise false
|
||||
*/
|
||||
var isFileList = kindOfTest('FileList');
|
||||
|
||||
/**
|
||||
* Determine if a value is a Function
|
||||
@@ -185,14 +197,27 @@ function isStream(val) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a value is a URLSearchParams object
|
||||
* Determine if a value is a FormData
|
||||
*
|
||||
* @param {Object} thing The value to test
|
||||
* @returns {boolean} True if value is an FormData, otherwise false
|
||||
*/
|
||||
function isFormData(thing) {
|
||||
var pattern = '[object FormData]';
|
||||
return thing && (
|
||||
(typeof FormData === 'function' && thing instanceof FormData) ||
|
||||
toString.call(thing) === pattern ||
|
||||
(isFunction(thing.toString) && thing.toString() === pattern)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a value is a URLSearchParams object
|
||||
* @function
|
||||
* @param {Object} val The value to test
|
||||
* @returns {boolean} True if value is a URLSearchParams object, otherwise false
|
||||
*/
|
||||
function isURLSearchParams(val) {
|
||||
return toString.call(val) === '[object URLSearchParams]';
|
||||
}
|
||||
var isURLSearchParams = kindOfTest('URLSearchParams');
|
||||
|
||||
/**
|
||||
* Trim excess whitespace off the beginning and end of a string
|
||||
@@ -385,6 +410,48 @@ function toFlatObject(sourceObj, destObj, filter) {
|
||||
return destObj;
|
||||
}
|
||||
|
||||
/*
|
||||
* determines whether a string ends with the characters of a specified string
|
||||
* @param {String} str
|
||||
* @param {String} searchString
|
||||
* @param {Number} [position= 0]
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function endsWith(str, searchString, position) {
|
||||
str = String(str);
|
||||
if (position === undefined || position > str.length) {
|
||||
position = str.length;
|
||||
}
|
||||
position -= searchString.length;
|
||||
var lastIndex = str.indexOf(searchString, position);
|
||||
return lastIndex !== -1 && lastIndex === position;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns new array from array like object
|
||||
* @param {*} [thing]
|
||||
* @returns {Array}
|
||||
*/
|
||||
function toArray(thing) {
|
||||
if (!thing) return null;
|
||||
var i = thing.length;
|
||||
if (isUndefined(i)) return null;
|
||||
var arr = new Array(i);
|
||||
while (i-- > 0) {
|
||||
arr[i] = thing[i];
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line func-names
|
||||
var isTypedArray = (function(TypedArray) {
|
||||
// eslint-disable-next-line func-names
|
||||
return function(thing) {
|
||||
return TypedArray && thing instanceof TypedArray;
|
||||
};
|
||||
})(typeof Uint8Array !== 'undefined' && Object.getPrototypeOf(Uint8Array));
|
||||
|
||||
module.exports = {
|
||||
supportedProtocols: supportedProtocols,
|
||||
getProtocol: getProtocol,
|
||||
@@ -411,5 +478,11 @@ module.exports = {
|
||||
trim: trim,
|
||||
stripBOM: stripBOM,
|
||||
inherits: inherits,
|
||||
toFlatObject: toFlatObject
|
||||
toFlatObject: toFlatObject,
|
||||
kindOf: kindOf,
|
||||
kindOfTest: kindOfTest,
|
||||
endsWith: endsWith,
|
||||
toArray: toArray,
|
||||
isTypedArray: isTypedArray,
|
||||
isFileList: isFileList
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user