stream-line-wrapper
Wrap each lines of a stream with a prefix, suffix or a custom function.
Last updated 12 years ago by neoziro .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install stream-line-wrapper 
SYNC missed versions from official npm registry.

Stream line wrapper Build Status

Wrap each lines of a stream with a prefix, suffix or a custom function.

Usage

var childProcess = require('child_process');
var LineWrapper = require('stream-line-wrapper');
var ls = childProcess.exec('ls');

var lineWrapper = new LineWrapper({ prefix: '-- ' });
ls.stdout.pipe(lineWrapper).pipe(process.stdout);

// -- file1.js
// -- file2.js
// -- file3.js

Options

prefix

Prefix each lines with a string.

var lineWrapper = new LineWrapper({ prefix: '-- ' });
ls.stdout.pipe(lineWrapper).pipe(process.stdout);

// -- file1.js

suffix

Suffix each lines with a string.

var lineWrapper = new LineWrapper({ suffix: ' @' });
ls.stdout.pipe(lineWrapper).pipe(process.stdout);

// file1.js @

wrapper

Use a function to wrapper each lines.

var lineWrapper = new LineWrapper({ wrapper: countChars });

/**
 * Prefix each lines with char count.
 *
 * @param {String} line
 * @param {Function} cb
 */

function countChars(line, cb) {
  return cb(null, '(' + line.length + ') ' + line);
}

ls.stdout.pipe(lineWrapper).pipe(process.stdout);

// (8) file1.js

License

MIT

Current Tags

  • 0.1.1                                ...           latest (12 years ago)

2 Versions

  • 0.1.1                                ...           12 years ago
  • 0.1.0                                ...           12 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (1)
Dev Dependencies (2)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |