Minimal semantic output writer

Downloads in past


130.1.49 years ago10 years agoMinified + gzip package size for miniwrite in KB


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


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


Buffer writes: ````js // 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: ````js 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 ````js var mw = miniwrite.multi(myANSIConsole, myRemoteSocket, myDiskLogger); mw.enabled = true; mw.targets.forEach(function(subw, num) {
// .. 
}); ```` Proxy to toggle stream or swap output target: ````js 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: ````js var mw = miniwrite.proxy(myMiniWrite); mw.enabled = true; = myOherWrite; = myOherWrite; ```` Convenience preset for grunt (same as in grunt ~0.4.1): ````js var mw = miniwrite.grunt(grunt); ````


Build your own: ````js var mw = {}; mw.writeln = function(line) {
myWebSocketHyperStream.send({line: line})
}; // pass to supporting tools awesomeModule.useMiniWritePlz(mw); ```` Tap into output ````js awesomeModule.writer = miniwrite.splitter(awesomeModule.writer, myMiniWrite); ````


```shell $ npm install miniwrite --save ```


  • 0.1.2 - Enabled strict mode, split in internal modules
  • 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.