export function getURLSearchParams(value?: string): URLSearchParams {
  value ??= `${ location.search }&${ location.hash.split('?')[ 1 ] || '' }`;
  return new URLSearchParams(value);
}

export function getURLSearchParamsByUrl(value: string): URLSearchParams {
  const snippet = value.split('#');
  return getURLSearchParams(snippet.map((param) => param.split('?')[1] || '').join('&'))
}


export function getClientURL(value: string, origin?: string) {
  if ( !value || /^https?:\/\//.test(value) ) return value;
  if ( value.startsWith('~') ) { value = value.slice(1); }
  return fullURL(value, origin);
}

function fullURL(value: string, origin = location.origin) {
  return origin + `${ import.meta.env.BASE_URL }/${ value }`.replace(/\/{2,}/g, '/');
}
