simple-fs-server/util/util.ts

23 lines
488 B
TypeScript
Raw Normal View History

2023-01-06 18:24:27 +09:00
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;
2023-01-06 18:17:36 +09:00
}
export function encodePath(path: string): string {
2023-01-06 18:24:27 +09:00
return path.split("/").map(encodeURIComponent).join("/");
}
2023-01-06 22:50:32 +09:00
export function decodePath(path: string): string {
return path.split("/").map(decodeURIComponent).join("/");
}