MCPcopy Create free account
hub / github.com/0010aor/FlashNotes / getFormData

Function getFormData

frontend/src/client/core/request.ts:84–109  ·  view source on GitHub ↗
(options: ApiRequestOptions)

Source from the content-addressed store, hash-verified

82}
83
84export const getFormData = (options: ApiRequestOptions): FormData | undefined => {
85 if (options.formData) {
86 const formData = new FormData()
87
88 const process = (key: string, value: unknown) => {
89 if (isString(value) || isBlob(value)) {
90 formData.append(key, value)
91 } else {
92 formData.append(key, JSON.stringify(value))
93 }
94 }
95
96 Object.entries(options.formData)
97 .filter(([, value]) => value !== undefined && value !== null)
98 .forEach(([key, value]) => {
99 if (Array.isArray(value)) {
100 value.forEach((v) => process(key, v))
101 } else {
102 process(key, value)
103 }
104 })
105
106 return formData
107 }
108 return undefined
109}
110
111type Resolver<T> = (options: ApiRequestOptions<T>) => Promise<T>
112

Callers 1

requestFunction · 0.85

Calls 1

processFunction · 0.85

Tested by

no test coverage detected