Skip to content

Latest commit

 

History

History
111 lines (78 loc) · 2.6 KB

path.md

File metadata and controls

111 lines (78 loc) · 2.6 KB
id stdlib-path
title Path Module
slug /stdlib/path

All functions in this module are core builtins. They manipulate path strings without filesystem access. Rules are fixed on every platform: / is the only separator, comparison is case-sensitive and ordinal, and backslashes/drive letters are ordinary characters. The base for relative paths must be supplied explicitly. These functions do not inspect symlinks, check existence, or prove filesystem containment. Normalize inputs explicitly before glob matching if desired.

Path.normalize

Path.normalize : string -> string

Collapses repeated /, . segments, and resolvable .. segments. Absolute paths cannot ascend above /; unresolved leading parents in relative paths are preserved. Removes trailing separators. Empty relative results become ..

Path.normalize "a/./b/../c"
// "a/c"

Path.isAbsolute

Path.isAbsolute : string -> bool

Tests for a leading /. Drive letters and backslashes have no special meaning.

Path.isAbsolute "/a"
// true

Path.combine

Path.combine : string -> string -> string

Joins and normalizes two paths. An absolute right argument replaces the left argument.

Path.combine "a/b" "../c"
// "a/c"

Path.fileName

Path.fileName : string -> string

Returns the last segment after trimming trailing / characters. The root path produces the empty string.

Path.fileName "a/b.txt"
// "b.txt"

Path.extension

Path.extension : string -> string option

Returns the final extension including its dot, or None for a dotfile, absent extension, or trailing dot.

Path.extension "a/b.txt"
// Some ".txt"

Path.fileNameWithoutExtension

Path.fileNameWithoutExtension : string -> string

Returns the last segment without its final extension. A leading dot alone does not introduce an extension.

Path.fileNameWithoutExtension "a/b.txt"
// "b"

Path.parent

Path.parent : string -> string option

Returns the parent of a normalized path. A single relative filename has parent .; / and . have no parent.

Path.parent "a/b.txt"
// Some "a"

Path.relative

Path.relative : string -> string -> string option

Computes a lexical path from the supplied base directory to the target. Returns None for mixed absolute/relative paths or unresolved parents remaining in the base after removing the common prefix. Equal paths return Some ".".

Path.relative "/a/b" "/a/c/file"
// Some "../c/file"