2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-08 17:22:34 +03:00

Added enhanced toFormData implementation with additional options support; (#4704)

Updated default notation for arrays and objects to bracket style;
Added `multer/express.js` tests;
Updated README.md;

Co-authored-by: Jay <jasonsaayman@gmail.com>
This commit is contained in:
Dmitriy Mozgovoy
2022-05-11 20:30:08 +03:00
committed by GitHub
parent 495d5fb133
commit 807918bda2
9 changed files with 664 additions and 87 deletions
+11 -7
View File
@@ -366,29 +366,32 @@ function inherits(constructor, superConstructor, props, descriptors) {
* Resolve object with deep prototype chain to a flat object
* @param {Object} sourceObj source object
* @param {Object} [destObj]
* @param {Function} [filter]
* @param {Function|Boolean} [filter]
* @param {Function} [propFilter]
* @returns {Object}
*/
function toFlatObject(sourceObj, destObj, filter) {
function toFlatObject(sourceObj, destObj, filter, propFilter) {
var props;
var i;
var prop;
var merged = {};
destObj = destObj || {};
// eslint-disable-next-line no-eq-null,eqeqeq
if (sourceObj == null) return destObj;
do {
props = Object.getOwnPropertyNames(sourceObj);
i = props.length;
while (i-- > 0) {
prop = props[i];
if (!merged[prop]) {
if ((!propFilter || propFilter(prop, sourceObj, destObj)) && !merged[prop]) {
destObj[prop] = sourceObj[prop];
merged[prop] = true;
}
}
sourceObj = Object.getPrototypeOf(sourceObj);
sourceObj = filter !== false && Object.getPrototypeOf(sourceObj);
} while (sourceObj && (!filter || filter(sourceObj, destObj)) && sourceObj !== Object.prototype);
return destObj;
@@ -413,14 +416,15 @@ function endsWith(str, searchString, position) {
/**
* Returns new array from array like object
* Returns new array from array like object or null if failed
* @param {*} [thing]
* @returns {Array}
* @returns {?Array}
*/
function toArray(thing) {
if (!thing) return null;
if (isArray(thing)) return thing;
var i = thing.length;
if (isUndefined(i)) return null;
if (!isNumber(i)) return null;
var arr = new Array(i);
while (i-- > 0) {
arr[i] = thing[i];