vael:path
Lexical POSIX and Windows path manipulation utilities.
Available in both vjs (vaeljs) and vjs-lite (vaeljs-lite) runtimes.
Provides host-dialect top-level helpers as well as explicit posix and
win32 dialects without touching the filesystem (except resolve,
relative, and Windows toNamespacedPath when reading the working directory).
import ... from "vael:path"
vaeljs-core; vael-path (default) in vaeljs-lite-coreExample
Section titled “Example”import { basename, dirname, extname, join, posix } from "vael:path";
const full = join("src", "app", "main.ts");console.log(dirname(full), basename(full), extname(full));console.log(posix.join("/etc", "nginx", "..", "hosts")); // "/etc/hosts"joinv0.0.0-alpha.0normalizev0.0.0-alpha.0. and .. segments and separators using the host dialect.basenamev0.0.0-alpha.0suffix.dirnamev0.0.0-alpha.0path.extnamev0.0.0-alpha.0".") of the last component, or "".isAbsolutev0.0.0-alpha.0true if path is absolute in the host dialect.parsev0.0.0-alpha.0path into { root, dir, base, ext, name }.formatv0.0.0-alpha.0{ root, dir, base, ext, name } object into a path string.commonv0.0.0-alpha.0paths without normalizing or folding case.resolvev0.0.0-alpha.0relativev0.0.0-alpha.0from to to in the host dialect.toNamespacedPathv0.0.0-alpha.0path to a Windows \\?\ namespaced path on Windows, or return path unchanged on POSIX.posixv0.0.0-alpha.0win32v0.0.0-alpha.0SEPARATORv0.0.0-alpha.0"/" on POSIX, "\\" on Windows).DELIMITERv0.0.0-alpha.0":" on POSIX, ";" on Windows).SEPARATOR_PATTERNv0.0.0-alpha.0/\/+/ on POSIX, /[\\/]+/ on Windows).Functions
Section titled “Functions”export function join(...paths: string[]): string;
Join and normalize path segments using the build host’s path dialect.
| Name | Type | Description |
|---|---|---|
...paths | string[] | Path segments to join. |
string — Normalized joined path string.TypeError— when any segment is not a string or contains NUL.
import { join } from "vael:path";
console.log(join("var", "log", "..", "lib", "app.db"));normalize
Section titled “normalize”export function normalize(path: string): string;
Normalize . and .. segments and separators using the host dialect.
| Name | Type | Description |
|---|---|---|
path | string | Path string to normalize. |
string — Normalized path string.TypeError— whenpathis not a string or contains NUL.
basename
Section titled “basename”export function basename(path: string, suffix?: string): string;
Return the final path component, optionally stripping suffix.
| Name | Type | Description |
|---|---|---|
path | string | Path string. |
suffix optional | string | Optional trailing suffix to strip when matched. |
string — Final path component.TypeError— on non-string arguments or NUL bytes.
import { basename } from "vael:path";
console.log(basename("/srv/app/config.json", ".json")); // "config"dirname
Section titled “dirname”export function dirname(path: string): string;
Return the directory portion of path.
| Name | Type | Description |
|---|---|---|
path | string | Path string. |
string — Directory portion of path.TypeError— on non-stringpathor NUL bytes.
extname
Section titled “extname”export function extname(path: string): string;
Return the extension (including leading ".") of the last component, or "".
| Name | Type | Description |
|---|---|---|
path | string | Path string. |
string — Extension string or "".TypeError— on non-stringpathor NUL bytes.
isAbsolute
Section titled “isAbsolute”export function isAbsolute(path: string): boolean;
Return true if path is absolute in the host dialect.
| Name | Type | Description |
|---|---|---|
path | string | Path string to test. |
boolean — true if path is absolute.TypeError— on non-stringpathor NUL bytes.
export function parse(path: string): ParsedPath;
Split path into { root, dir, base, ext, name }.
| Name | Type | Description |
|---|---|---|
path | string | Path string to parse. |
ParsedPath — ParsedPath component record.TypeError— on non-stringpathor NUL bytes.
import { parse } from "vael:path";
console.log(parse("/home/user/notes.md"));format
Section titled “format”export function format(pathObject: FormatInputPathObject): string;
Format a { root, dir, base, ext, name } object into a path string.
| Name | Type | Description |
|---|---|---|
pathObject | FormatInputPathObject | Partial path component object. |
string — Formatted path string.TypeError— on invalidpathObjector NUL bytes.
common
Section titled “common”export function common(paths: readonly string[]): string;
Return the shared prefix at component boundaries across paths without
normalizing or folding case.
| Name | Type | Description |
|---|---|---|
paths | readonly string[] | Array of path strings to compare. |
string — Shared component-boundary prefix string.TypeError— on invalid array or path strings.
resolve
Section titled “resolve”export function resolve(...paths: string[]): string;
Resolve a sequence of paths into an absolute path using the host dialect.
Reads the working directory at most once if inputs lack an absolute base.
| Name | Type | Description |
|---|---|---|
...paths | string[] | Path segments resolved right-to-left. |
string — Absolute resolved path string.TypeError— on non-string segments or NUL bytes.Error— withcode: PathErrorCodeif the working directory is unavailable.
import { resolve } from "vael:path";
console.log(resolve("examples", "webapp", "main.ts"));relative
Section titled “relative”export function relative(from: string, to: string): string;
Compute the relative path from from to to in the host dialect.
| Name | Type | Description |
|---|---|---|
from | string | Origin path. |
to | string | Destination path. |
string — Relative path string from from to to.TypeError— on non-string arguments or NUL bytes.Error— withcode: PathErrorCodeif the working directory is unavailable.
toNamespacedPath
Section titled “toNamespacedPath”export function toNamespacedPath(path: string): string;
Convert path to a Windows \\?\ namespaced path on Windows, or return path unchanged on POSIX.
| Name | Type | Description |
|---|---|---|
path | string | Path string to convert. |
string — Namespaced path on Windows, or path unchanged on POSIX.TypeError— on non-stringpathor NUL bytes.Error— withcode: PathErrorCodeif working directory resolution fails.
Interfaces
Section titled “Interfaces”ParsedPath
Section titled “ParsedPath”export interface ParsedPath {
root: string;
dir: string;
base: string;
ext: string;
name: string;
}
Parsed components returned by parse(path).
| Property | Type | Description | Since |
|---|---|---|---|
root | string | Root prefix ("/", "C:\\", "\\\\server\\share\\", or ""). | v0.0.0-alpha.0 |
dir | string | Directory portion without trailing separator (except root). | v0.0.0-alpha.0 |
base | string | Final path component including extension. | v0.0.0-alpha.0 |
ext | string | Extension including leading ".", or "". | v0.0.0-alpha.0 |
name | string | File name without extension. | v0.0.0-alpha.0 |
FormatInputPathObject
Section titled “FormatInputPathObject”export interface FormatInputPathObject {
root?: string;
dir?: string;
base?: string;
ext?: string;
name?: string;
}
Input object accepted by format(pathObject).
dir takes precedence over root; base takes precedence over name + ext.
| Property | Type | Description | Since |
|---|---|---|---|
root optional | string | Root prefix used when dir is omitted. | v0.0.0-alpha.0 |
dir optional | string | Directory path (takes precedence over root). | v0.0.0-alpha.0 |
base optional | string | File base name including extension (takes precedence over name + ext). | v0.0.0-alpha.0 |
ext optional | string | File extension including leading ".". | v0.0.0-alpha.0 |
name optional | string | File name without extension. | v0.0.0-alpha.0 |
PathDialect
Section titled “PathDialect”export interface PathDialect {
readonly sep: string;
readonly delimiter: string;
join(...paths: string[]): string;
normalize(path: string): string;
basename(path: string, suffix?: string): string;
dirname(path: string): string;
extname(path: string): string;
isAbsolute(path: string): boolean;
parse(path: string): ParsedPath;
format(pathObject: FormatInputPathObject): string;
common(paths: readonly string[]): string;
resolve(...paths: string[]): string;
relative(from: string, to: string): string;
toNamespacedPath(path: string): string;
}
Lexical path operations for a fixed syntax dialect (posix or win32).
All arguments must be strings without NUL (\0) characters; performs no
filesystem I/O (only resolve, relative, and Windows toNamespacedPath
read the working directory when inputs lack an absolute base).
| Property | Type | Description | Since |
|---|---|---|---|
sep readonly | string | Path component separator ("/" for posix, "\\" for win32). | v0.0.0-alpha.0 |
delimiter readonly | string | Path list delimiter (":" for posix, ";" for win32). | v0.0.0-alpha.0 |
PathDialect.join
Section titled “PathDialect.join”join(...paths: string[]): string;
Join and normalize path segments using this dialect.
| Name | Type | Description |
|---|---|---|
...paths | string[] | Path segments to join. |
string — Normalized joined path string.TypeError— when any segment is not a string or contains NUL.
PathDialect.normalize
Section titled “PathDialect.normalize”normalize(path: string): string;
Normalize . and .. segments and separators using this dialect.
| Name | Type | Description |
|---|---|---|
path | string | Path string to normalize. |
string — Normalized path string.TypeError— whenpathis not a string or contains NUL.
PathDialect.basename
Section titled “PathDialect.basename”basename(path: string, suffix?: string): string;
Return the final path component, optionally stripping suffix.
| Name | Type | Description |
|---|---|---|
path | string | Path string. |
suffix optional | string | Optional trailing suffix to strip when matched. |
string — Final path component.TypeError— on non-string arguments or NUL bytes.
PathDialect.dirname
Section titled “PathDialect.dirname”dirname(path: string): string;
Return the directory portion of path.
| Name | Type | Description |
|---|---|---|
path | string | Path string. |
string — Directory portion of path.TypeError— on non-stringpathor NUL bytes.
PathDialect.extname
Section titled “PathDialect.extname”extname(path: string): string;
Return the extension (including leading ".") of the last component, or "".
| Name | Type | Description |
|---|---|---|
path | string | Path string. |
string — Extension string or "".TypeError— on non-stringpathor NUL bytes.
PathDialect.isAbsolute
Section titled “PathDialect.isAbsolute”isAbsolute(path: string): boolean;
Return true if path is absolute in this dialect.
| Name | Type | Description |
|---|---|---|
path | string | Path string to test. |
boolean — true when path is absolute in this dialect.TypeError— on non-stringpathor NUL bytes.
PathDialect.parse
Section titled “PathDialect.parse”parse(path: string): ParsedPath;
Split path into { root, dir, base, ext, name }.
| Name | Type | Description |
|---|---|---|
path | string | Path string to split. |
ParsedPath — ParsedPath component record.TypeError— on non-stringpathor NUL bytes.
PathDialect.format
Section titled “PathDialect.format”format(pathObject: FormatInputPathObject): string;
Format a { root, dir, base, ext, name } object into a path string.
| Name | Type | Description |
|---|---|---|
pathObject | FormatInputPathObject | Partial path component object. |
string — Formatted path string.TypeError— on invalidpathObjector NUL bytes.
PathDialect.common
Section titled “PathDialect.common”common(paths: readonly string[]): string;
Return the shared prefix at component boundaries across paths.
| Name | Type | Description |
|---|---|---|
paths | readonly string[] | Array of path strings to compare. |
string — Common directory prefix string.TypeError— on invalid array or path strings.
PathDialect.resolve
Section titled “PathDialect.resolve”resolve(...paths: string[]): string;
Resolve a sequence of paths into an absolute path in this dialect.
| Name | Type | Description |
|---|---|---|
...paths | string[] | Sequence of path segments resolved right-to-left. |
string — Absolute resolved path string.TypeError— on non-string segments or NUL bytes.Error— withcode: PathErrorCodeif working directory resolution fails.
PathDialect.relative
Section titled “PathDialect.relative”relative(from: string, to: string): string;
Compute the relative path from from to to in this dialect.
| Name | Type | Description |
|---|---|---|
from | string | Origin path. |
to | string | Destination path. |
string — Relative path from from to to.TypeError— on non-string arguments or NUL bytes.Error— withcode: PathErrorCodeif working directory resolution fails.
PathDialect.toNamespacedPath
Section titled “PathDialect.toNamespacedPath”toNamespacedPath(path: string): string;
Convert path to a Windows \\?\ namespaced path when applicable.
| Name | Type | Description |
|---|---|---|
path | string | Path string to namespace. |
string — Namespaced path (on win32) or path unchanged (on posix).TypeError— on non-stringpathor NUL bytes.Error— withcode: PathErrorCodeif working directory resolution fails.
Type Aliases
Section titled “Type Aliases”PathErrorCode
Section titled “PathErrorCode”export type PathErrorCode = "PATH_CWD" | "PATH_CWD_DIALECT" | "PATH_WINDOWS_ROOT";
Error codes thrown by vael:path on PathError.code when resolving against
the working directory or invalid Windows roots.
Constants
Section titled “Constants”export const posix: PathDialect;
Frozen POSIX lexical path dialect.
export const win32: PathDialect;
Frozen Windows lexical path dialect.
SEPARATOR
Section titled “SEPARATOR”export const SEPARATOR: "/" | "\\";
Host path component separator ("/" on POSIX, "\\" on Windows).
DELIMITER
Section titled “DELIMITER”export const DELIMITER: ":" | ";";
Host path list delimiter (":" on POSIX, ";" on Windows).
SEPARATOR_PATTERN
Section titled “SEPARATOR_PATTERN”export const SEPARATOR_PATTERN: RegExp;
Host path separator pattern (/\/+/ on POSIX, /[\\/]+/ on Windows).
