mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-03-31 14:22:27 +00:00
19 lines
532 B
TypeScript
19 lines
532 B
TypeScript
export function getFilename(path: string | undefined) {
|
|
if (!path) return ""
|
|
const trimmed = path.replace(/[\/\\]+$/, "")
|
|
const parts = trimmed.split(/[\/\\]/)
|
|
return parts[parts.length - 1] ?? ""
|
|
}
|
|
|
|
export function getDirectory(path: string | undefined) {
|
|
if (!path) return ""
|
|
const parts = path.split("/")
|
|
return parts.slice(0, parts.length - 1).join("/") + "/"
|
|
}
|
|
|
|
export function getFileExtension(path: string | undefined) {
|
|
if (!path) return ""
|
|
const parts = path.split(".")
|
|
return parts[parts.length - 1]
|
|
}
|