diff options
Diffstat (limited to 'packages/util/src/path.ts')
| -rw-r--r-- | packages/util/src/path.ts | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/packages/util/src/path.ts b/packages/util/src/path.ts new file mode 100644 index 000000000..fbb84878d --- /dev/null +++ b/packages/util/src/path.ts @@ -0,0 +1,16 @@ +export function getFilename(path: string) { + if (!path) return "" + const trimmed = path.replace(/[\/]+$/, "") + const parts = trimmed.split("/") + return parts[parts.length - 1] ?? "" +} + +export function getDirectory(path: string) { + const parts = path.split("/") + return parts.slice(0, parts.length - 1).join("/") + "/" +} + +export function getFileExtension(path: string) { + const parts = path.split(".") + return parts[parts.length - 1] +} |
