uri.js 350 B

123456789101112131415
  1. export function parseUrlAndPath(value) {
  2. const result = {}
  3. try {
  4. const url = new URL(value)
  5. result.url = url.origin
  6. result.path = url.pathname
  7. } catch (e) {
  8. const uriRegex = value.match(
  9. /^((http[s]?:\/\/)?(<<[^/]+>>)?[^/]*|)(\/?.*)$/
  10. )
  11. result.url = uriRegex[1]
  12. result.path = uriRegex[4]
  13. }
  14. return result
  15. }