insomnia-plugin-douglasmariz-response-xml-to-json
Version:
Transforms XML responses into Json
15 lines (14 loc) • 575 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const xml_js_1 = require("xml-js");
exports.default = async ({ response, store }) => {
var _a;
const responseBody = (_a = response.getBody()) === null || _a === void 0 ? void 0 : _a.toString();
const xml = await store.getItem('xml');
if (xml === 'true') {
await store.removeItem('xml');
const textJson = (0, xml_js_1.xml2json)(responseBody, { compact: true, spaces: 4 });
// @ts-ignore
response.setBody(Buffer.from(textJson));
}
};