UNPKG

@salesforce/core

Version:

Core libraries to interact with SFDX projects, orgs, and APIs.

41 lines 1.47 kB
"use strict"; /* * Copyright (c) 2021, salesforce.com, inc. * All rights reserved. * Licensed under the BSD 3-Clause license. * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause */ Object.defineProperty(exports, "__esModule", { value: true }); exports.fixExistingDollarSign = exports.JsonAsXml = exports.writeJSONasXML = exports.standardOptions = void 0; const fs_1 = require("fs"); const jsToXml = require("js2xmlparser"); exports.standardOptions = { declaration: { include: true, encoding: 'UTF-8', version: '1.0', }, format: { doubleQuotes: true, }, }; const writeJSONasXML = async ({ path, json, type, options = exports.standardOptions, }) => { const xml = jsToXml.parse(type, exports.fixExistingDollarSign(json), options); return await fs_1.promises.writeFile(path, xml); }; exports.writeJSONasXML = writeJSONasXML; const JsonAsXml = ({ json, type, options = exports.standardOptions }) => { return jsToXml.parse(type, exports.fixExistingDollarSign(json), options); }; exports.JsonAsXml = JsonAsXml; const fixExistingDollarSign = (existing) => { const existingCopy = { ...existing }; if (existingCopy.$) { const temp = existingCopy.$; delete existingCopy.$; existingCopy['@'] = temp; } return existingCopy; }; exports.fixExistingDollarSign = fixExistingDollarSign; //# sourceMappingURL=jsonXmlTools.js.map