summaryrefslogtreecommitdiffhomepage
path: root/packages/desktop/src/utils/path.ts
blob: d23568ae63a28008b609fac0809ddc2187b0fd61 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import { useSync } from "@/context/sync"

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 sync = useSync()
  const parts = path.split("/")
  const dir = parts.slice(0, parts.length - 1).join("/")
  return dir ? sync.sanitize(dir + "/") : ""
}

export function getFileExtension(path: string) {
  const parts = path.split(".")
  return parts[parts.length - 1]
}