CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-ts-api-utils

Utility functions for working with TypeScript's API, providing comprehensive tools for analyzing and manipulating TypeScript AST nodes, types, and compiler APIs.

79

1.97x
Overview
Eval results
Files

task.mdevals/scenario-2/

Comment Analyzer

A TypeScript tool that analyzes comments in TypeScript source code files and provides statistics and content extraction capabilities.

Capabilities

Extract all comments from source code

  • When given a TypeScript source file, the analyzer extracts all comments (both single-line and multi-line) and returns them as an array of strings @test
  • Empty source files return an empty array of comments @test

Count comments by type

  • The analyzer counts single-line comments separately from multi-line comments @test
  • The result includes both singleLine and multiLine counts @test

Generate comment statistics

  • The analyzer provides a summary including total comment count, total character count across all comments, and average comment length @test
  • For files with no comments, statistics return zero values @test

Implementation

@generates

API

/**
 * Extracts all comments from a TypeScript source file.
 *
 * @param sourceCode - The TypeScript source code as a string
 * @returns An array of comment text content (without comment delimiters)
 */
export function extractComments(sourceCode: string): string[];

/**
 * Counts comments by type in a TypeScript source file.
 *
 * @param sourceCode - The TypeScript source code as a string
 * @returns An object with singleLine and multiLine counts
 */
export function countCommentsByType(sourceCode: string): {
  singleLine: number;
  multiLine: number;
};

/**
 * Generates statistics about comments in a TypeScript source file.
 *
 * @param sourceCode - The TypeScript source code as a string
 * @returns An object with total count, total characters, and average length
 */
export function getCommentStatistics(sourceCode: string): {
  totalComments: number;
  totalCharacters: number;
  averageLength: number;
};

Dependencies { .dependencies }

ts-api-utils { .dependency }

Provides utilities for working with TypeScript's Compiler API, including comment extraction capabilities.

typescript { .dependency }

Provides the TypeScript compiler API for parsing and analyzing TypeScript code.

Install with Tessl CLI

npx tessl i tessl/npm-ts-api-utils

tile.json