This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const objectAssignNotNull = (target, ...sources) => { | |
for (const source of sources) { | |
for (const [key, value] of Object.entries(source)) { | |
if (value && typeof value === 'object' && !Array.isArray(value)) { | |
if (!target[key]) target[key] = {} | |
objectAssignNotNull(target[key], value) | |
} else if ((value !== null && value !== undefined) || !Object.prototype.hasOwnProperty.call(target, key)) { | |
Object.assign(target, { [key]: value }) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Append every property of an object into a formData, then returns it. | |
* | |
* @param {Object} obj Original object. | |
* @return {FormData} FormData object reference. | |
*/ | |
function objectToFormData(obj) { | |
const getPrefix = (prefix, key) => prefix + (prefix ? '[' : '') + key + (prefix ? ']' : '') | |
const fromArray = (_arr, prefix = '') => { |