1.0.1 • Published 8 years ago

xmlovely v1.0.1

Weekly downloads
7
License
ISC
Repository
github
Last release
8 years ago

xmlovely

Version Build Status Coverage Dependencies DevDependencies

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
}
keytypedefault
widthnumber2
whitespacestring' '

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>↵
*/