veko doc
Self-Contained API Reference • Gradual Types • Capabilities • Wasm Sandbox

path

lib/path.vk

lib/path.vk Pure-Veko lexical POSIX/cross-platform path manipulation and root confinement. Zero capabilities required.

signature
is-abs? = fn [p str] bool

Returns true if p is an absolute POSIX (/a/b) or Windows drive (C:/a/b) path.

signature
normalize = fn [p str] str

Lexically normalizes p, converting backslashes to /, collapsing duplicate slashes, and resolving . and .. segments cleanly.

Executable Example
veko
use [path]
if (path/normalize 'a/b/../c/./d.vk') != 'a/c/d.vk' [ err 'normalize' ] else [ .ok ]
join fn
signature
join = fn [a str, b str] str

Joins two path segments a and b and normalizes the result.

Executable Example
veko
use [path]
if (path/join 'src/lib' '../main.vk') != 'src/main.vk' [ err 'path/join' ] else [ .ok ]
signature
join-all = fn [parts block[str]] str

Joins a block of path segments and normalizes the result.

signature
split-parts = fn [p str] block[str]

Splits a normalized path into its non-empty path segments.

dir fn
signature
dir = fn [p str] str

Returns the parent directory portion of p.

Executable Example
veko
use [path]
if (path/dir 'a/b/c.vk') != 'a/b' [ err 'path/dir' ] else [ .ok ]
base fn
signature
base = fn [p str] str

Returns the final filename component of p.

Executable Example
veko
use [path]
if (path/base 'a/b/c.vk') != 'c.vk' [ err 'path/base' ] else [ .ok ]
ext fn
signature
ext = fn [p str] str

Returns the file extension including the leading . (or '' if none).

Executable Example
veko
use [path]
if (path/ext 'src/main.vk') != '.vk' or (path/stem 'src/main.vk') != 'main' [ err 'ext/stem' ] else [ .ok ]
stem fn
signature
stem = fn [p str] str

Returns the base filename without its final extension.

signature
with-ext = fn [p str, new_ext str] str

Replaces (or appends) the file extension of p with new_ext (with or without leading .).

signature
confine = fn [root str, rel str] str

Safely resolves rel inside root, returning err if rel is absolute or escapes root via ...

Executable Example
veko
use [path]
ok_p = path/confine '/srv/app' 'assets/logo.svg'
bad_p = path/confine/or '/srv/app' '../../etc/passwd' ['blocked']
if ok_p != '/srv/app/assets/logo.svg' or bad_p != 'blocked' [ err 'confine' ] else [ .ok ]