toString
Transform stream which converts each datum to a string.
DEPRECATED: use flow-tostring.
Installation
$ npm install flow-tostring
For use in the browser, use browserify.
Usage
To use the module,
var toString = ;
toString( [options] )
Returns a transform stream
where each chunk
is converted to a string
. To create a new stream,
var stream = ;
The default options are as follows:
highWaterMark=16
encoding=null
allowHalfOpen=true
objectMode=false
decodeStrings=true
To set the options
when creating a stream,
var opts ='encoding': 'utf8''highWaterMark': 8'allowHalfOpen': false'objectMode': true'decodeStrings': false;stream = ;
toString.factory( [options] )
Returns a reusable stream factory. The factory method ensures streams are configured identically by using the same set of provided options
.
var opts ='encoding': 'utf8''highWaterMark': 8'allowHalfOpen': false'objectMode': true'decodeStrings': false;var factory = toString;var streams = 10 ;// Create many streams configured identically but may each be independently written to...for var i = 0; i < streamslength; i++streams i = ;
toString.objectMode( [options] )
This method is a convenience function to create transform streams which always operate in objectMode
. The method will always override the objectMode
option in options
.
var fromArray toString;fromArray = objectMode;toString = objectMode;;
Examples
var toString =append = objectModefromArray = ;// Create some data...var data = 1000 ;for var i = 0; i < datalength; i++data i = Math;// Create a readable stream:var readableStream = ;// Pipe the data:readableStream;
To run the example code from the top-level application directory,
$ node ./examples/index.js
Notes
The output (readable) stream always operates in 'objectMode'.
When in objectMode
, anything which is not a buffer
or a string
is coerced into being a string
. Values are stringified according to the following conventions:
undefined
:"undefined"
number
:<number>.toString()
boolean
:<boolean>.toString()
function
:<function>.toString()
array
:JSON.stringify( <array> )
object
:JSON.stringify( <object> )
The only value which cannot be converted to a string
is null
due to the special status null
has in Node.js streams.
With the exception of arrays
and objects
, the conventions follow the ES5 specification. arrays
and objects
are more conveniently stringified.
Note that the stringified values are buffered according to the encoding
option. If the encoding
is null
(default), buffering assumes utf8
encoding.
Tests
Unit
Unit tests use the Mocha test framework with Chai assertions. To run the tests, execute the following command in the top-level application directory:
$ make test
All new feature development should have corresponding unit tests to validate correct functionality.
Test Coverage
This repository uses Istanbul as its code coverage tool. To generate a test coverage report, execute the following command in the top-level application directory:
$ make test-cov
Istanbul creates a ./reports/coverage
directory. To access an HTML version of the report,
$ open reports/coverage/lcov-report/index.html
License
Copyright
Copyright © 2014. Athan Reines.