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