Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@rushstack/lookup-by-path

Package Overview
Dependencies
Maintainers
0
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rushstack/lookup-by-path - npm Package Compare versions

Comparing version 0.3.2 to 0.4.0

12

CHANGELOG.json

@@ -5,2 +5,14 @@ {

{
"version": "0.4.0",
"tag": "@rushstack/lookup-by-path_v0.4.0",
"date": "Thu, 17 Oct 2024 20:25:42 GMT",
"comments": {
"minor": [
{
"comment": "Add `IReadonlyLookupByPath` interface to help unit tests for functions that consume `LookupByPath`."
}
]
}
},
{
"version": "0.3.2",

@@ -7,0 +19,0 @@ "tag": "@rushstack/lookup-by-path_v0.3.2",

9

CHANGELOG.md
# Change Log - @rushstack/lookup-by-path
This log was last generated on Thu, 17 Oct 2024 08:35:06 GMT and should not be manually modified.
This log was last generated on Thu, 17 Oct 2024 20:25:42 GMT and should not be manually modified.
## 0.4.0
Thu, 17 Oct 2024 20:25:42 GMT
### Minor changes
- Add `IReadonlyLookupByPath` interface to help unit tests for functions that consume `LookupByPath`.
## 0.3.2

@@ -6,0 +13,0 @@ Thu, 17 Oct 2024 08:35:06 GMT

106

dist/lookup-by-path.d.ts

@@ -28,2 +28,62 @@ /**

/**
* The readonly component of `LookupByPath`, to simplify unit testing.
*
* @beta
*/
export declare interface IReadonlyLookupByPath<TItem> {
/**
* Searches for the item associated with `childPath`, or the nearest ancestor of that path that
* has an associated item.
*
* @returns the found item, or `undefined` if no item was found
*
* @example
* ```ts
* const trie = new LookupByPath([['foo', 1], ['foo/bar', 2]]);
* trie.findChildPath('foo/baz'); // returns 1
* trie.findChildPath('foo/bar/baz'); // returns 2
* ```
*/
findChildPath(childPath: string): TItem | undefined;
/**
* 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.
*
* @returns the found item and the length of the matched prefix, or `undefined` if no item was found
*
* @example
* ```ts
* const trie = new LookupByPath([['foo', 1], ['foo/bar', 2]]);
* trie.findLongestPrefixMatch('foo/baz'); // returns { item: 1, index: 3 }
* trie.findLongestPrefixMatch('foo/bar/baz'); // returns { item: 2, index: 7 }
* ```
*/
findLongestPrefixMatch(query: string): IPrefixMatch<TItem> | undefined;
/**
* Searches for the item associated with `childPathSegments`, or the nearest ancestor of that path that
* has an associated item.
*
* @returns the found item, or `undefined` if no item was found
*
* @example
* ```ts
* const trie = new LookupByPath([['foo', 1], ['foo/bar', 2]]);
* trie.findChildPathFromSegments(['foo', 'baz']); // returns 1
* trie.findChildPathFromSegments(['foo','bar', 'baz']); // returns 2
* ```
*/
findChildPathFromSegments(childPathSegments: Iterable<string>): TItem | undefined;
/**
* Groups the provided map of info by the nearest entry in the trie that contains the path. If the path
* is not found in the trie, the info is ignored.
*
* @returns The grouped info, grouped by the nearest entry in the trie that contains the path
*
* @param infoByPath - The info to be grouped, keyed by path
*/
groupByChild<TInfo>(infoByPath: Map<string, TInfo>): Map<TItem, Map<string, TInfo>>;
}
/**
* This class is used to associate path-like-strings, such as those returned by `git` commands,

@@ -48,3 +108,3 @@ * with entities that correspond with ancestor folders, such as Rush Projects or npm packages.

*/
export declare class LookupByPath<TItem> {
export declare class LookupByPath<TItem> implements IReadonlyLookupByPath<TItem> {
/**

@@ -90,51 +150,15 @@ * The delimiter used to split paths

/**
* Searches for the item associated with `childPath`, or the nearest ancestor of that path that
* has an associated item.
*
* @returns the found item, or `undefined` if no item was found
*
* @example
* ```ts
* const trie = new LookupByPath([['foo', 1], ['foo/bar', 2]]);
* trie.findChildPath('foo/baz'); // returns 1
* trie.findChildPath('foo/bar/baz'); // returns 2
* ```
* {@inheritdoc IReadonlyLookupByPath}
*/
findChildPath(childPath: string): TItem | undefined;
/**
* 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.
*
* @returns the found item and the length of the matched prefix, or `undefined` if no item was found
*
* @example
* ```ts
* const trie = new LookupByPath([['foo', 1], ['foo/bar', 2]]);
* trie.findLongestPrefixMatch('foo/baz'); // returns { item: 1, index: 3 }
* trie.findLongestPrefixMatch('foo/bar/baz'); // returns { item: 2, index: 7 }
* ```
* {@inheritdoc IReadonlyLookupByPath}
*/
findLongestPrefixMatch(query: string): IPrefixMatch<TItem> | undefined;
/**
* Searches for the item associated with `childPathSegments`, or the nearest ancestor of that path that
* has an associated item.
*
* @returns the found item, or `undefined` if no item was found
*
* @example
* ```ts
* const trie = new LookupByPath([['foo', 1], ['foo/bar', 2]]);
* trie.findChildPathFromSegments(['foo', 'baz']); // returns 1
* trie.findChildPathFromSegments(['foo','bar', 'baz']); // returns 2
* ```
* {@inheritdoc IReadonlyLookupByPath}
*/
findChildPathFromSegments(childPathSegments: Iterable<string>): TItem | undefined;
/**
* Groups the provided map of info by the nearest entry in the trie that contains the path. If the path
* is not found in the trie, the info is ignored.
*
* @returns The grouped info, grouped by the nearest entry in the trie that contains the path
*
* @param infoByPath - The info to be grouped, keyed by path
* {@inheritdoc IReadonlyLookupByPath}
*/

@@ -141,0 +165,0 @@ groupByChild<TInfo>(infoByPath: Map<string, TInfo>): Map<TItem, Map<string, TInfo>>;

@@ -8,5 +8,5 @@ // This file is read by tools that parse documentation comments conforming to the TSDoc standard.

"packageName": "@microsoft/api-extractor",
"packageVersion": "7.47.10"
"packageVersion": "7.47.11"
}
]
}

@@ -6,4 +6,4 @@ /**

*/
export type { IPrefixMatch } from './LookupByPath';
export type { IPrefixMatch, IReadonlyLookupByPath } from './LookupByPath';
export { LookupByPath } from './LookupByPath';
//# sourceMappingURL=index.d.ts.map

@@ -21,2 +21,61 @@ /**

/**
* The readonly component of `LookupByPath`, to simplify unit testing.
*
* @beta
*/
export interface IReadonlyLookupByPath<TItem> {
/**
* Searches for the item associated with `childPath`, or the nearest ancestor of that path that
* has an associated item.
*
* @returns the found item, or `undefined` if no item was found
*
* @example
* ```ts
* const trie = new LookupByPath([['foo', 1], ['foo/bar', 2]]);
* trie.findChildPath('foo/baz'); // returns 1
* trie.findChildPath('foo/bar/baz'); // returns 2
* ```
*/
findChildPath(childPath: string): TItem | undefined;
/**
* 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.
*
* @returns the found item and the length of the matched prefix, or `undefined` if no item was found
*
* @example
* ```ts
* const trie = new LookupByPath([['foo', 1], ['foo/bar', 2]]);
* trie.findLongestPrefixMatch('foo/baz'); // returns { item: 1, index: 3 }
* trie.findLongestPrefixMatch('foo/bar/baz'); // returns { item: 2, index: 7 }
* ```
*/
findLongestPrefixMatch(query: string): IPrefixMatch<TItem> | undefined;
/**
* Searches for the item associated with `childPathSegments`, or the nearest ancestor of that path that
* has an associated item.
*
* @returns the found item, or `undefined` if no item was found
*
* @example
* ```ts
* const trie = new LookupByPath([['foo', 1], ['foo/bar', 2]]);
* trie.findChildPathFromSegments(['foo', 'baz']); // returns 1
* trie.findChildPathFromSegments(['foo','bar', 'baz']); // returns 2
* ```
*/
findChildPathFromSegments(childPathSegments: Iterable<string>): TItem | undefined;
/**
* Groups the provided map of info by the nearest entry in the trie that contains the path. If the path
* is not found in the trie, the info is ignored.
*
* @returns The grouped info, grouped by the nearest entry in the trie that contains the path
*
* @param infoByPath - The info to be grouped, keyed by path
*/
groupByChild<TInfo>(infoByPath: Map<string, TInfo>): Map<TItem, Map<string, TInfo>>;
}
/**
* This class is used to associate path-like-strings, such as those returned by `git` commands,

@@ -41,3 +100,3 @@ * with entities that correspond with ancestor folders, such as Rush Projects or npm packages.

*/
export declare class LookupByPath<TItem> {
export declare class LookupByPath<TItem> implements IReadonlyLookupByPath<TItem> {
/**

@@ -83,51 +142,15 @@ * The delimiter used to split paths

/**
* Searches for the item associated with `childPath`, or the nearest ancestor of that path that
* has an associated item.
*
* @returns the found item, or `undefined` if no item was found
*
* @example
* ```ts
* const trie = new LookupByPath([['foo', 1], ['foo/bar', 2]]);
* trie.findChildPath('foo/baz'); // returns 1
* trie.findChildPath('foo/bar/baz'); // returns 2
* ```
* {@inheritdoc IReadonlyLookupByPath}
*/
findChildPath(childPath: string): TItem | undefined;
/**
* 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.
*
* @returns the found item and the length of the matched prefix, or `undefined` if no item was found
*
* @example
* ```ts
* const trie = new LookupByPath([['foo', 1], ['foo/bar', 2]]);
* trie.findLongestPrefixMatch('foo/baz'); // returns { item: 1, index: 3 }
* trie.findLongestPrefixMatch('foo/bar/baz'); // returns { item: 2, index: 7 }
* ```
* {@inheritdoc IReadonlyLookupByPath}
*/
findLongestPrefixMatch(query: string): IPrefixMatch<TItem> | undefined;
/**
* Searches for the item associated with `childPathSegments`, or the nearest ancestor of that path that
* has an associated item.
*
* @returns the found item, or `undefined` if no item was found
*
* @example
* ```ts
* const trie = new LookupByPath([['foo', 1], ['foo/bar', 2]]);
* trie.findChildPathFromSegments(['foo', 'baz']); // returns 1
* trie.findChildPathFromSegments(['foo','bar', 'baz']); // returns 2
* ```
* {@inheritdoc IReadonlyLookupByPath}
*/
findChildPathFromSegments(childPathSegments: Iterable<string>): TItem | undefined;
/**
* Groups the provided map of info by the nearest entry in the trie that contains the path. If the path
* is not found in the trie, the info is ignored.
*
* @returns The grouped info, grouped by the nearest entry in the trie that contains the path
*
* @param infoByPath - The info to be grouped, keyed by path
* {@inheritdoc IReadonlyLookupByPath}
*/

@@ -134,0 +157,0 @@ groupByChild<TInfo>(infoByPath: Map<string, TInfo>): Map<TItem, Map<string, TInfo>>;

@@ -115,13 +115,3 @@ "use strict";

/**
* Searches for the item associated with `childPath`, or the nearest ancestor of that path that
* has an associated item.
*
* @returns the found item, or `undefined` if no item was found
*
* @example
* ```ts
* const trie = new LookupByPath([['foo', 1], ['foo/bar', 2]]);
* trie.findChildPath('foo/baz'); // returns 1
* trie.findChildPath('foo/bar/baz'); // returns 2
* ```
* {@inheritdoc IReadonlyLookupByPath}
*/

@@ -132,14 +122,3 @@ findChildPath(childPath) {

/**
* 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.
*
* @returns the found item and the length of the matched prefix, or `undefined` if no item was found
*
* @example
* ```ts
* const trie = new LookupByPath([['foo', 1], ['foo/bar', 2]]);
* trie.findLongestPrefixMatch('foo/baz'); // returns { item: 1, index: 3 }
* trie.findLongestPrefixMatch('foo/bar/baz'); // returns { item: 2, index: 7 }
* ```
* {@inheritdoc IReadonlyLookupByPath}
*/

@@ -150,13 +129,3 @@ findLongestPrefixMatch(query) {

/**
* Searches for the item associated with `childPathSegments`, or the nearest ancestor of that path that
* has an associated item.
*
* @returns the found item, or `undefined` if no item was found
*
* @example
* ```ts
* const trie = new LookupByPath([['foo', 1], ['foo/bar', 2]]);
* trie.findChildPathFromSegments(['foo', 'baz']); // returns 1
* trie.findChildPathFromSegments(['foo','bar', 'baz']); // returns 2
* ```
* {@inheritdoc IReadonlyLookupByPath}
*/

@@ -184,8 +153,3 @@ findChildPathFromSegments(childPathSegments) {

/**
* Groups the provided map of info by the nearest entry in the trie that contains the path. If the path
* is not found in the trie, the info is ignored.
*
* @returns The grouped info, grouped by the nearest entry in the trie that contains the path
*
* @param infoByPath - The info to be grouped, keyed by path
* {@inheritdoc IReadonlyLookupByPath}
*/

@@ -192,0 +156,0 @@ groupByChild(infoByPath) {

{
"name": "@rushstack/lookup-by-path",
"version": "0.3.2",
"version": "0.4.0",
"description": "Strongly typed trie data structure for path and URL-like strings.",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc