UNPKG

1.05 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.createMultipartFormData = exports.ensureJSON = exports.toArray = void 0;
4const exceptions_1 = require("./exceptions");
5const FormData = require("form-data");
6function toArray(maybeArr) {
7 return Array.isArray(maybeArr) ? maybeArr : [maybeArr];
8}
9exports.toArray = toArray;
10function 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}
18exports.ensureJSON = ensureJSON;
19function 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}
31exports.createMultipartFormData = createMultipartFormData;