Skip to content

PurePath.withSuffix() method

pathlib-ts > PurePath > withSuffix

Return a new path with the file suffix changed. If the path has no suffix, add the given suffix. If the given suffix is an empty string, remove the suffix from the path.

Signature:

withSuffix(suffix: string): PurePath;

Parameter

Type

Description

suffix

string

New suffix starting with a dot, or an empty string to remove it.

Returns:

PurePath

A new path with the updated suffix.

The Error class If the suffix does not start with . or the path lacks a stem.

Provide "" to strip the suffix entirely. The argument must start with a dot unless it is empty. Behaviour matches CPython, including validation of empty stems.