UNPKG

@iotize/tap

Version:

IoTize Device client for Javascript

74 lines (67 loc) 3.01 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@iotize/tap/config/iotize-studio'), require('xml2js')) : typeof define === 'function' && define.amd ? define('@iotize/tap/config/iotize-studio/parser/xml', ['exports', '@iotize/tap/config/iotize-studio', 'xml2js'], factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.iotize = global.iotize || {}, global.iotize.tap = global.iotize.tap || {}, global.iotize.tap.config = global.iotize.tap.config || {}, global.iotize.tap.config["iotize-studio"] = global.iotize.tap.config["iotize-studio"] || {}, global.iotize.tap.config["iotize-studio"].parser = global.iotize.tap.config["iotize-studio"].parser || {}, global.iotize.tap.config["iotize-studio"].parser.xml = {}), global.iotize.tap.config["iotize-studio"], global.xml2js)); })(this, (function (exports, iotizeStudio, xml2js) { 'use strict'; // TODO remove xml2js dependencie /** * Convert XML to Javascript Object */ var XMLParser = /** @class */ (function () { function XMLParser() { } /** * Parse XML input synchonously * @param xml */ XMLParser.prototype.parseSync = function (xml) { var res = null; xml2js.parseString(xml, function (err, result) { if (err !== null) { throw err; } res = result; }); return res; }; /** * Parse XML input async * @param xml */ XMLParser.prototype.parse = function (xml) { xml = this.cleanifyXml(xml); return new Promise(function (resolve, reject) { xml2js.parseString(xml, function (err, result) { if (err !== null) { reject(err); } resolve(result); }); }); }; /** * Cleanify the xml input before parsing * @see http://stackoverflow.com/questions/34783452/cannot-parse-xml-error-non-whitespace-before-first-tag-line-0-column-1-cha */ XMLParser.prototype.cleanifyXml = function (xml) { if (!xml) { return xml; } return xml.replace('\ufeff', '').trim(); }; return XMLParser; }()); /** * Create IotizeConfigModel from a XML string * @param xml */ iotizeStudio.IotizeConfigFactory.fromXML = function (xml) { return new iotizeStudio.IotizeConfigModel(new XMLParser().parseSync(xml)); }; /** * Generated bundle index. Do not edit. */ exports.XMLParser = XMLParser; Object.defineProperty(exports, '__esModule', { value: true }); })); //# sourceMappingURL=iotize-tap-config-iotize-studio-parser-xml.umd.js.map