unmock-core
Version:
[][npmjs] [](https://circleci.com/gh/unmock/unmock-js) [](h
28 lines • 1.08 kB
JavaScript
;
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