Rush StackShopBlogEvents
Skip to main content

Home > @rushstack/lookup-by-path > LookupByPath

LookupByPath class

This API is provided as a beta 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 path-like-strings, such as those returned by git commands, with entities that correspond with ancestor folders, such as Rush Projects or npm packages.

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

It is implemented as a Trie (https://en.wikipedia.org/wiki/Trie) data structure, with each edge being a path segment.

Signature:

export declare class LookupByPath<TItem extends {}> implements IReadonlyLookupByPath<TItem> 

Implements: IReadonlyLookupByPath<TItem>

Example

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

Constructors

Constructor

Modifiers

Description

(constructor)(entries, delimiter)

(BETA) Constructs a new LookupByPath

Properties

Property

Modifiers

Type

Description

delimiter

readonly

string

(BETA) The delimiter used to split paths

size

readonly

number

(BETA) Gets the number of entries in this trie.

tree

readonly

IReadonlyPathTrieNode<TItem>

(BETA)

Methods

Method

Modifiers

Description

[Symbol.iterator](query, delimiter)

(BETA) The readonly component of LookupByPath, to simplify unit testing.

clear()

(BETA) Deletes all entries from this LookupByPath instance.

deleteItem(query, delimeter)

(BETA) Deletes an item if it exists.

deleteSubtree(query, delimeter)

(BETA) Deletes an item and all its children.

entries(query, delimiter)

(BETA) The readonly component of LookupByPath, to simplify unit testing.

findChildPath(childPath, delimiter)

(BETA) The readonly component of LookupByPath, to simplify unit testing.

findChildPathFromSegments(childPathSegments)

(BETA) The readonly component of LookupByPath, to simplify unit testing.

findLongestPrefixMatch(query, delimiter)

(BETA) The readonly component of LookupByPath, to simplify unit testing.

get(key, delimiter)

(BETA) The readonly component of LookupByPath, to simplify unit testing.

getNodeAtPrefix(query, delimiter)

(BETA) The readonly component of LookupByPath, to simplify unit testing.

groupByChild(infoByPath, delimiter)

(BETA) The readonly component of LookupByPath, to simplify unit testing.

has(key, delimiter)

(BETA) The readonly component of LookupByPath, to simplify unit testing.

iteratePathSegments(serializedPath, delimiter)

static

(BETA) Iterates over the segments of a serialized path.

setItem(serializedPath, value, delimiter)

(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.