xmlovely
v1.0.1
Published
A compact XML to pretty-printed XML Node transform stream
Downloads
90
Readme
xmlovely
Node transform stream to pretty print a compact XML stream
what it does
Turns a stream of this:
<hello><from><the><other><side/></other></the></from></hello>
Into a stream of this:
<hello>
<from>
<the>
<other>
<side/>
</other>
</the>
</from>
</hello>
usage
$ npm install --save xmlovely
var xmlovely = require('xmlovely')
var prettyPrinter = xmlovely()
getReadableXmlStreamSomehow()
.pipe(prettyPrinter)
.pipe(getOutputStreamSomehow())
options
var xmlovely = require('xmlovely')
var options = getOptionsSomehow()
var prettyPrinter = xmlovely(options)
The options parameter may be a number or an object. If it is an object, it may be used to specify the whitespace character and the number of those characters that make up a "tab". If the options parameter is a number, the whitespace character will be a space, and the value of options
will be used as the tab-width.
var optionsNumber = WHITESPACE_WIDTH
var optionsObject = {
width: WHITESPACE_WIDTH,
whitespace: WHITESPACE_CHARACTER
}
key | type | default
-----------|--------|---------
width | number | 2
whitespace | string | ' '
For example, to use 3-space "tabs":
var xmlovely = require('xmlovely')
var prettyPrinter = xmlovely(3)
prettyPrinter.pipe(process.stdout)
prettyPrinter.write('<node><child/></node>')
/*
<node>↵
···<child/>↵
</node>↵
*/
To use actual tabs:
var xmlovely = require('xmlovely')
var prettyPrinter = xmlovely({width: 1, whitespace: '\t'})
prettyPrinter.pipe(process.stdout)
prettyPrinter.write('<node><child/></node>')
/*
<node>↵
→<child/>↵
</node>↵
*/