vael:os/dirs
Cross-platform user directories, XDG Base Directory Specification paths, and
.NET SpecialFolder resolution.
Available in both vjs (vaeljs) and vjs-lite (vaeljs-lite) runtimes.
Resolves standard platform directories on Linux (XDG Base Directory +
user-dirs.dirs), macOS (~/Library/...), and Windows (Known Folders and
environment fallbacks). Installs no globals.
import ... from "vael:os/dirs"
vaeljs-core; vael-os (default) in vaeljs-lite-coreExample
Section titled “Example”import { configDir, specialFolder, tempDir, xdgDirs } from "vael:os/dirs";
console.log("Temp:", tempDir());console.log("Config:", configDir());console.log("Downloads:", specialFolder("Downloads"));console.log("XDG:", xdgDirs().dataDirs);homeDirv0.0.0-alpha.2null if unavailable.configDirv0.0.0-alpha.2$XDG_CONFIG_HOME / ~/.config on Linux, ~/Library/Application Support on macOS...dataDirv0.0.0-alpha.2$XDG_DATA_HOME / ~/.local/share on Linux, ~/Library/Application Support on macOS...localDataDirv0.0.0-alpha.2$XDG_DATA_HOME / ~/.local/share on Linux, ~/Library/Application Support on ma...cacheDirv0.0.0-alpha.2$XDG_CACHE_HOME / ~/.cache on Linux, ~/Library/Caches on macOS, %LOCALAPPDATA% on Windows), or...stateDirv0.0.0-alpha.2$XDG_STATE_HOME / ~/.local/state on Linux, null on macOS and Windows).runtimeDirv0.0.0-alpha.2$XDG_RUNTIME_DIR on Linux when set to a valid absolute path; null otherwise).tempDirv0.0.0-alpha.2desktopDirv0.0.0-alpha.2null if unavailable.documentsDirv0.0.0-alpha.2null if unavailable.downloadsDirv0.0.0-alpha.2null if unavailable.picturesDirv0.0.0-alpha.2null if unavailable.xdgDirsv0.0.0-alpha.2XdgDirs snapshot of XDG Base Directory paths for the current host.specialFolderv0.0.0-alpha.2.NET System.Environment.SpecialFolder directory path on the current host.Functions
Section titled “Functions”homeDir
Section titled “homeDir”export function homeDir(): string | null;
Return the current user’s home directory, or null if unavailable.
string | null — Absolute home directory path, or null.TypeError— when any argument is supplied.
configDir
Section titled “configDir”export function configDir(): string | null;
Return the user’s configuration directory ($XDG_CONFIG_HOME /
~/.config on Linux, ~/Library/Application Support on macOS,
%APPDATA% on Windows), or null if unavailable.
string | null — Configuration directory path, or null.TypeError— when any argument is supplied.
dataDir
Section titled “dataDir”export function dataDir(): string | null;
Return the user’s roaming data directory ($XDG_DATA_HOME /
~/.local/share on Linux, ~/Library/Application Support on macOS,
%APPDATA% on Windows), or null if unavailable.
string | null — Data directory path, or null.TypeError— when any argument is supplied.
localDataDir
Section titled “localDataDir”export function localDataDir(): string | null;
Return the user’s local (non-roaming) data directory ($XDG_DATA_HOME /
~/.local/share on Linux, ~/Library/Application Support on macOS,
%LOCALAPPDATA% on Windows), or null if unavailable.
string | null — Local data directory path, or null.TypeError— when any argument is supplied.
cacheDir
Section titled “cacheDir”export function cacheDir(): string | null;
Return the user’s cache directory ($XDG_CACHE_HOME / ~/.cache on
Linux, ~/Library/Caches on macOS, %LOCALAPPDATA% on Windows), or
null if unavailable.
string | null — Cache directory path, or null.TypeError— when any argument is supplied.
stateDir
Section titled “stateDir”export function stateDir(): string | null;
Return the user’s state directory ($XDG_STATE_HOME / ~/.local/state
on Linux, null on macOS and Windows).
string | null — State directory path, or null.TypeError— when any argument is supplied.
runtimeDir
Section titled “runtimeDir”export function runtimeDir(): string | null;
Return the user’s XDG runtime directory ($XDG_RUNTIME_DIR on Linux when
set to a valid absolute path; null otherwise).
string | null — Runtime directory path, or null.TypeError— when any argument is supplied.
tempDir
Section titled “tempDir”export function tempDir(): string;
Return the host temporary files directory.
string — Non-empty temporary directory path.TypeError— when any argument is supplied.
import { tempDir } from "vael:os/dirs";
console.log(tempDir());desktopDir
Section titled “desktopDir”export function desktopDir(): string | null;
Return the user’s Desktop directory, or null if unavailable.
string | null — Desktop directory path, or null.TypeError— when any argument is supplied.
documentsDir
Section titled “documentsDir”export function documentsDir(): string | null;
Return the user’s Documents directory, or null if unavailable.
string | null — Documents directory path, or null.TypeError— when any argument is supplied.
downloadsDir
Section titled “downloadsDir”export function downloadsDir(): string | null;
Return the user’s Downloads directory, or null if unavailable.
string | null — Downloads directory path, or null.TypeError— when any argument is supplied.
picturesDir
Section titled “picturesDir”export function picturesDir(): string | null;
Return the user’s Pictures directory, or null if unavailable.
string | null — Pictures directory path, or null.TypeError— when any argument is supplied.
xdgDirs
Section titled “xdgDirs”export function xdgDirs(): XdgDirs;
Return the frozen XdgDirs snapshot of XDG Base Directory paths for the
current host.
TypeError— when any argument is supplied.
import { xdgDirs } from "vael:os/dirs";
const xdg = xdgDirs();console.log(xdg.configHome, xdg.dataDirs);specialFolder
Section titled “specialFolder”export function specialFolder(folder: SpecialFolder): string | null;
Resolve a .NET System.Environment.SpecialFolder directory path on the
current host.
Accepts canonical PascalCase names as well as case-insensitive, camelCase,
kebab-case, and snake_case equivalents of the 18 SpecialFolder variants.
Unknown folder names throw TypeError.
| Name | Type | Description |
|---|---|---|
folder | SpecialFolder | .NET SpecialFolder name (such as "ApplicationData" or "Temp"). |
string | null — Resolved directory path, or null when that folder is not applicable on the host OS.TypeError— whenfolderis not a string or not a recognizedSpecialFoldername.
import { specialFolder } from "vael:os/dirs";
const tmp = specialFolder("Temp");console.log(tmp);Interfaces
Section titled “Interfaces”XdgDirs
Section titled “XdgDirs”export interface XdgDirs {
readonly configHome: string | null;
readonly dataHome: string | null;
readonly cacheHome: string | null;
readonly stateHome: string | null;
readonly runtimeDir: string | null;
readonly dataDirs: readonly string[];
readonly configDirs: readonly string[];
}
Frozen XDG Base Directory Specification paths returned by xdgDirs().
On Linux and Unix, relative paths in XDG_* variables are ignored and fall
back to XDG specification defaults ($HOME/.config, $HOME/.local/share,
$HOME/.cache, $HOME/.local/state, ["/usr/local/share", "/usr/share"],
["/etc/xdg"], and runtimeDir = null unless $XDG_RUNTIME_DIR is a
valid absolute path).
| Property | Type | Description | Since |
|---|---|---|---|
configHome readonly | string | null | $XDG_CONFIG_HOME or $HOME/.config (platform fallback on non-Linux), or null if unavailable. | v0.0.0-alpha.2 |
dataHome readonly | string | null | $XDG_DATA_HOME or $HOME/.local/share (platform fallback on non-Linux), or null if unavailable. | v0.0.0-alpha.2 |
cacheHome readonly | string | null | $XDG_CACHE_HOME or $HOME/.cache (platform fallback on non-Linux), or null if unavailable. | v0.0.0-alpha.2 |
stateHome readonly | string | null | $XDG_STATE_HOME or $HOME/.local/state (or null when unavailable). | v0.0.0-alpha.2 |
runtimeDir readonly | string | null | $XDG_RUNTIME_DIR when set to a valid absolute path; otherwise null. | v0.0.0-alpha.2 |
dataDirs readonly | readonly string[] | Frozen preference-ordered array of base data directories parsed from $XDG_DATA_DIRS (defaults to ["/usr/local/share", "/usr/share"] on Linux/Unix, [] on Windows). | v0.0.0-alpha.2 |
configDirs readonly | readonly string[] | Frozen preference-ordered array of base configuration directories parsed from $XDG_CONFIG_DIRS (defaults to ["/etc/xdg"] on Linux/Unix, [] on Windows). | v0.0.0-alpha.2 |
Type Aliases
Section titled “Type Aliases”SpecialFolder
Section titled “SpecialFolder”export type SpecialFolder =
| "UserProfile"
| "ApplicationData"
| "LocalApplicationData"
| "CommonApplicationData"
| "Desktop"
| "MyDocuments"
| "Personal"
| "Downloads"
| "MyPictures"
| "MyMusic"
| "MyVideos"
| "Templates"
| "Fonts"
| "ProgramFiles"
| "ProgramFilesX86"
| "System"
| "Windows"
| "Temp";
.NET System.Environment.SpecialFolder directory identifiers accepted by
specialFolder().
