Angular Modernizer
    Preparing search index...

    Searches source files in a ts-morph Project by text, regex, or symbol name, using three modes:

    • text - literal string search (case-sensitive substring)
    • pattern - regular-expression search
    • symbol - TypeScript declaration search (class, function, interface, enum, type alias, variable)

    The project must already have the relevant source files added before calling CodebaseSearcher.search. For symbol mode only top-level named declarations are indexed; local variables and anonymous expressions are not returned.

    When rootDir is given, text and pattern modes additionally scan files under that directory which are not part of the ts-morph program: Angular templates (.html) and .ts files outside the tsconfig (for example src/i18n/*.ts). node_modules, dist, .angular, coverage, out-tsc and hidden directories are skipped. Use CodebaseSearcher.searchWithCoverage to learn how many files were actually searched.

    const searcher = new CodebaseSearcher(project);

    // Text search
    const hits = searcher.search('TODO:', { mode: 'text' });

    // Regex search
    const selectors = searcher.search('selector:\\s*["\']([^"\']+)["\']', { mode: 'pattern' });

    // Symbol search
    const classes = searcher.search('UserService', { mode: 'symbol' });
    Index

    Constructors

    Methods

    • Search for query across all (filtered) source files.

      Parameters

      • query: string

        The text, regex pattern, or symbol name to find.

      • options: SearchOptions

        Search mode and optional file filter / result limit.

      Returns SearchResult[]

      Array of SearchResult objects ordered by file then line.

      searcher.search('UserService', { mode: 'symbol' });
      searcher.search('TODO', { mode: 'text', include: 'src/**/*.ts' });
    • Like search, but also reports which files were covered. Callers should surface coverage whenever a search returns 0 hits: an empty result only proves absence within the covered files.

      Parameters

      Returns SearchWithCoverageResult

      const { results, coverage } = searcher.searchWithCoverage('i18n.key', {
      mode: 'text',
      rootDir: '/project',
      });
      // coverage.programFileCount, coverage.extraFileCount