Every line of 'remove function in javascript' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.
37 export function removeTemplateInformation(functionName: string) { 38 let result = ''; 39 let depth = 0; 40 let start = 0; // Start of a segment we'd like to keep 41 // We start the loop at i = 1 because we don't want to extract any 42 // template-like information starting at the beginning of the string: 43 // templates can't occur before the name of a function, so this is certainly 44 // an HTML tag like <script>. 45 for (let i = 1; i < functionName.length; i++) { 46 // We also don't want to extract template-like information that start after 47 // a space, as that won't likely be a real template information and 48 // probably rather an HTML tag name. 49 if (functionName[i] === '<' && functionName[i - 1] !== ' ') { 50 if (depth === 0) { 51 // Template information begins, save segment 52 result += functionName.substr(start, i - start); 53 // Start a new segment here to not lose the rest of the string 54 // should we find no matching '>' 55 start = i; 56 } 57 depth++; 58 } else if (functionName[i] === '>') { 59 depth--; 60 if (depth === 0) { 61 // Template information ends, start of new segment 62 start = i + 1; 63 } 64 } 65 } 66 result += functionName.substr(start); 67 return result; 68 }
Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code