import _Object$assign from "@babel/runtime-corejs2/core-js/object/assign";
import isEqual from 'lodash/isEqual';
export function toRelativePath(url, host) {
  if (host) {
    const reg = new RegExp(host.replace(/^https?:\/\//, ''));

    if (reg.test(url)) {
      const path = url.replace(/^https?:\/\//, '').replace(reg, '');
      if (path === '') return '/';
      return path;
    }
  }

  return url;
}
export function includeUrl(href, url) {
  if (url === href) return true;

  if (url.split('?')[0].replace(/(\/$|#.*)/, '') === href.split('?')[0].replace(/(\/$|#.*)/, '')) {
    if (href.split('?')[1]) {
      const currentQueryParams = getQueryParams(href);
      return isEqual(currentQueryParams, _Object$assign({}, currentQueryParams, getQueryParams(url)));
    }

    return true;
  }

  return false;
}
export function getQueryParams(url) {
  const result = {};
  const param = /([^?=&]+)=([^&]+)/ig;
  let match;

  while ((match = param.exec(url)) != null) {
    result[match[1]] = match[2];
  }

  return result;
}
export function parse(url) {
  const [hostname, ...pathname] = url.toLowerCase().replace(/^:?\/\/|https?:\/\/?(.+?)/, '$1').split('/');
  const params = getQueryParams(url);
  return {
    hostname,
    pathname: '/' + pathname.join('/').replace(/(\?.*?)$/, ''),
    params
  };
}