@rxap/ts-morph
Version:
Provides utilities for manipulating TypeScript code using the ts-morph library. It offers a fluent API to add, modify, and remove code elements such as classes, decorators, imports, and properties in both Angular and NestJS projects. This package simplifi
25 lines • 989 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.GetClass = GetClass;
const find_function_1 = require("./find-function");
function GetClass(sourceFile, nameOrFindFunction) {
if (nameOrFindFunction) {
let findFunction;
if (typeof nameOrFindFunction === 'string') {
findFunction = (0, find_function_1.FindByNameFunction)({ name: nameOrFindFunction });
}
else {
findFunction = nameOrFindFunction;
}
return sourceFile.getClassOrThrow(findFunction);
}
const classDeclarationList = sourceFile.getClasses();
if (classDeclarationList.length === 0) {
throw new Error(`No class declaration found in file: ${sourceFile.getFilePath()}`);
}
if (classDeclarationList.length !== 1) {
throw new Error(`Multiple class declarations found in file: ${sourceFile.getFilePath()}`);
}
return classDeclarationList[0];
}
//# sourceMappingURL=get-class.js.map