blob: 1edad67247980b37e22505d169692e5fd1654c6d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
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}` : ""}`;
};
export const capitalize = (str: string) => str.charAt(0).toUpperCase() + str.slice(1);
export const lengthStr = (length: number) =>
`${Math.floor(length / 60)}:${Math.floor(length % 60)
.toString()
.padStart(2, "0")}`;
|