INNER CODE UNIT · TypeScript
implementInterface
maciejtreder/ng-toolkit · schematics/_utils/index.ts:107
export function implementInterface(tree: Tree, filePath: string, interfaceName: string, fileName: string): void {
let results: any = getFileContent(tree, filePath).match(new RegExp("(.*class)\\s*(.*?)\\s*(:?implements\\s*(.*)|){"));
if (results) {
const oldClassDeclaration = results[0];
let interfaces = results[5] || '';
if (interfaces.indexOf(interfaceName) == -1) {
addImportStatement(tree, filePath, interfaceName, fileName);
if (interfaces.length > 0) {
interfaces += ',';
}
interfaces += interfaceName;
const newClassDeclaration = `${results[1]} ${results[2]} implements ${interfaces} {`
tree.overwrite(filePath, getFileContent(tree, filePath).replace(oldClassDeclaration, newClassDeclaration));
}
}
}