UNPKG

1.46 kBJavaScriptView Raw
1"use strict";
2/*
3 * Copyright (c) 2021, salesforce.com, inc.
4 * All rights reserved.
5 * Licensed under the BSD 3-Clause license.
6 * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7 */
8Object.defineProperty(exports, "__esModule", { value: true });
9exports.fixExistingDollarSign = exports.JsonAsXml = exports.writeJSONasXML = exports.standardOptions = void 0;
10const fs_1 = require("fs");
11const jsToXml = require("js2xmlparser");
12exports.standardOptions = {
13 declaration: {
14 include: true,
15 encoding: 'UTF-8',
16 version: '1.0',
17 },
18 format: {
19 doubleQuotes: true,
20 },
21};
22const writeJSONasXML = async ({ path, json, type, options = exports.standardOptions, }) => {
23 const xml = jsToXml.parse(type, (0, exports.fixExistingDollarSign)(json), options);
24 return fs_1.promises.writeFile(path, xml);
25};
26exports.writeJSONasXML = writeJSONasXML;
27const JsonAsXml = ({ json, type, options = exports.standardOptions }) => jsToXml.parse(type, (0, exports.fixExistingDollarSign)(json), options);
28exports.JsonAsXml = JsonAsXml;
29const fixExistingDollarSign = (existing) => {
30 const existingCopy = { ...existing };
31 if (existingCopy.$) {
32 const temp = existingCopy.$;
33 delete existingCopy.$;
34 existingCopy['@'] = temp;
35 }
36 return existingCopy;
37};
38exports.fixExistingDollarSign = fixExistingDollarSign;
39//# sourceMappingURL=jsonXmlTools.js.map
\No newline at end of file