Improve flexibility of url parsing (#26)
This commit is contained in:
committed by
Michael Vines
parent
1ad1ba73fa
commit
e59625a41d
@@ -11,6 +11,20 @@ export function findGetParameter(parameterName: string): string | null {
|
||||
return result;
|
||||
}
|
||||
|
||||
export function findPathSegment(pathName: string): string | null {
|
||||
const segments = window.location.pathname.substr(1).split("/");
|
||||
if (segments.length < 2) return null;
|
||||
|
||||
// remove all but last two segments
|
||||
segments.splice(0, segments.length - 2);
|
||||
|
||||
if (segments[0] === pathName) {
|
||||
return segments[1];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export function assertUnreachable(x: never): never {
|
||||
throw new Error("Unreachable!");
|
||||
}
|
||||
|
Reference in New Issue
Block a user