3 changed files with 27 additions and 3 deletions
@ -0,0 +1,17 @@ |
|||||||
|
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"; |
||||||
|
return "object"; |
||||||
|
} |
||||||
|
|
||||||
|
export function convertBodyToObject(body: unknown): any { |
||||||
|
if (body instanceof FormData || body instanceof URLSearchParams) { |
||||||
|
return [...body]; |
||||||
|
} |
||||||
|
return body; |
||||||
|
} |
Loading…
Reference in new issue