UNPKG

1.02 kBJavaScriptView Raw
1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT License. See License.txt in the project root for license information.
3import * as xml2js from "xml2js";
4export function stringifyXML(obj, opts) {
5 var builder = new xml2js.Builder({
6 rootName: (opts || {}).rootName,
7 renderOpts: {
8 pretty: false,
9 },
10 });
11 return builder.buildObject(obj);
12}
13export function parseXML(str) {
14 var xmlParser = new xml2js.Parser({
15 explicitArray: false,
16 explicitCharkey: false,
17 explicitRoot: false,
18 });
19 return new Promise(function (resolve, reject) {
20 if (!str) {
21 reject(new Error("Document is empty"));
22 }
23 else {
24 xmlParser.parseString(str, function (err, res) {
25 if (err) {
26 reject(err);
27 }
28 else {
29 resolve(res);
30 }
31 });
32 }
33 });
34}
35//# sourceMappingURL=xml.js.map
\No newline at end of file