js2ts: chiefCenter
- common: unwrap_any - jQuery export 수정 - axios로 변경 - moment -> luxon
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import { isArray, isString, isNumber, isBoolean } from "lodash";
|
||||
|
||||
export function convertFormData(values: Record<string, number[]|string[]|boolean[]|number|string|boolean>): FormData{
|
||||
const formData = new FormData();
|
||||
|
||||
const simpleConv = (v: unknown):string=>{
|
||||
if(isString(v)){
|
||||
return v;
|
||||
}
|
||||
if(isNumber(v)){
|
||||
return v.toString();
|
||||
}
|
||||
if(isBoolean(v)){
|
||||
return v?'true':'false';
|
||||
}
|
||||
throw new TypeError('지원하지 않는 formData Type');
|
||||
}
|
||||
|
||||
for(const [key, value] of Object.entries(values)){
|
||||
if(isArray(value)){
|
||||
const arrKey = `${key}[]`;
|
||||
for(const subValue of value){
|
||||
formData.append(arrKey, simpleConv(subValue));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
formData.append(key, simpleConv(value));
|
||||
}
|
||||
|
||||
return formData;
|
||||
}
|
||||
Reference in New Issue
Block a user