UNPKG

nationstates.js

Version:

A wrapper to interact with the NationStates API.

55 lines 1.52 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseXml = void 0; const xml2js = require("xml2js"); /** * @author The xmlParser is based on the following written by Auralia: * https://github.com/auralia/node-nsapi/blob/master/src/api.ts#L25 * @hidden */ const xmlParser = new xml2js.Parser({ charkey: "value", trim: true, normalizeTags: true, normalize: true, explicitRoot: false, explicitArray: false, mergeAttrs: true, attrValueProcessors: [(value) => { let num = Number(value); if (!isNaN(num)) { return num; } else { return value; } }], valueProcessors: [(value) => { let num = Number(value); if (!isNaN(num)) { return num; } else { return value; } }] }); /** * Parses XML into a JSON object. * @author The xmLParser is based on the following written by Auralia: * https://github.com/auralia/node-nsapi/blob/master/src/api.ts#L25 * @param {string} xml The XML to parse. * @return data promise returning a JSON object. */ function parseXml(xml) { return new Promise((resolve, reject) => { xmlParser.parseString(xml, (err, data) => { if (err) { return reject(err); } resolve(data); }); }); } exports.parseXml = parseXml; //# sourceMappingURL=xml_parser.js.map