mirror of
https://github.com/tenrok/axios.git
synced 2026-06-11 18:02:32 +03:00
feat(fomdata): added support for spec-compliant FormData & Blob types; (#5316)
This commit is contained in:
+35
-1
@@ -512,7 +512,7 @@ const matchAll = (regExp, str) => {
|
||||
const isHTMLForm = kindOfTest('HTMLFormElement');
|
||||
|
||||
const toCamelCase = str => {
|
||||
return str.toLowerCase().replace(/[_-\s]([a-z\d])(\w*)/g,
|
||||
return str.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,
|
||||
function replacer(m, p1, p2) {
|
||||
return p1.toUpperCase() + p2;
|
||||
}
|
||||
@@ -596,6 +596,37 @@ const toFiniteNumber = (value, defaultValue) => {
|
||||
return Number.isFinite(value) ? value : defaultValue;
|
||||
}
|
||||
|
||||
const ALPHA = 'abcdefghijklmnopqrstuvwxyz'
|
||||
|
||||
const DIGIT = '0123456789';
|
||||
|
||||
const ALPHABET = {
|
||||
DIGIT,
|
||||
ALPHA,
|
||||
ALPHA_DIGIT: ALPHA + ALPHA.toUpperCase() + DIGIT
|
||||
}
|
||||
|
||||
const generateString = (size = 16, alphabet = ALPHABET.ALPHA_DIGIT) => {
|
||||
let str = '';
|
||||
const {length} = alphabet;
|
||||
while (size--) {
|
||||
str += alphabet[Math.random() * length|0]
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the thing is a FormData object, return true, otherwise return false.
|
||||
*
|
||||
* @param {unknown} thing - The thing to check.
|
||||
*
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function isSpecCompliantForm(thing) {
|
||||
return !!(thing && isFunction(thing.append) && thing[Symbol.toStringTag] === 'FormData' && thing[Symbol.iterator]);
|
||||
}
|
||||
|
||||
const toJSONObject = (obj) => {
|
||||
const stack = new Array(10);
|
||||
|
||||
@@ -673,5 +704,8 @@ export default {
|
||||
findKey,
|
||||
global: _global,
|
||||
isContextDefined,
|
||||
ALPHABET,
|
||||
generateString,
|
||||
isSpecCompliantForm,
|
||||
toJSONObject
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user