"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.UrlEncodingError = void 0;
exports.validateEncodedUrl = validateEncodedUrl;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
class UrlEncodingError extends Error {
  constructor(originalError) {
    super();
    (0, _defineProperty2.default)(this, "originalError", void 0);
    this.originalError = originalError;
  }
}
exports.UrlEncodingError = UrlEncodingError;
function validateEncodedUrl(url) {
  // if we're able to decode all parts of the url pathname & query params, it means that the url is encoded correctly
  try {
    url.pathname.split('/').forEach(decodeURIComponent);
    Array.from(url.searchParams.keys()).forEach(decodeURIComponent);
    Array.from(url.searchParams.values()).forEach(decodeURIComponent);
  } catch (e) {
    if (e instanceof URIError) {
      throw new UrlEncodingError(e);
    }
    throw e;
  }
}
//# sourceMappingURL=validateEncodedUrl.js.map