node package manager


Minimal semantic output writer


Minimal output-stream writer API.

A pluggable output writer interface/adapter to embed/expose in tools and reporters, also a simplified stream.

This is not a logging framework or full console or stream replacement. Instead this is an abstraction to build on or expose in other tools. Intend as companion to ministyle (et al).

Main usage:

// simplified node.js.browser compatible console.log() 
var mw = miniwrite.console();
// write plain text line 
mw.writeln('hello world!');

Buffer writes:

// buffer own lines 
var mw = miniwrite.buffer();
// buffer other writes (handy for testing) 
var mw = miniwrite.buffer(myMiniWrite);
// get buffer 
var str = mw.concat();
var str = mw.concat('\n\n', '\t');
// iterate buffer if you must 
mw.lines.forEach(function(line) {
// clear buffer 

Adapter to buffer character writes via mw.write(chars), auto-flushes on newlines:

var mw = miniwrite.chars(miniwrite.console());
// write plain text line 
mw.write(' ');
mw.writeln('world!'); // "hello world\n" 
//or accumulate chars 
mw.flush(true); // onetwo 
// clear buffer 
mw.flush(true); // two 

Spread of multiple writers

var mw = miniwrite.multi([myANSIConsole, myRemoteSocket, myDiskLogger]);
mw.enabled = true;
mw.targets.forEach(function(subw, num) {
    // ..  

Proxy to toggle stream or swap output target:

var mw = miniwrite.peek(myMiniWrite, callback);
mw.enabled = true; = myOherWrite;
mw.callback = function(line) {
    // return string, or false to ignore 

Proxy to toggle stream or swap output target:

var mw = miniwrite.proxy(myMiniWrite);
mw.enabled = true; = myOherWrite; = myOherWrite;

Convenience preset for grunt (same as in grunt ~0.4.1):

var mw = miniwrite.grunt(grunt);

Build your own:

var mw = {};
mw.writeln = function(line) {
    myWebSocketHyperStream.send({line: line})
// pass to supporting tools 

Tap into output

awesomeModule.writer = miniwrite.splitter([awesomeModule.writer, myMiniWrite]);
$ npm install miniwrite --save
  • 0.1.2 - Enabled strict mode, split in internal modules
  • 0.1.0 - Extracted styling to ministyle.
  • 0.0.1 - Extracted code from existing projects

Install development dependencies in your git checkout:

$ npm install

~Build and run tests:

$ grunt

See the Gruntfile.js for additional commands.

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.

Note: this is an opinionated module: please create a ticket to discuss any big ideas. Pull requests for bug fixes are of course always welcome.

Copyright (c) 2013 Bart van der Schoor

Licensed under the MIT license.