Module
pooka/path
src/pooka/path.pookaA path is a set of directions, not proof that the house exists.
Transform paths with the host runtime conventions. Normalization is lexical and does not resolve symbolic links. absolute and relative may fail while consulting the working directory; extensions include their leading dot.
import pooka/path
assert path.extension("notes.txt") == Some(".txt")
API reference
class PathError(message: String)
A path failure carrying the details needed by its caller. Keep this value in Result until a boundary can explain it.
message: String
String
fn(String) -> pooka/path.PathErrorjoin(parts: List(String)) -> String
fn(List(String)) -> StringJoin path components using the host filename conventions. An empty list yields a dot.
import pooka/path
assert path.join([]) == "."
basename(path: String) -> String
fn(String) -> StringReturn the final component of a path.
import pooka/path
assert path.basename("notes/oak.txt") == "oak.txt"
dirname(path: String) -> String
fn(String) -> StringReturn the path's parent component.
import pooka/path
assert path.dirname("notes/oak.txt") == "notes"
extension(path: String) -> Option(String)
fn(String) -> Option(String)Return a leading-dot extension, or None when there is no suffix.
import pooka/path
assert path.extension("notes.txt") == Some(".txt")
stem(path: String) -> String
fn(String) -> StringReturn the basename without its final extension.
import pooka/path
assert path.stem("notes.txt") == "notes"
is_absolute(path: String) -> Bool
fn(String) -> BoolCheck the host runtime's absolute-path convention.
import pooka/path
let absolute = path.is_absolute("notes.txt")
is_relative(path: String) -> Bool
fn(String) -> BoolAsk whether the host runtime considers the path relative.
import pooka/path
let relative = path.is_relative("notes.txt")
normalize(path: String) -> String
fn(String) -> StringNormalize lexical components without resolving symbolic links.
import pooka/path
let normalized = path.normalize("notes/./oak.txt")
absolute(path: String) -> Result(String, PathError)
fn(String) -> Result(String, pooka/path.PathError)Resolve a relative path against the working directory without a filesystem existence check.
import pooka/path
let assert Ok(resolved) = path.absolute("notes.txt")
relative(path: String, base: String) -> Result(String, PathError)
fn(String, String) -> Result(String, pooka/path.PathError)Find a lexical path from base to path after resolving their absolute forms.
import pooka/path
let assert Ok(relative) = path.relative("notes/oak.txt", "notes")