Skip to content

Bartvds/miniwrite

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

miniwrite

Build Status Dependency Status NPM version

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).

API

Main usage:

// simplified node.js.browser compatible console.log()
var mw = miniwrite.console();

// write plain text line
mw.writeln('hello world!');

Helpers

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
mw.clear();

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('hello');
mw.write(' ');
mw.writeln('world!'); // "hello world\n"

//or accumulate chars
mw.write('one');
mw.write('two');
mw.flush(true); // onetwo

// clear buffer
mw.write('one');
mw.clear();
mw.write('two');
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;
mw.target = 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;
mw.target = myOherWrite;
mw.target = myOherWrite;

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

var mw = miniwrite.grunt(grunt);

Examples

Build your own:

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

Tap into output

awesomeModule.writer = miniwrite.splitter([awesomeModule.writer, myMiniWrite]);

Installation

$ npm install miniwrite --save

History

  • 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

Build

Install development dependencies in your git checkout:

$ npm install

~Build and run tests:

$ grunt

See the Gruntfile.js for additional commands.

Contributing

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.

License

Copyright (c) 2013 Bart van der Schoor

Licensed under the MIT license.

About

Minimal semantic output styler/writer

Resources

License

Stars

Watchers

Forks

Packages

No packages published