UNPKG

@loken/hierarchies

Version:

Library for working with hierarchies of identifiers and identifiable objects.

38 lines 1.9 kB
import type { Identify } from '../utilities/identify.js'; import type { IdSpec, ItemIdOptions } from '../utilities/identity-options.js'; import { Hierarchy } from './hierarchy.js'; /** * Convenience functions for creating and mapping `Hierarchy` instances. */ export declare class Hierarchies { /** Create a hierarchy of `Id`s. */ static createForIds<Id>(): Hierarchy<Id>; /** Create a hierarchy of `Item`s using the provided identify function. */ static createForItems<Item, Id>(identify: Identify<Item, Id>): Hierarchy<Item, Id>; /** * Create a hierarchy of `Id`s matching the `spec`. * * @param spec Specification of how to create an `Id` hierarchy from a list of relations, a multi-map of `Id`s or a hierarchy. */ static createWithIds<Id>(spec: IdSpec<Id>): Hierarchy<Id>; /** * Create a hierarchy of `Id`s matching the properties of the `source`. * * @param source The object describing the relations. * @param include Optional predicate used for determining whether a property should be included as an ID. */ static createWithPropertyIds(source: object, include?: (prop: string, val: any) => boolean): Hierarchy<string>; /** * Create a hierarchy of `Item`s matching details from the `options`. * * @template Item The type of item. * @template Id The type of IDs. * @param items The items to wrap in nodes. * @param identify Means of getting an ID for an item. * @param options Options with details on how to create an `Item` hierarchy from a list of relations, a multi-map of `Id`s, * a hierarchy or functions for inferring the relations from each item. * @returns The fully linked `Hierarchy<Item, Id>`. */ static createWithItems<Item, Id>(options: ItemIdOptions<Item, Id>): Hierarchy<Item, Id>; } //# sourceMappingURL=hierarchies.d.ts.map