Package: effect
Module: Path
Structured representation of a parsed file system path.
When to use
Use to model the object form produced by Path.parse and consumed by
Path.format.
Details
The fields correspond to the path root, directory, base filename,
extension, and filename without extension, matching the shape consumed by
Path.format.
Example (Parsing and formatting paths)
import { Effect, Path } from "effect"
const program = Effect.gen(function*() {
const path = yield* Path.Path
// Parse a path into its components
const parsed = path.parse("/home/user/documents/file.txt")
console.log(parsed)
// {
// root: "/",
// dir: "/home/user/documents",
// base: "file.txt",
// ext: ".txt",
// name: "file"
// }
// Format a path from its components
const formatted = path.format({
dir: "/home/user",
name: "newfile",
ext: ".ts"
})
console.log(formatted) // "/home/user/newfile.ts"
})
Signature
export interface Parsed {
readonly root: string
readonly dir: string
readonly base: string
readonly ext: string
readonly name: string
}
Since v4.0.0