Dav*_*ith 18 node.js gulp gulp-spellcheck
我想把我的拼写检查结果输出到控制台而不是文件,我认为这应该有效,因为据我了解它gulp返回一个流.
相反,我得到一个错误:
TypeError: Object #<Stream> has no method 'read'
Run Code Online (Sandbox Code Playgroud)
这是我的代码
gulp.task('spellcheck', function() {
var patterns = [{
// Strip tags from HTML
pattern: /(<([^>]+)>)/ig,
replacement: ''
}];
var spellSuggestions = [{
pattern: / [^ ]+? \(suggestions:[A-z, ']+\)/g,
replacement: function(match) {
return '<<<' + match + '>>>';
}
}];
var nonSuggestions = [{
pattern: /<<<.+>>>|([^\s]+[^<]+)/g,
replacement: function(match) {
if (match.indexOf('<') == 0) {
return '\n' + match + '\n';
}
return '';
}
}];
var toConsole = gulp.src('./_site/**/*.html')
.pipe(frep(patterns))
.pipe(spellcheck())
.pipe(frep((spellSuggestions)))
.pipe(frep((nonSuggestions)));
var b = toConsole.read();
console.log(b);
});
Run Code Online (Sandbox Code Playgroud)
leo*_*ion 31
流上没有读取方法.你有两个选择:
在代码中实现:
gulp.task('spellcheck', function () {
var patterns = [
{
// Strip tags from HTML
pattern: /(<([^>]+)>)/ig,
replacement: ''
}];
var nonSuggestions = [
{
pattern: /<<<.+>>>|([^\s]+[^<]+)/g,
replacement: function(match) {
if (match.indexOf('<')==0) {
return '\n' + match +'\n';
}
return '';
}
}];
var a = gulp.src('./_site/**/*.html')
.pipe(frep(patterns))
.pipe(spellcheck(({replacement: '<<<%s (suggestions: %s)>>>'})))
.pipe(frep(nonSuggestions))
;
a.on('data', function(chunk) {
var contents = chunk.contents.toString().trim();
var bufLength = process.stdout.columns;
var hr = '\n\n' + Array(bufLength).join("_") + '\n\n'
if (contents.length > 1) {
process.stdout.write(chunk.path + '\n' + contents + '\n');
process.stdout.write(chunk.path + hr);
}
});
});
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
43872 次 |
最近记录: |