Skip to content

Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia

351 B
Raw Blame
export function parseUrlAndPath(value) {
  const result = {}
  try {
    const url = new URL(value)
    result.url = url.origin
    result.path = url.pathname
  } catch (_e) {
    const uriRegex = value.match(
      /^((http[s]?:\/\/)?(<<[^/]+>>)?[^/]*|)(\/?.*)$/
    )
    result.url = uriRegex[1]
    result.path = uriRegex[4]
  }
  return result
}