brainfock
Version:
Brainfock business management & CMS software.
38 lines (30 loc) • 756 B
JavaScript
import warning from 'warning'
import extractPath from './extractPath'
function parsePath(path) {
let pathname = extractPath(path)
let search = ''
let hash = ''
warning(
path === pathname,
'A path must be pathname + search + hash only, not a fully qualified URL like "%s"',
path
)
let hashIndex = pathname.indexOf('#')
if (hashIndex !== -1) {
hash = pathname.substring(hashIndex)
pathname = pathname.substring(0, hashIndex)
}
let searchIndex = pathname.indexOf('?')
if (searchIndex !== -1) {
search = pathname.substring(searchIndex)
pathname = pathname.substring(0, searchIndex)
}
if (pathname === '')
pathname = '/'
return {
pathname,
search,
hash
}
}
export default parsePath