Skip to content
VaelJS Blog

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"
Since v0.0.0-alpha.2 vjs (V8) vjs-lite (QuickJS)
Cargo feature: Always enabled in vaeljs-core; vael-os (default) in vaeljs-lite-core
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);
API Symbols
Functions (14)
homeDirv0.0.0-alpha.2
Return the current user's home directory, or null if unavailable.
configDirv0.0.0-alpha.2
Return the user's configuration directory ($XDG_CONFIG_HOME / ~/.config on Linux, ~/Library/Application Support on macOS...
dataDirv0.0.0-alpha.2
Return the user's roaming data directory ($XDG_DATA_HOME / ~/.local/share on Linux, ~/Library/Application Support on macOS...
localDataDirv0.0.0-alpha.2
Return the user's local (non-roaming) data directory ($XDG_DATA_HOME / ~/.local/share on Linux, ~/Library/Application Support on ma...
cacheDirv0.0.0-alpha.2
Return the user's cache directory ($XDG_CACHE_HOME / ~/.cache on Linux, ~/Library/Caches on macOS, %LOCALAPPDATA% on Windows), or...
stateDirv0.0.0-alpha.2
Return the user's state directory ($XDG_STATE_HOME / ~/.local/state on Linux, null on macOS and Windows).
runtimeDirv0.0.0-alpha.2
Return the user's XDG runtime directory ($XDG_RUNTIME_DIR on Linux when set to a valid absolute path; null otherwise).
tempDirv0.0.0-alpha.2
Return the host temporary files directory.
desktopDirv0.0.0-alpha.2
Return the user's Desktop directory, or null if unavailable.
documentsDirv0.0.0-alpha.2
Return the user's Documents directory, or null if unavailable.
downloadsDirv0.0.0-alpha.2
Return the user's Downloads directory, or null if unavailable.
picturesDirv0.0.0-alpha.2
Return the user's Pictures directory, or null if unavailable.
xdgDirsv0.0.0-alpha.2
Return the frozen XdgDirs snapshot of XDG Base Directory paths for the current host.
specialFolderv0.0.0-alpha.2
Resolve a .NET System.Environment.SpecialFolder directory path on the current host.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function homeDir(): string | null;

Return the current user’s home directory, or null if unavailable.

Returns
string | null — Absolute home directory path, or null.
Exceptions
  • TypeError — when any argument is supplied.
functionSince v0.0.0-alpha.2vjs & vjs-lite
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.

Returns
string | null — Configuration directory path, or null.
Exceptions
  • TypeError — when any argument is supplied.
functionSince v0.0.0-alpha.2vjs & vjs-lite
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.

Returns
string | null — Data directory path, or null.
Exceptions
  • TypeError — when any argument is supplied.
functionSince v0.0.0-alpha.2vjs & vjs-lite
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.

Returns
string | null — Local data directory path, or null.
Exceptions
  • TypeError — when any argument is supplied.
functionSince v0.0.0-alpha.2vjs & vjs-lite
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.

Returns
string | null — Cache directory path, or null.
Exceptions
  • TypeError — when any argument is supplied.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function stateDir(): string | null;

Return the user’s state directory ($XDG_STATE_HOME / ~/.local/state on Linux, null on macOS and Windows).

Returns
string | null — State directory path, or null.
Exceptions
  • TypeError — when any argument is supplied.
functionSince v0.0.0-alpha.2vjs & vjs-lite
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).

Returns
string | null — Runtime directory path, or null.
Exceptions
  • TypeError — when any argument is supplied.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function tempDir(): string;

Return the host temporary files directory.

Returns
string — Non-empty temporary directory path.
Exceptions
  • TypeError — when any argument is supplied.
import { tempDir } from "vael:os/dirs";
console.log(tempDir());
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function desktopDir(): string | null;

Return the user’s Desktop directory, or null if unavailable.

Returns
string | null — Desktop directory path, or null.
Exceptions
  • TypeError — when any argument is supplied.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function documentsDir(): string | null;

Return the user’s Documents directory, or null if unavailable.

Returns
string | null — Documents directory path, or null.
Exceptions
  • TypeError — when any argument is supplied.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function downloadsDir(): string | null;

Return the user’s Downloads directory, or null if unavailable.

Returns
string | null — Downloads directory path, or null.
Exceptions
  • TypeError — when any argument is supplied.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function picturesDir(): string | null;

Return the user’s Pictures directory, or null if unavailable.

Returns
string | null — Pictures directory path, or null.
Exceptions
  • TypeError — when any argument is supplied.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function xdgDirs(): XdgDirs;

Return the frozen XdgDirs snapshot of XDG Base Directory paths for the current host.

Returns
XdgDirs — Frozen XdgDirs object with frozen dataDirs and configDirs arrays.
Exceptions
  • TypeError — when any argument is supplied.
import { xdgDirs } from "vael:os/dirs";
const xdg = xdgDirs();
console.log(xdg.configHome, xdg.dataDirs);
functionSince v0.0.0-alpha.2vjs & vjs-lite
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.

Parameters
NameTypeDescription
folderSpecialFolder.NET SpecialFolder name (such as "ApplicationData" or "Temp").
Returns
string | null — Resolved directory path, or null when that folder is not applicable on the host OS.
Exceptions
  • TypeError — when folder is not a string or not a recognized SpecialFolder name.
import { specialFolder } from "vael:os/dirs";
const tmp = specialFolder("Temp");
console.log(tmp);
interfaceSince v0.0.0-alpha.2vjs & vjs-lite
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).

Properties
PropertyTypeDescriptionSince
configHome readonlystring | null$XDG_CONFIG_HOME or $HOME/.config (platform fallback on non-Linux), or null if unavailable.v0.0.0-alpha.2
dataHome readonlystring | null$XDG_DATA_HOME or $HOME/.local/share (platform fallback on non-Linux), or null if unavailable.v0.0.0-alpha.2
cacheHome readonlystring | null$XDG_CACHE_HOME or $HOME/.cache (platform fallback on non-Linux), or null if unavailable.v0.0.0-alpha.2
stateHome readonlystring | null$XDG_STATE_HOME or $HOME/.local/state (or null when unavailable).v0.0.0-alpha.2
runtimeDir readonlystring | null$XDG_RUNTIME_DIR when set to a valid absolute path; otherwise null.v0.0.0-alpha.2
dataDirs readonlyreadonly 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 readonlyreadonly 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
typeSince v0.0.0-alpha.2vjs & vjs-lite
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().