miniwrite
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; // write plain text linemw;
Helpers
Buffer writes:
// buffer own linesvar mw = miniwrite;// buffer other writes (handy for testing)var mw = miniwrite; // get buffervar str = mw;var str = mw;// iterate buffer if you mustmwlines// clear buffermwclear;
Adapter to buffer character writes via mw.write(chars)
, auto-flushes on newlines:
var mw = miniwrite; // write plain text linemw;mw;mw; // "hello world\n" //or accumulate charsmw;mw;mw; // onetwo // clear buffermw;mwclear;mw;mw; // two
Spread of multiple writers
var mw = miniwrite;mwenabled = true;mwtargets;
Proxy to toggle stream or swap output target:
var mw = miniwrite;mwenabled = true;mwtarget = myOherWrite;mw { // return string, or false to ignore});
Proxy to toggle stream or swap output target:
var mw = miniwrite;mwenabled = true;mwtarget = myOherWrite;mwtarget = myOherWrite;
Convenience preset for grunt (same as in grunt ~0.4.1
):
var mw = miniwrite;
Examples
Build your own:
var mw = {};mw { myWebSocketHyperStream};// pass to supporting toolsawesomeModule;
Tap into output
awesomeModulewriter = miniwrite;
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.