object-to-formdata
Advanced tools
Comparing version 4.2.0 to 4.2.1
{ | ||
"name": "object-to-formdata", | ||
"version": "4.2.0", | ||
"version": "4.2.1", | ||
"keywords": [ | ||
@@ -5,0 +5,0 @@ "form", |
@@ -1,48 +0,57 @@ | ||
const isUndefined = (value) => value === undefined; | ||
function isUndefined(value) { | ||
return value === undefined; | ||
} | ||
const isNull = (value) => value === null; | ||
function isNull(value) { | ||
return value === null; | ||
} | ||
const isBoolean = (value) => typeof value === 'boolean'; | ||
function isBoolean(value) { | ||
return typeof value === 'boolean'; | ||
} | ||
const isObject = (value) => value === Object(value); | ||
function isObject(value) { | ||
return value === Object(value); | ||
} | ||
const isArray = (value) => Array.isArray(value); | ||
function isArray(value) { | ||
return Array.isArray(value); | ||
} | ||
const isDate = (value) => value instanceof Date; | ||
function isDate(value) { | ||
return value instanceof Date; | ||
} | ||
const isBlob = (value) => | ||
value && | ||
typeof value.size === 'number' && | ||
typeof value.type === 'string' && | ||
typeof value.slice === 'function'; | ||
function isBlob(value) { | ||
return ( | ||
value && | ||
typeof value.size === 'number' && | ||
typeof value.type === 'string' && | ||
typeof value.slice === 'function' | ||
); | ||
} | ||
const isFile = (value) => | ||
isBlob(value) && | ||
typeof value.name === 'string' && | ||
(typeof value.lastModifiedDate === 'object' || | ||
typeof value.lastModified === 'number'); | ||
function isFile(value) { | ||
return ( | ||
isBlob(value) && | ||
typeof value.name === 'string' && | ||
(typeof value.lastModifiedDate === 'object' || | ||
typeof value.lastModified === 'number') | ||
); | ||
} | ||
const serialize = (obj, cfg, fd, pre) => { | ||
function initCfgValue(value) { | ||
return isUndefined(value) ? false : value; | ||
} | ||
function serialize(obj, cfg, fd, pre) { | ||
cfg = cfg || {}; | ||
fd = fd || new FormData(); | ||
cfg.indices = isUndefined(cfg.indices) ? false : cfg.indices; | ||
Object.keys(cfg).forEach((opt) => { | ||
const value = cfg[opt]; | ||
cfg.nullsAsUndefineds = isUndefined(cfg.nullsAsUndefineds) | ||
? false | ||
: cfg.nullsAsUndefineds; | ||
cfg[opt] = isUndefined(value) ? false : value; | ||
}); | ||
cfg.booleansAsIntegers = isUndefined(cfg.booleansAsIntegers) | ||
? false | ||
: cfg.booleansAsIntegers; | ||
cfg.allowEmptyArrays = isUndefined(cfg.allowEmptyArrays) | ||
? false | ||
: cfg.allowEmptyArrays; | ||
cfg.noFilesWithArrayNotation = isUndefined(cfg.noFilesWithArrayNotation) | ||
? false | ||
: cfg.noFilesWithArrayNotation; | ||
fd = fd || new FormData(); | ||
if (isUndefined(obj)) { | ||
@@ -95,3 +104,3 @@ return fd; | ||
return fd; | ||
}; | ||
} | ||
@@ -98,0 +107,0 @@ module.exports = { |
@@ -9,3 +9,3 @@ export type Options = { | ||
export const serialize: <T = {}>( | ||
export function serialize<T = {}>( | ||
object: T, | ||
@@ -15,2 +15,2 @@ options?: Options, | ||
keyPrefix?: string, | ||
) => FormData; | ||
): FormData; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
354
13958