Replace find helper method with string.match
This commit is contained in:
Родитель
50c1a7787f
Коммит
0d7e2dc51f
|
@ -18,25 +18,6 @@ var logError = function(pluginName, file, message) {
|
|||
gutil.log(`[${gutil.colors.cyan(pluginName)}] ${gutil.colors.red("error")} ${sourcePath}: ${message}`);
|
||||
};
|
||||
|
||||
/**
|
||||
* Helper function to return a list of all matches for a given pattern
|
||||
* @param {string|RegExp} pattern The pattern to match against
|
||||
* @param {string} text The text to search
|
||||
* @returns {string[]} An array of matches
|
||||
*/
|
||||
var find = function(pattern, text) {
|
||||
var results = [];
|
||||
if (pattern.hasOwnProperty("source")) {
|
||||
pattern = new RegExp(pattern.source, "g");
|
||||
}
|
||||
|
||||
text.toString().replace(pattern, function(match) {
|
||||
results.push(match);
|
||||
});
|
||||
|
||||
return results;
|
||||
};
|
||||
|
||||
/**
|
||||
* Plugin to verify the Microsoft copyright notice is present
|
||||
*/
|
||||
|
@ -80,7 +61,7 @@ var checkImports = function() {
|
|||
return through.obj(function(file, encoding, callback) {
|
||||
if (file.isBuffer() && !file.path.endsWith(".d.ts")) {
|
||||
var fileContents = file.contents.toString(encoding);
|
||||
var importStatements = find(re, fileContents);
|
||||
var importStatements = fileContents.match(new RegExp(re.source, "g")) || [];
|
||||
var workingDirectory = path.dirname(file.path);
|
||||
|
||||
importStatements.forEach(function(importStatement) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче