Skip to main content

getClassesInFile

codebolt.codeparsers.getClassesInFile(file: string): Array<ClassInfo>
Retrieves all classes found in a given file. Supports JavaScript, TypeScript, and Python files.

Parameters

NameTypeDescription
filestringThe file path to parse for classes.

Description

The getClassesInFile function parses a source code file and extracts information about all classes defined within it. This function supports multiple programming languages including JavaScript, TypeScript, and Python.

Usage

const result = await codebolt.codeparsers.getClassesInFile(filePath);

Examples

// For a JavaScript file containing:
// class Calculator {
// add(a, b) { return a + b; }
// multiply(a, b) { return a * b; }
// }

const jsResult = await codebolt.codeparsers.getClassesInFile('test.js');
console.log(jsResult);
// Output:
// [
// {
// name: 'Calculator',
// location: 'C:\\path\\to\\file\\test.js'
// }
// ]

Response Format

The function returns an array of objects, where each object represents a class found in the file:

[
{
name: 'Calculator',
location: 'C:\\path\\to\\file\\test.js'
},
{
name: 'UserService',
location: 'C:\\path\\to\\file\\test.ts'
}
]

Response Properties

  • name (string): The name of the class
  • location (string): The absolute file path where the class is defined

Supported File Types

  • JavaScript (.js)
  • TypeScript (.ts)
  • Python (.py)

Error Handling

If the file doesn't exist or is not supported, the function will return an appropriate error response. Always handle potential errors when using this function.