UNPKG

1.47 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, exports.fixExistingDollarSign(json), options);
24 return await fs_1.promises.writeFile(path, xml);
25};
26exports.writeJSONasXML = writeJSONasXML;
27const JsonAsXml = ({ json, type, options = exports.standardOptions }) => {
28 return jsToXml.parse(type, exports.fixExistingDollarSign(json), options);
29};
30exports.JsonAsXml = JsonAsXml;
31const fixExistingDollarSign = (existing) => {
32 const existingCopy = { ...existing };
33 if (existingCopy.$) {
34 const temp = existingCopy.$;
35 delete existingCopy.$;
36 existingCopy['@'] = temp;
37 }
38 return existingCopy;
39};
40exports.fixExistingDollarSign = fixExistingDollarSign;
41//# sourceMappingURL=jsonXmlTools.js.map
\No newline at end of file