0
使用Gulp我需要搜索我的文件的字符串,并找到该字符串时记录到控制台。吞咽每个错误
当我搜索每个文件中存在的字符串时,以下方法可用。
function logMatches(regex) {
return map(function(file, done) {
file.contents.toString().match(regex).forEach(function(match) {
console.log(match);
});
done(null, file);
});
}
var search = function() {
return gulp.src(myfiles)
.pipe(logMatches(/string to search for/g));
},
然而,如果在每一个文件中的字符串心不是那么我得到的错误:
TypeError: Cannot read property 'forEach' of null
我知道有从正则表达式匹配的结果,因为他们正在登录到控制台(错误之前) 。
那是'map'功能从一个众所周知的图书馆吗?另外,你能指定一些输入和预期结果吗? –