parses the provided file path and breaks it down into useful bit described by the interface FilepathInfo. note that a file path must never end in a trailing slash ("/"), and conversely, a folder path must always in a trailing slash ("/"), otherwise it will be parsed as a file.

import { assertEquals } from "jsr:@std/assert"

// aliasing our functions for brevity
const eq = assertEquals, fn = parseFilepathInfo

eq(fn("/home\\user/docs"), {
path: "/home/user/docs",
dirpath: "/home/user/",
dirname: "user",
filename: "docs",
basename: "docs",
extname: "",
})
eq(fn("home\\user/docs/"), {
path: "home/user/docs/",
dirpath: "home/user/docs/",
dirname: "docs",
filename: "",
basename: "",
extname: "",
})
eq(fn("/home/xyz/.././././user/.bashrc."), {
path: "/home/user/.bashrc.",
dirpath: "/home/user/",
dirname: "user",
filename: ".bashrc.",
basename: ".bashrc.",
extname: "",
})
eq(fn("C:\\home\\user/.file.tar.gz"), {
path: "C:/home/user/.file.tar.gz",
dirpath: "C:/home/user/",
dirname: "user",
filename: ".file.tar.gz",
basename: ".file.tar",
extname: ".gz",
})
eq(fn("/home/user///file.txt"), {
path: "/home/user///file.txt",
dirpath: "/home/user///",
dirname: "", // this is because the there is no name attached between the last two slashes of the `dirpath = "/home/user///"`
filename: "file.txt",
basename: "file",
extname: ".txt",
})