Skip to content

Commit

Permalink
Fixed isFormData predicate; (axios#4413)
Browse files Browse the repository at this point in the history
Added support for automatic object serialization to FormData if `Content-Type` is `multipart/form-data`;
Added support for FormData to be overloaded using `config.env.FormData` option;
Added support for FormData in node.js environment using `form-data` package;

(cherry picked from commit 73e3bdb)
  • Loading branch information
DigitalBrainJS committed Feb 15, 2022
1 parent 3b2de16 commit cd853ec
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
3 changes: 3 additions & 0 deletions index.d.ts
Expand Up @@ -107,6 +107,9 @@ export interface AxiosRequestConfig<D = any> {
transitional?: TransitionalOptions;
signal?: AbortSignal;
insecureHTTPParser?: boolean;
env?: {
FormData?: new (...args: any[]) => object;
};
}

export interface HeadersDefaults {
Expand Down
24 changes: 15 additions & 9 deletions lib/utils.js
Expand Up @@ -62,15 +62,6 @@ function isBuffer(val) {
*/
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
Expand Down Expand Up @@ -180,6 +171,21 @@ function isStream(val) {
return isObject(val) && isFunction(val.pipe);
}

/**
* 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
Expand Down

0 comments on commit cd853ec

Please sign in to comment.