<commit_before>import PropTypes from "prop-types"
import React from "react"
import { Link, Location } from "@reach/router"
import { resolve } from "@reach/router/lib/utils"

import { parsePath } from "./parse-path"

export { parsePath }

const isAbsolutePath = path => path.startsWith(`/`)

export function withPrefix(path, prefix = __BASE_PATH__) {
  if (!isLocalLink(path)) {
    return path
  }

  if (path.startsWith(`./`) || path.startsWith(`../`)) {
    return path
  }
  const base = prefix ?? __PATH_PREFIX__ ?? `/`

  return `${base?.endsWith(`/`) ? base.slice(0, -1) : base}${
    path.startsWith(`/`) ? path : `/${path}`
  }`
}

const isLocalLink = path =><commit_msg>fix(gatsby-link): Fail gracefully on empty `to` prop (#24745)<commit_after>import PropTypes from "prop-types"
import React from "react"
import { Link, Location } from "@reach/router"
import { resolve } from "@reach/router/lib/utils"

import { parsePath } from "./parse-path"

export { parsePath }

const isAbsolutePath = path => path?.startsWith(`/`)

export function withPrefix(path, prefix = __BASE_PATH__) {
  if (!isLocalLink(path)) {
    return path
  }

  if (path.startsWith(`./`) || path.startsWith(`../`)) {
    return path
  }
  const base = prefix ?? __PATH_PREFIX__ ?? `/`

  return `${base?.endsWith(`/`) ? base.slice(0, -1) : base}${
    path.startsWith(`/`) ? path : `/${path}`
  }`
}

const isLocalLink = path =>
  path &&
{'fraction_non_alphanumeric': 0.1806633733239238, 'fraction_numerical': 0.006351446718419196, 'mean_word_length': 3.774410774410774, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '3497656', 'n_tokens_mistral': 477, 'n_tokens_neox': 484, 'n_words': 120}