1 | import { Buffer } from "node:buffer";
|
2 | import { JSONParseError } from "./exceptions.js";
|
3 | export function toArray(maybeArr) {
|
4 | return Array.isArray(maybeArr) ? maybeArr : [maybeArr];
|
5 | }
|
6 | export function ensureJSON(raw) {
|
7 | if (typeof raw === "object") {
|
8 | return raw;
|
9 | }
|
10 | else {
|
11 | throw new JSONParseError("Failed to parse response body as JSON", { raw });
|
12 | }
|
13 | }
|
14 | export function createMultipartFormData(formBody) {
|
15 | const formData = this instanceof FormData ? this : new FormData();
|
16 | Object.entries(formBody).forEach(([key, value]) => {
|
17 | if (Buffer.isBuffer(value) || value instanceof Uint8Array) {
|
18 | formData.append(key, new Blob([value]));
|
19 | }
|
20 | else {
|
21 | formData.append(key, String(value));
|
22 | }
|
23 | });
|
24 | return formData;
|
25 | }
|
26 |
|
\ | No newline at end of file |