RoadmapShopEvents
Skip to main content

Home > @microsoft/rush-lib > LookupByPath

LookupByPath class

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

This class is used to associate POSIX relative paths, such as those returned by git commands, with entities that correspond with ancestor folders, such as Rush Projects.

It is optimized for efficiently locating the nearest ancestor path with an associated value.

Signature:
export declare class LookupByPath<TItem>

Example

const tree = new LookupByPath([['foo', 1], ['bar', 2], ['foo/bar', 3]]);
tree.getNearestAncestor('foo'); // returns 1
tree.getNearestAncestor('foo/baz'); // returns 1
tree.getNearestAncestor('baz'); // returns undefined
tree.getNearestAncestor('foo/bar/baz'); returns 3
tree.getNearestAncestor('bar/foo/bar'); returns 2

Constructors

ConstructorModifiersDescription
(constructor)(entries, delimiter)(BETA) Constructs a new LookupByPath

Properties

PropertyModifiersTypeDescription
delimiterstring(BETA) The delimiter used to split paths

Methods

MethodModifiersDescription
findChildPath(childPath)(BETA) Searches for the item associated with childPath, or the nearest ancestor of that path that has an associated item.
findChildPathFromSegments(childPathSegments)(BETA) Searches for the item associated with childPathSegments, or the nearest ancestor of that path that has an associated item.
iteratePathSegments(serializedPath, delimiter)static(BETA) Iterates over the segments of a serialized path.
setItem(serializedPath, value)(BETA) Associates the value with the specified serialized path. If a value is already associated, will overwrite.
setItemFromSegments(pathSegments, value)(BETA) Associates the value with the specified path. If a value is already associated, will overwrite.