blob: 4786c6b5bbf0edae4375b68769d270e30b97d6fe (
plain)
1
2
3
4
5
6
7
8
9
10
11
|
export const basename = (path: string, stripExt = true) => {
const lastSlash = path.lastIndexOf("/");
const lastDot = path.lastIndexOf(".");
return path.slice(lastSlash + 1, stripExt && lastDot > lastSlash ? lastDot : undefined);
};
export const pathToFileName = (path: string, ext?: string) => {
const start = /[a-z]+:\/\//.test(path) ? 0 : path.indexOf("/") + 1;
const dir = path.slice(start, path.lastIndexOf("/")).replaceAll("/", "-");
return `${dir}-${basename(path, ext !== undefined)}${ext ? `.${ext}` : ""}`;
};
|