Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 如何将吞咽结果输出到控制台?_Node.js_Gulp_Gulp Spellcheck - Fatal编程技术网

Node.js 如何将吞咽结果输出到控制台?

Node.js 如何将吞咽结果输出到控制台?,node.js,gulp,gulp-spellcheck,Node.js,Gulp,Gulp Spellcheck,我想把我的拼写检查结果放在控制台上,而不是放在一个文件上,我认为这应该是可行的,因为据我所知,gulp返回一个流 相反,我得到了一个错误: TypeError: Object #<Stream> has no method 'read' TypeError:对象#没有方法“read” 这是我的密码 gulp.task('spellcheck', function() { var patterns = [{ // Strip tags from HTML pat

我想把我的拼写检查结果放在控制台上,而不是放在一个文件上,我认为这应该是可行的,因为据我所知,gulp返回一个流

相反,我得到了一个错误:

TypeError: Object #<Stream> has no method 'read'
TypeError:对象#没有方法“read”
这是我的密码

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);
});
gulp.task('拼写检查',函数(){
变量模式=[{
//从HTML中剥离标记
模式:/(]+)>)/ig,
替换:“”
}];
var=[{
模式:/[^]+?\(建议:[A-z,]+\)/g,
替换:功能(匹配){
返回“”;
}
}];
var非建议=[{

模式:/|([^\s]+[^流上没有读取方法。您有两种选择:

  • 使用实际控制台流:
  • 使用to console.log
  • 在代码中实现:

     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);
            }
        });
    });
    
    gulp.task('拼写检查',函数(){
    变量模式=[
    {
    //从HTML中剥离标记
    模式:/(]+)>)/ig,
    替换:“”
    }];
    var非建议=[
    {
    模式:/|([^\s]+[^1){
    process.stdout.write(chunk.path+'\n'+contents+'\n');
    process.stdout.write(chunk.path+hr);
    }
    });
    });
    
    像这样修改了我的代码:
    process.stdout.write(a++'\n');
    它输出
    [object object]
    David Silva Smith,do
    process.stdout.write(JSON.stringify(a)+'\n')
    或者只是
    process.stdout.write(a)
    不需要新行。这在很多情况下都很有用,有些人想知道发生了什么(特别是:错误)在任何一个巨大的链式吞气管中。。。