Skip to content

Path.expandUser() method

pathlib-ts > Path > expandUser

Return a new path with expanded ~ and ~user constructs.

Signature:

expandUser(): Promise<Path>;

Returns:

Promise<Path>

Promise resolving to a Path with user-home prefixes expanded.

The Error class When the home directory cannot be determined.

Uses the current platform home directory lookup to mirror CPython semantics.

Expanding a user directory asynchronously

import { Path } from "pathlib-ts";
const downloads = await new Path("~/Downloads").expandUser();
console.log(downloads.toString());