UNPKG

834 BJavaScriptView Raw
1import { Buffer } from "node:buffer";
2import { JSONParseError } from "./exceptions.js";
3export function toArray(maybeArr) {
4 return Array.isArray(maybeArr) ? maybeArr : [maybeArr];
5}
6export 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}
14export 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//# sourceMappingURL=utils.js.map
\No newline at end of file