23 lines
488 B
TypeScript
23 lines
488 B
TypeScript
export function removePrefixFromPathname(
|
|
pathname: string,
|
|
prefix: string,
|
|
): string {
|
|
let ret = pathname;
|
|
ret = ret.slice(prefix.length);
|
|
if (ret.startsWith("/")) {
|
|
ret = ret.slice(1);
|
|
}
|
|
if (ret === "") {
|
|
ret = ".";
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
export function encodePath(path: string): string {
|
|
return path.split("/").map(encodeURIComponent).join("/");
|
|
}
|
|
|
|
export function decodePath(path: string): string {
|
|
return path.split("/").map(decodeURIComponent).join("/");
|
|
}
|