mirror of
https://github.com/tenrok/axios.git
synced 2026-06-05 16:42:32 +03:00
chore(Utils): added docs for utils functions
This commit is contained in:
+64
-13
@@ -26,6 +26,7 @@ function kindOfTest(type) {
|
||||
* Determine if a value is an Array
|
||||
*
|
||||
* @param {Object} val The value to test
|
||||
*
|
||||
* @returns {boolean} True if value is an Array, otherwise false
|
||||
*/
|
||||
function isArray(val) {
|
||||
@@ -36,6 +37,7 @@ function isArray(val) {
|
||||
* Determine if a value is undefined
|
||||
*
|
||||
* @param {Object} val The value to test
|
||||
*
|
||||
* @returns {boolean} True if the value is undefined, otherwise false
|
||||
*/
|
||||
function isUndefined(val) {
|
||||
@@ -46,6 +48,7 @@ function isUndefined(val) {
|
||||
* Determine if a value is a Buffer
|
||||
*
|
||||
* @param {Object} val The value to test
|
||||
*
|
||||
* @returns {boolean} True if value is a Buffer, otherwise false
|
||||
*/
|
||||
function isBuffer(val) {
|
||||
@@ -56,8 +59,8 @@ 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
|
||||
*/
|
||||
var isArrayBuffer = kindOfTest('ArrayBuffer');
|
||||
@@ -67,6 +70,7 @@ var isArrayBuffer = kindOfTest('ArrayBuffer');
|
||||
* Determine if a value is a view on an ArrayBuffer
|
||||
*
|
||||
* @param {Object} val The value to test
|
||||
*
|
||||
* @returns {boolean} True if value is a view on an ArrayBuffer, otherwise false
|
||||
*/
|
||||
function isArrayBufferView(val) {
|
||||
@@ -83,6 +87,7 @@ function isArrayBufferView(val) {
|
||||
* Determine if a value is a String
|
||||
*
|
||||
* @param {Object} val The value to test
|
||||
*
|
||||
* @returns {boolean} True if value is a String, otherwise false
|
||||
*/
|
||||
function isString(val) {
|
||||
@@ -93,6 +98,7 @@ function isString(val) {
|
||||
* Determine if a value is a Number
|
||||
*
|
||||
* @param {Object} val The value to test
|
||||
*
|
||||
* @returns {boolean} True if value is a Number, otherwise false
|
||||
*/
|
||||
function isNumber(val) {
|
||||
@@ -103,6 +109,7 @@ function isNumber(val) {
|
||||
* Determine if a value is an Object
|
||||
*
|
||||
* @param {Object} val The value to test
|
||||
*
|
||||
* @returns {boolean} True if value is an Object, otherwise false
|
||||
*/
|
||||
function isObject(val) {
|
||||
@@ -113,7 +120,8 @@ function isObject(val) {
|
||||
* Determine if a value is a plain Object
|
||||
*
|
||||
* @param {Object} val The value to test
|
||||
* @return {boolean} True if value is a plain Object, otherwise false
|
||||
*
|
||||
* @returns {boolean} True if value is a plain Object, otherwise false
|
||||
*/
|
||||
function isPlainObject(val) {
|
||||
if (kindOf(val) !== 'object') {
|
||||
@@ -127,8 +135,8 @@ 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
|
||||
*/
|
||||
var isDate = kindOfTest('Date');
|
||||
@@ -136,8 +144,8 @@ 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
|
||||
*/
|
||||
var isFile = kindOfTest('File');
|
||||
@@ -145,8 +153,8 @@ 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
|
||||
*/
|
||||
var isBlob = kindOfTest('Blob');
|
||||
@@ -154,8 +162,8 @@ 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');
|
||||
@@ -164,6 +172,7 @@ var isFileList = kindOfTest('FileList');
|
||||
* Determine if a value is a Function
|
||||
*
|
||||
* @param {Object} val The value to test
|
||||
*
|
||||
* @returns {boolean} True if value is a Function, otherwise false
|
||||
*/
|
||||
function isFunction(val) {
|
||||
@@ -174,6 +183,7 @@ function isFunction(val) {
|
||||
* Determine if a value is a Stream
|
||||
*
|
||||
* @param {Object} val The value to test
|
||||
*
|
||||
* @returns {boolean} True if value is a Stream, otherwise false
|
||||
*/
|
||||
function isStream(val) {
|
||||
@@ -184,6 +194,7 @@ function isStream(val) {
|
||||
* 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) {
|
||||
@@ -197,8 +208,9 @@ function isFormData(thing) {
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
var isURLSearchParams = kindOfTest('URLSearchParams');
|
||||
@@ -207,6 +219,7 @@ var isURLSearchParams = kindOfTest('URLSearchParams');
|
||||
* Trim excess whitespace off the beginning and end of a string
|
||||
*
|
||||
* @param {String} str The String to trim
|
||||
*
|
||||
* @returns {String} The String freed of excess whitespace
|
||||
*/
|
||||
function trim(str) {
|
||||
@@ -227,6 +240,8 @@ function trim(str) {
|
||||
* navigator.product -> 'ReactNative'
|
||||
* nativescript
|
||||
* navigator.product -> 'NativeScript' or 'NS'
|
||||
*
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function isStandardBrowserEnv() {
|
||||
var product;
|
||||
@@ -252,6 +267,8 @@ function isStandardBrowserEnv() {
|
||||
*
|
||||
* @param {Object|Array} obj The object to iterate
|
||||
* @param {Function} fn The callback to invoke for each item
|
||||
*
|
||||
* @returns {void}
|
||||
*/
|
||||
function forEach(obj, fn) {
|
||||
// Don't bother if no value provided
|
||||
@@ -295,6 +312,7 @@ function forEach(obj, fn) {
|
||||
* ```
|
||||
*
|
||||
* @param {Object} obj1 Object to merge
|
||||
*
|
||||
* @returns {Object} Result of all merge properties
|
||||
*/
|
||||
function merge(/* obj1, obj2, obj3, ... */) {
|
||||
@@ -323,7 +341,8 @@ function merge(/* obj1, obj2, obj3, ... */) {
|
||||
* @param {Object} a The object to be extended
|
||||
* @param {Object} b The object to copy properties from
|
||||
* @param {Object} thisArg The object to bind function to
|
||||
* @return {Object} The resulting value of object a
|
||||
*
|
||||
* @returns {Object} The resulting value of object a
|
||||
*/
|
||||
function extend(a, b, thisArg) {
|
||||
forEach(b, function assignValue(val, key) {
|
||||
@@ -340,7 +359,8 @@ function extend(a, b, thisArg) {
|
||||
* Remove byte order marker. This catches EF BB BF (the UTF-8 BOM)
|
||||
*
|
||||
* @param {string} content with BOM
|
||||
* @return {string} content value without BOM
|
||||
*
|
||||
* @returns {string} content value without BOM
|
||||
*/
|
||||
function stripBOM(content) {
|
||||
if (content.charCodeAt(0) === 0xFEFF) {
|
||||
@@ -355,8 +375,9 @@ function stripBOM(content) {
|
||||
* @param {function} superConstructor
|
||||
* @param {object} [props]
|
||||
* @param {object} [descriptors]
|
||||
*
|
||||
* @returns {void}
|
||||
*/
|
||||
|
||||
function inherits(constructor, superConstructor, props, descriptors) {
|
||||
constructor.prototype = Object.create(superConstructor.prototype, descriptors);
|
||||
constructor.prototype.constructor = constructor;
|
||||
@@ -369,9 +390,9 @@ function inherits(constructor, superConstructor, props, descriptors) {
|
||||
* @param {Object} [destObj]
|
||||
* @param {Function|Boolean} [filter]
|
||||
* @param {Function} [propFilter]
|
||||
*
|
||||
* @returns {Object}
|
||||
*/
|
||||
|
||||
function toFlatObject(sourceObj, destObj, filter, propFilter) {
|
||||
var props;
|
||||
var i;
|
||||
@@ -398,11 +419,13 @@ function toFlatObject(sourceObj, destObj, filter, propFilter) {
|
||||
return destObj;
|
||||
}
|
||||
|
||||
/*
|
||||
* determines whether a string ends with the characters of a specified string
|
||||
/**
|
||||
* 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) {
|
||||
@@ -418,7 +441,9 @@ function endsWith(str, searchString, position) {
|
||||
|
||||
/**
|
||||
* Returns new array from array like object or null if failed
|
||||
*
|
||||
* @param {*} [thing]
|
||||
*
|
||||
* @returns {?Array}
|
||||
*/
|
||||
function toArray(thing) {
|
||||
@@ -433,6 +458,14 @@ function toArray(thing) {
|
||||
return arr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checking if the Uint8Array exists and if it does, it returns a function that checks if the
|
||||
* thing passed in is an instance of Uint8Array
|
||||
*
|
||||
* @param {TypedArray}
|
||||
*
|
||||
* @returns {Array}
|
||||
*/
|
||||
// eslint-disable-next-line func-names
|
||||
var isTypedArray = (function(TypedArray) {
|
||||
// eslint-disable-next-line func-names
|
||||
@@ -441,6 +474,14 @@ var isTypedArray = (function(TypedArray) {
|
||||
};
|
||||
})(typeof Uint8Array !== 'undefined' && Object.getPrototypeOf(Uint8Array));
|
||||
|
||||
/**
|
||||
* For each entry in the object, call the function with the key and value.
|
||||
*
|
||||
* @param {Object<any, any>} obj - The object to iterate over.
|
||||
* @param {Function} fn - The function to call for each entry.
|
||||
*
|
||||
* @returns {void}
|
||||
*/
|
||||
function forEachEntry(obj, fn) {
|
||||
var generator = obj && obj[Symbol.iterator];
|
||||
|
||||
@@ -454,6 +495,14 @@ function forEachEntry(obj, fn) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* It takes a regular expression and a string, and returns an array of all the matches
|
||||
*
|
||||
* @param {string} regExp - The regular expression to match against.
|
||||
* @param {string} str - The string to search.
|
||||
*
|
||||
* @returns {Array<boolean>}
|
||||
*/
|
||||
function matchAll(regExp, str) {
|
||||
var matches;
|
||||
var arr = [];
|
||||
@@ -465,8 +514,10 @@ function matchAll(regExp, str) {
|
||||
return arr;
|
||||
}
|
||||
|
||||
/* Checking if the kindOfTest function returns true when passed an HTMLFormElement. */
|
||||
var isHTMLForm = kindOfTest('HTMLFormElement');
|
||||
|
||||
/* Creating a function that will check if an object has a property. */
|
||||
var hasOwnProperty = (function resolver(_hasOwnProperty) {
|
||||
return function(obj, prop) {
|
||||
return _hasOwnProperty.call(obj, prop);
|
||||
|
||||
Reference in New Issue
Block a user