https://github.com/mcous/xmlovely
Compact XML to pretty-printed XML Node transform stream
https://github.com/mcous/xmlovely
Last synced: 8 months ago
JSON representation
Compact XML to pretty-printed XML Node transform stream
- Host: GitHub
- URL: https://github.com/mcous/xmlovely
- Owner: mcous
- License: isc
- Created: 2015-12-24T00:24:54.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-05-04T05:45:26.000Z (about 10 years ago)
- Last Synced: 2025-09-27T20:18:09.563Z (8 months ago)
- Language: JavaScript
- Size: 8.79 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# xmlovely
[](https://www.npmjs.org/package/xmlovely)
[](https://travis-ci.org/mcous/xmlovely) [](https://coveralls.io/r/mcous/xmlovely) [](https://david-dm.org/mcous/xmlovely)
[](https://david-dm.org/mcous/xmlovely#info=devDependencies)
Node transform stream to pretty print a compact XML stream
## what it does
Turns a stream of this:
``` xml
```
Into a stream of this:
``` xml
```
## usage
`$ npm install --save xmlovely`
``` javascript
var xmlovely = require('xmlovely')
var prettyPrinter = xmlovely()
getReadableXmlStreamSomehow()
.pipe(prettyPrinter)
.pipe(getOutputStreamSomehow())
```
### options
``` javascript
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.
``` javascript
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":
``` javascript
var xmlovely = require('xmlovely')
var prettyPrinter = xmlovely(3)
prettyPrinter.pipe(process.stdout)
prettyPrinter.write('')
/*
↵
···↵
↵
*/
```
To use actual tabs:
``` javascript
var xmlovely = require('xmlovely')
var prettyPrinter = xmlovely({width: 1, whitespace: '\t'})
prettyPrinter.pipe(process.stdout)
prettyPrinter.write('')
/*
↵
→↵
↵
*/
```