INNER CODE UNIT · TypeScript
addParamterToMethod
maciejtreder/ng-toolkit · schematics/_utils/index.ts:292
export function addParamterToMethod(tree: Tree, filePath: string, name: string, parameterDeclaration: string): void {
let method = getMethod(tree, filePath, name);
const fileContent = getFileContent(tree, filePath);
if (method) {
let results: any = method.match(new RegExp("(?:public|private|\\s).*" + name + "[\\s\\S]*?(\([\\s\\S]*?\)[\\s\\S]*?{)"));
if (results) {
let oldParams = results[1];
oldParams = oldParams.substring(1, oldParams.lastIndexOf(")"));
if (oldParams.indexOf(parameterDeclaration) > 0) {
return;
}
let newParams = parameterDeclaration + ", " + oldParams;
let newMethod = method.replace(oldParams, newParams);
tree.overwrite(filePath, fileContent.replace(method, newMethod));
}
}