import xml2js from 'xml2js';
import iotizeStudio from '@iotize/device-client.js/config/iotize-studio';

var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};

function commonjsRequire () {
	throw new Error('Dynamic requires are not currently supported by rollup-plugin-commonjs');
}

function unwrapExports (x) {
	return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
}

function createCommonjsModule(fn, module) {
	return module = { exports: {} }, fn(module, module.exports), module.exports;
}

function getCjsExportFromNamespace (n) {
	return n && n['default'] || n;
}

var xmlParser = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

/**
 * Convert XML to Javascript Object
 */
class XMLParser {
    /**
     * Parse XML input synchonously
     * @param xml
     */
    parseSync(xml) {
        let res = null;
        xml2js.parseString(xml, function (err, result) {
            if (err !== null) {
                throw err;
            }
            res = result;
        });
        return res;
    }
    /**
     * Parse XML input async
     * @param xml
     */
    parse(xml) {
        xml = this.cleanifyXml(xml);
        return new Promise((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
     */
    cleanifyXml(xml) {
        if (!xml) {
            return xml;
        }
        return xml.replace('\ufeff', '').trim();
    }
}
exports.XMLParser = XMLParser;

});

var xmlParser$1 = unwrapExports(xmlParser);
var xmlParser_1 = xmlParser.XMLParser;

var configFactoryExtension = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });


/**
 * Create IotizeConfigModel from a XML string
 * @param xml
 */
iotizeStudio.IotizeConfigFactory.fromXML = function (xml) {
    return new iotizeStudio.IotizeConfigModel(new xmlParser.XMLParser().parseSync(xml));
};

});

var configFactoryExtension$1 = unwrapExports(configFactoryExtension);

var public_api = createCommonjsModule(function (module, exports) {
"use strict";
function __export(m) {
    for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
__export(xmlParser);


});

var public_api$1 = unwrapExports(public_api);

var iotizeDeviceClient_jsConfigIotizeStudioParserXml = createCommonjsModule(function (module, exports) {
"use strict";
/**
 * Generated bundle index. Do not edit.
 */
function __export(m) {
    for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
__export(public_api);

});

var iotizeDeviceClient_jsConfigIotizeStudioParserXml$1 = unwrapExports(iotizeDeviceClient_jsConfigIotizeStudioParserXml);

export default iotizeDeviceClient_jsConfigIotizeStudioParserXml$1;
//# sourceMappingURL=iotize-device-client.js-config-iotize-studio-parser-xml.js.map
