through.obj(function(file, enc, next) { if (file.isNull() || file.isDirectory()) { next(null, file); return; } if (file.extname !== '.md' && path.extname(file.history[0]) !== '.md') { next(null, file); return; } try { let md = new Remarkable(opts); file.contents = Buffer.from(md.render(file.contents.toString())); file.extname = '.html'; } catch (err) { this.emit('error', new PluginError('remarkable', err, { fileName: file.path })); return; } next(null, file); })
through.obj(function(file, enc, next) { if (file.isNull() || file.isDirectory()) { next(null, file); return; } if (file.extname !== '.md' && path.extname(file.history[0]) !== '.md') { next(null, file); return; } try { let str = file.contents.toString(); str = str.replace(/(\{{2,4})([^}]+)(\}{2,4})/g, (m, open, inner, close) => { return open + unescape(inner) + close; }); file.contents = Buffer.from(str); } catch (err) { this.emit('error', new PluginError('unescape', err, { fileName: file.path })); return; } next(null, file); })
app.task('default', ['readme'], function(cb) { return app.src('README.md') .pipe(through.obj(function(file, enc, next) { var str = file.contents.toString(); str = str.replace(/^(#+ \[)#/gm, '$1Base.'); file.contents = new Buffer(str); next(null, file); })) .pipe(app.dest('.')); });
through(function(buf, enc, next) { this.push( buf.toString('utf-8') .replace(regex, '') ); next(); })
// TODO: empty before? // TODO: use batched writestream // TODO: emit warning if pre hook is called during rebuild this.parent.createReadStream().pipe(through2(function(kv, _, next){ var ops = [], add = ops.push.bind(ops) index.update(kv.key, kv.value, add) return ops.length ? index.db.batch(ops, next) : next() })).on('finish', done).on('error', done)
process.stdin .pipe(split()) .pipe(through(function (line, _, next) { this.push(lineNumber % 2 === 0 ? line.toString().toUpperCase()+'\n' : line.toString().toLowerCase()+'\n' ) lineNumber++ next() })) .pipe(process.stdout)
function concat(stream, cb) { var acc = [] return stream.once('error', done) .pipe(through2.obj(function(o, _, next){ acc.push(o) next(null, o) })).on('finish', done).once('error', done) function done(err) { cb && cb(err, acc, stream.plan) cb = null } }
through.obj(function(file, enc, next) { if (file.isNull() || file.isStream()) { next(null, file); return; } var str = file.contents.toString(); str = restore(str, file, 'gfm'); str = restore(str, file, 'tables'); str = str.replace(/\| {2}`/g, '| `'); file.contents = Buffer.from(str); next(null, file); })
through.obj(function(file, enc, next) { if (file.isNull() || file.isDirectory()) { next(null, file); return; } if (file.extname !== '.md' && path.extname(file.history[0]) !== '.md') { next(null, file); return; } try { let md = new Remarkable(opts); file.contents = Buffer.from(md.render(file.contents.toString())); file.extname = '.html'; } catch (err) { this.emit('error', new PluginError('remarkable', err, { fileName: file.path })); return; } next(null, file); })
through.obj(function(file, enc, next) { if (file.isNull() || file.isDirectory()) { next(null, file); return; } if (file.extname !== '.md' && path.extname(file.history[0]) !== '.md') { next(null, file); return; } try { let str = file.contents.toString(); str = str.replace(/(\{{2,4})([^}]+)(\}{2,4})/g, (m, open, inner, close) => { return open + unescape(inner) + close; }); file.contents = Buffer.from(str); } catch (err) { this.emit('error', new PluginError('unescape', err, { fileName: file.path })); return; } next(null, file); })