3 changed files with 27 additions and 32 deletions
@ -0,0 +1,22 @@ |
|||||||
|
import { ExtensionMakeRequestBodyType } from "./plasmo"; |
||||||
|
|
||||||
|
export function getBodyTypeFromBody( |
||||||
|
body: unknown, |
||||||
|
): ExtensionMakeRequestBodyType { |
||||||
|
if (typeof body === "string") return "string"; |
||||||
|
if (body instanceof FormData) return "FormData"; |
||||||
|
if (body instanceof URLSearchParams) return "URLSearchParams"; |
||||||
|
if (typeof body === "object") return "object"; |
||||||
|
return "string"; |
||||||
|
} |
||||||
|
|
||||||
|
export function convertBodyToObject(body: unknown): any { |
||||||
|
if (body instanceof FormData || body instanceof URLSearchParams) { |
||||||
|
const obj: Record<string, any> = {}; |
||||||
|
for (const [key, value] of body.entries()) { |
||||||
|
obj[key] = value; |
||||||
|
} |
||||||
|
return obj; |
||||||
|
} |
||||||
|
return body; |
||||||
|
} |
Loading…
Reference in new issue