initial breadcrumb builder
This commit is contained in:
1 parent
113fb9db77
commit
ebaebec835
5 files changed
+53
-46
No files matched your search
@@ -0,0 +1,28 @@
|
||||
export function dropTrailingSlash(path: string) {
|
||||
if (path === '/' || path === '') {
|
||||
return '/'
|
||||
}
|
||||
|
||||
const lastChar = path.charAt(path.length - 1)
|
||||
if (lastChar === '/') {
|
||||
return path.substr(0, path.length - 1)
|
||||
}
|
||||
|
||||
return path
|
||||
}
|
||||
|
||||
export function getPathWaterfall(path: string): string[] {
|
||||
const parts = path
|
||||
.split('/')
|
||||
.filter(Boolean)
|
||||
.reduce((acc, part, index, parts) => {
|
||||
const i = index + 1
|
||||
const item = `/${parts.slice(0, i).join('/')}`
|
||||
return [
|
||||
...acc,
|
||||
item
|
||||
]
|
||||
}, [])
|
||||
|
||||
return ['/', ...parts]
|
||||
}
|
||||
Reference in new issue
Block a user