UNPKG

@siren-js/client

Version:
38 lines (37 loc) 1.12 kB
import { Link } from '../models'; import { DefaultSirenElementVisitor } from './default-siren-element-visitor'; /** * Collects visited links that satisfy {@linkcode predicate} * * @example * const itemLinkFinder = new LinkFinder((link) => link.rel.includes('item')); * * await entity.accept(itemLinkFinder); * * if (!itemLinkFinder.isEmpty) { * const firstItemLink = itemLinkFinder.links[0]; * entity = await follow(firstItemLink).then(parse); * } * * // reset the link finder and do it again * itemLinkFinder.reset(); * await entity.accept(itemLinkFinder); */ export declare class LinkFinder extends DefaultSirenElementVisitor { private predicate; private _links; constructor(predicate: (link: Link) => boolean); /** * Indicates whether any visited links have satisfied {@linkcode predicate} */ get isEmpty(): boolean; /** * List of visited links that have satisfied {@linkcode predicate} */ get links(): readonly Link[]; /** * Resets this visitor, forgetting all visited links */ reset(): void; visitLink(link: Link): void; }