Rush StackShopBlogEvents
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.findChildPath('foo'); // returns 1
tree.findChildPath('foo/baz'); // returns 1
tree.findChildPath('baz'); // returns undefined
tree.findChildPath('foo/bar/baz'); returns 3
tree.findChildPath('bar/foo/bar'); returns 2

Constructors

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

Properties

PropertyModifiersTypeDescription
delimiterreadonlystring(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.
findLongestPrefixMatch(query)(BETA) Searches for the item for which the recorded prefix is the longest matching prefix of query. Obtains both the item and the length of the matched prefix, so that the remainder of the path can be extracted.
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.