Skip to content

Path.replace() method

pathlib-ts > Path > replace

Replace the target path, overwriting it if necessary, and return the new Path.

Signature:

replace(target: PathLike): Promise<Path>;

Parameter

Type

Description

target

PathLike

Destination path or string.

Returns:

Promise<Path>

Promise resolving to a Path representing the destination.

Overwrite behavior matches CPython while relying on Node’s rename.

Replacing assets atomically asynchronously

import { Path } from "pathlib-ts";
const staged = new Path("./public/app.css.stage");
await staged.replace("./public/app.css");