2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-20 20:00:40 +03:00

chore(Utils): added docs for utils functions

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