Every line of 'regex all symbols' 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.
84 function filterSymbols(patterns, symbols, callback) { 85 let matches = []; 86 87 let lookup = {}; 88 symbols.forEach(function(symbol) { 89 lookup[symbol.name] = symbol; 90 }); 91 92 patterns.forEach(function(name) { 93 let match = false; 94 let pattern = (name.substr(-1) === '*'); 95 if (pattern) { 96 name = name.substr(0, name.length - 1); 97 symbols.forEach(function(symbol) { 98 if (symbol.name.indexOf(name) === 0) { 99 matches.push(symbol); 100 match = true; 101 } 102 }); 103 } else { 104 let symbol = lookup[name]; 105 if (symbol) { 106 matches.push(symbol); 107 match = true; 108 } 109 } 110 if (!match) { 111 let message = 'No matching symbol found: ' + name + (pattern ? '*' : ''); 112 callback(new Error(message)); 113 } 114 }); 115 116 callback(null, matches); 117 }