<commit_before>import URL from './url';

function isAbsolute(url: string): boolean {
  try {
    return !!new URL(url);
  } catch (e) {
    return false;
  }
}

export default function resolve(input: string, base: string | undefined): string {
  if (isAbsolute(input)) return new URL(input).href;
  if (base) {
    if (isAbsolute(base)) return new URL(input, base).href;
    throw new Error(`cannot handle relative base "${base}"`);
  }
  return input;
}<commit_msg>Base is always considered a directory<commit_after>import URL from './url';

function isAbsolute(url: string): boolean {
  try {
    return !!new URL(url);
  } catch (e) {
    return false;
  }
}

export default function resolve(input: string, base: string | undefined): string {
  if (isAbsolute(input)) return new URL(input).href;
  if (base) {
    base = base.replace(/\/?$/, '/');
    if (isAbsolute(base)) return new URL(input, base).href;
    throw new Error(`cannot handle relative base "${base}"`);
  }
  return input;
}
{'fraction_non_alphanumeric': 0.14989939637826963, 'fraction_numerical': 0.0, 'mean_word_length': 3.8300970873786406, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2304328', 'n_tokens_mistral': 309, 'n_tokens_neox': 306, 'n_words': 101}