Skip to content

PathParents class

pathlib-ts > PathParents

Sequence-like view over the logical ancestors of a PurePath.

Signature:

export declare class PathParents implements Iterable<PurePath>

Implements: Iterable<PurePath>

Iterating over this object yields each parent path in order, from immediate to the top-level anchor.

Iterating over parent directories

import { PathParents, PurePath } from "pathlib-ts";
const article = new PurePath("/site/content/posts/launch.mdx");
const parents = new PathParents(article);
for (const parent of parents) {
console.log(parent.toString());
}
// '/site/content/posts'
// '/site/content'
// '/site'

Constructor

Modifiers

Description

(constructor)(origin)

Constructs a new instance of the PathParents class

Property

Modifiers

Type

Description

length

readonly

number

Method

Modifiers

Description

[Symbol.iterator]()

at(index)