"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = getDataByURL;

/**
 * Gets data by url
 * @param url
 * @param [type]
 * @returns
 */
function getDataByURL(url) {
  var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'text';
  return new Promise(function (resolve, reject) {
    var request = new XMLHttpRequest();
    request.open('GET', url);
    request.responseType = type;

    request.onload = function () {
      resolve(request.response);
    };

    request.onerror = function () {
      reject(new Error("Request error: ".concat(url)));
    };

    request.send();
  });
}