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