"use strict";

var URL = require("url");
var queryParser = require("querystring");

var connectUrl = void 0;

var normalize = function normalize(remoteurl) {
  var urlObj = URL.parse(remoteurl);
  if (urlObj.query) {
    urlObj.query = queryParser.stringify(queryParser.parse(urlObj.query));
    urlObj.search = "?" + urlObj.query;
  }
  return urlObj.format();
};

var getConnectUrl = function getConnectUrl(channelId) {
  return connectUrl.replace("{channelId}", channelId);
};

var setConnectUrl = function setConnectUrl(url) {
  connectUrl = url;
};

module.exports = {
  normalize: normalize,
  getConnectUrl: getConnectUrl,
  setConnectUrl: setConnectUrl
};