UNPKG

cannabis

Version:
67 lines (66 loc) 2.25 kB
import { Options as MicroMatchOptions } from 'micromatch'; import { ASTNode } from './node/astNode'; interface MatchStringOptions { /** * The patterns input paths match. Example: `'** /*method*1* /** /*Statement* /** /push']` */ include: string[]; /** * Exclude nodes matchint this pattern */ exclude?: string[]; /** * internally it uses micromatch library so options can be also given using this param. * See https://github.com/micromatch/nanomatch#options */ micromatch?: MicroMatchOptions; } interface Source<T> { path: string; data: T; } export declare function searchSource<T>(p: Source<T>[], options?: MatchStringOptions): Source<T>[]; interface MatchNodeOptions extends MatchStringOptions { /** * By default `/` */ levelSeparator?: string; /** * The node from which search in the AST.By default it search on its ascendants including it. */ root: ASTNode; /** * The path mode to build for input nodes. Alternative [[pathCreator]] function can be pass to build a custom path. */ path?: 'index' | 'kind' | 'name'; /** * Function to build a custom path. It must return a single node representation in the path (not all the * path). This way custom semantics for queries is supported. Remember that performance is important and the * function call runs a lot of times and probably for the same input. Tip: memoize / cache. * * Example: n=>isExportedDescendant(n) ? 'exported' : isDeclaration(n) ? 'declaration' : 'isTypeOnly(n) ? : * 'type' : 'other' */ pathBuilder?: (n: ASTNode) => 'string'; /** * Defines from given root node, which nodes take as input of the query. By default will be its decendants. */ selectNodeDirection?: SelectNodeDirection; } interface SelectNodeDirection { ancestors?: boolean; descendants?: boolean; children?: boolean; siblings?: boolean; } interface Result { /** * When true means all the input paths were filtered. */ searchFinished?: boolean; timingSafeEqual?: { total: number; }; result: Source<ASTNode>[]; } export declare function queryByPath(o: MatchNodeOptions): Result; export {};