UNPKG

unmock-core

Version:

[![npm](https://img.shields.io/npm/v/unmock-core.svg)][npmjs] [![CircleCI](https://circleci.com/gh/unmock/unmock-js.svg?style=svg)](https://circleci.com/gh/unmock/unmock-js) [![codecov](https://codecov.io/gh/unmock/unmock-js/branch/dev/graph/badge.svg)](h

28 lines 1.08 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const querystring = require("querystring"); class FormSerializer { serialize(json) { const contentType = json.headers ? json.headers["Content-Type"] || json.headers["content-type"] : undefined; if (contentType && typeof contentType === "string" && contentType.startsWith("application/x-www-form-urlencoded")) { return Object.assign(Object.assign({}, json), (json.body && typeof json.body === "string" ? { body: json.body .split("&") .map((kv) => kv.split("=")) .map(([k, v]) => ({ [querystring.unescape(k)]: querystring.unescape(v), })) .reduce((a, b) => (Object.assign(Object.assign({}, a), b)), {}), } : {})); } return json; } } exports.default = FormSerializer; //# sourceMappingURL=form.js.map