Skip to content

cdt.path ​

Platform-aware lexical path manipulation without filesystem access.

conduit
import * as path from "cdt.path"

func main() -> Void {
    p := path.join("/var/log", "app/../service/server.log")
    clean := path.normalize(p)
    print(path.dirname(clean))   // /var/log/service
    print(path.basename(clean))  // server.log
    print(path.stem(clean))      // server
    print(path.ext(clean))       // log
    print(path.with_ext(clean, "json")) // /var/log/service/server.json
}

API ​

FunctionSignatureDescription
join(a: String, b: String) -> StringJoins two path segments
join_all(parts: [String]) -> StringJoins a list of path segments
dirname(p: String) -> StringParent directory (or "" if none)
basename(p: String) -> StringFinal file or directory name
ext(p: String) -> StringExtension without leading . (or "")
stem(p: String) -> StringFile name without extension
normalize(p: String) -> StringLexically resolves . and ..
is_abs(p: String) -> Booltrue if p is an absolute path
with_ext(p: String, ext: String) -> StringReplaces or appends file extension
safe_join(root: String, rel: String) -> String?Safely joins rel under canonical root, resolving symlinks step-by-step against the filesystem and returning nil on .. traversal, absolute/prefixed paths, NUL bytes, dangling symlinks, or symlink escapes (allows not-yet-created nested files inside an existing root)