UNPKG

react-http-fetch

Version:

An http library for React JS built on top of native JS fetch

27 lines (26 loc) 1.08 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.serializeRequestBody = void 0; var shared_1 = require("../shared"); function serializeRequestBody(body) { // If no body is present, no need to serialize it. if (body === null || typeof body === 'undefined') { return null; } // Check whether the body is already in a serialized form. If so, // it can just be returned directly. if ((0, shared_1.isArrayBuffer)(body) || (0, shared_1.isBlob)(body) || (0, shared_1.isFormData)(body) || (0, shared_1.isUrlSearchParams)(body) || typeof body === 'string') { return body; } // Check whether the body is an object, an array, a boolean or a number, and serialize with JSON if so. if ((0, shared_1.isObject)(body) || (0, shared_1.isBoolean)(body) || (0, shared_1.isNumber)(body) || Array.isArray(body)) { return JSON.stringify(body); } // Fallback to body string literal. return "".concat(body); } exports.serializeRequestBody = serializeRequestBody;