Home > @microsoft/rush-lib > LookupByPath > findLongestPrefixMatch
LookupByPath.findLongestPrefixMatch() method
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.
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.
Signature:
findLongestPrefixMatch(query: string): IPrefixMatch<TItem> | undefined;
Parameters
| Parameter | Type | Description |
|---|---|---|
| query | string |
Returns:
IPrefixMatch<TItem> | undefined
the found item and the length of the matched prefix, or undefined if no item was found
Example
const tree = new LookupByPath([['foo', 1], ['foo/bar', 2]]);
tree.findLongestPrefixMatch('foo/baz'); // returns { item: 1, index: 3 }
tree.findLongestPrefixMatch('foo/bar/baz'); // returns { item: 2, index: 7 }