api-client/helpers/utils/uri.js

16 lines
354 B
JavaScript
Raw Normal View History

export function parseUrlAndPath(value) {
2021-05-18 09:27:29 +00:00
const result = {}
2020-06-11 14:25:40 +00:00
try {
2021-05-18 09:27:29 +00:00
const url = new URL(value)
2020-06-11 14:25:40 +00:00
result.url = url.origin
result.path = url.pathname
} catch (error) {
2021-05-18 09:27:29 +00:00
const uriRegex = value.match(
/^((http[s]?:\/\/)?(<<[^/]+>>)?[^/]*|)(\/?.*)$/
)
2020-06-11 14:25:40 +00:00
result.url = uriRegex[1]
result.path = uriRegex[4]
}
return result
}