Skip to content

paths

Functions

basename()

function basename(path, extension?): string;

Returns the last path segment, optionally removing a known extension suffix.

Parameters

path

string

Path to inspect.

extension?

string

Optional extension suffix to remove from the result.

Returns

string

The basename of path.

Example

basename("generated/models/user.ts");
// returns "user.ts"

See

Powered by pathe (MIT License): https://github.com/unjs/pathe


dirname()

function dirname(path): string;

Returns the parent directory portion of a path.

Parameters

path

string

Path to inspect.

Returns

string

The directory name portion of path.

Example

dirname("generated/models/user.ts");
// returns "generated/models"

See

Powered by pathe (MIT License): https://github.com/unjs/pathe


extname()

function extname(path): string;

Returns the file extension of a path, including the leading dot.

Parameters

path

string

Path to inspect.

Returns

string

The extension portion of path, or an empty string when none exists.

Example

extname("generated/models/user.ts");
// returns ".ts"

See

Powered by pathe (MIT License): https://github.com/unjs/pathe


filename()

function filename(path): string | undefined;

Returns the filename without its extension.

This is useful for deriving stable artifact names without manually stripping directory segments or extensions.

Parameters

path

string

Path to inspect.

Returns

string | undefined

The filename without its extension, or undefined when it cannot be derived.

Example

filename("generated/models/user.ts");
// returns "user"

See

Powered by pathe (MIT License): https://github.com/unjs/pathe


isAbsolute()

function isAbsolute(path): boolean;

Checks whether a path is absolute.

Parameters

path

string

Path to inspect.

Returns

boolean

true when path is absolute, otherwise false.

Example

isAbsolute("/generated/models/user.ts");
// returns true

See

Powered by pathe (MIT License): https://github.com/unjs/pathe


join()

function join(...parts): string;

Joins path segments using deterministic forward-slash normalization.

This is a thin wrapper around pathe.join, which keeps behavior consistent across platforms and normalizes path separators to /.

Parameters

parts

...string[]

Path segments to join.

Returns

string

The normalized joined path.

Example

join("generated", "models", "user.ts");
// returns "generated/models/user.ts"z

See

Powered by pathe (MIT License): https://github.com/unjs/pathe


normalize()

function normalize(path): string;

Normalizes a path by collapsing redundant separators and dot segments.

This is helpful when plugin code receives mixed Windows and POSIX-style path input and needs a single predictable format.

Parameters

path

string

Path to normalize.

Returns

string

The normalized path using / separators.

Example

normalize("generated\\models/../types/user.ts");
// returns "generated/types/user.ts"

See

Powered by pathe (MIT License): https://github.com/unjs/pathe


relative()

function relative(from, to): string;

Computes the relative path from one location to another.

Parameters

from

string

Starting path.

to

string

Destination path.

Returns

string

The normalized relative path from from to to.

Example

relative("generated/models", "generated/types/user.ts");
// returns "../types/user.ts"

See

Powered by pathe (MIT License): https://github.com/unjs/pathe


resolve()

function resolve(...parts): string;

Resolves one or more path segments into a normalized absolute or rooted path.

This is useful when plugin code needs stable path resolution without relying on platform-specific separators.

Parameters

parts

...string[]

Path segments to resolve.

Returns

string

The resolved normalized path.

Example

resolve("/workspace/plugin", "src", "../dist/index.js");
// returns "/workspace/plugin/dist/index.js"

See

Powered by pathe (MIT License): https://github.com/unjs/pathe