PurePath class
PurePath class
Section titled “PurePath class”Immutable filesystem path that never performs I/O.
Signature:
export declare class PurePathRemarks
Section titled “Remarks”This mirrors CPython’s `pathlib.PurePath`. Separators are normalised according to the active parser (POSIX vs Windows), parts are exposed via flavour-aware casing, and joining semantics match the reference implementation. Prefer this class when you need deterministic, purely lexical path manipulation. Use Path to add filesystem-aware operations.
The constructor preserves the concrete subclass by default: instantiating PurePath chooses the flavour for the current runtime, whereas PurePosixPath and PureWindowsPath can be requested explicitly for cross-platform tooling.
Example
Section titled “Example”Creating a nested PurePath without touching the filesystem
import { PurePath } from "pathlib-ts";
const project = new PurePath("/srv/app");const config = project.joinpath("pyproject.toml");
console.log(config.toString()); // '/srv/app/pyproject.toml'console.log(config.isAbsolute()); // trueConstructors
Section titled “Constructors”|
Constructor |
Modifiers |
Description |
|---|---|---|
|
Constructs a new instance of the |
Properties
Section titled “Properties”|
Property |
Modifiers |
Type |
Description |
|---|---|---|---|
|
|
string |
The concatenation of the drive and root, or ”. | |
|
|
boolean | ||
|
|
string |
Gets the drive prefix for Windows-style paths, or an empty string on POSIX. | |
|
|
string |
(Optional) | |
|
|
string |
Returns the final path component as a string, excluding any anchor, if any. | |
|
|
string |
(Optional) | |
|
|
string[] |
(Optional) | |
|
|
Returns the lexical (logical) parent of the current path. | ||
|
|
Provides indexed access to the sequence of lexical (logical) ancestors of the path. | ||
|
|
nodepath.PlatformPath | ||
|
|
nodepath.PlatformPath | ||
|
|
string[] |
Returns the normalized path components as an array of strings. | |
|
|
string[] | ||
|
|
string |
A string representing the (local or global) root, if any. | |
|
|
string |
(Optional) | |
|
|
string |
Returns the final component without its last suffix. | |
|
|
string |
(Optional) | |
|
|
string |
Returns the rightmost suffix (including the leading dot) for the last path segment. | |
|
|
string[] |
Lists all suffixes (extensions) attached to the final path component, if any. | |
|
|
string[] |
(Optional) |
Methods
Section titled “Methods”|
Method |
Modifiers |
Description |
|---|---|---|
|
| ||
|
Returns the string representation of the path with forward (/) slashes, regardless of platform. | ||
|
Converts the path to a | ||
|
| ||
|
Removes trailing segments from the path while preserving the anchor. | ||
|
| ||
|
|
Creates a path from a | |
|
Tests whether the entire path matches a glob-style pattern. | ||
|
Indicates whether the path is anchored (has a root and optional drive). | ||
|
Returns | ||
|
Produces a new path by appending additional segments to the current instance. | ||
|
Checks whether the path matches a non-recursive glob pattern. | ||
|
| ||
|
Return the relative path to another path identified by the passed arguments. | ||
|
| ||
|
Returns a new path with the final component replaced by the provided name. | ||
|
Builds a sibling path instance of the same type by combining additional segments. | ||
|
Returns a new path with the stem component changed. | ||
|
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. |