Comparing version 0.0.5 to 0.0.6
18
index.js
@@ -16,4 +16,4 @@ const fs = require('fs'); | ||
const source = await readFile(filename, 'utf8'); | ||
const dom = await XML.read(`<root>${source}</root>`, options); | ||
return dom.children; | ||
const ast = await XML.read(`<root>${source}</root>`, options); | ||
return ast.children; | ||
} | ||
@@ -26,4 +26,18 @@ static serialize(ast, options){ | ||
} | ||
static transform(source, options = {}){ | ||
const { plugins = [] } = options; | ||
const ast = await XML.read(source); | ||
const visitors = plugins | ||
.map(plugin => plugin(ast)) | ||
.filter(Boolean); | ||
XML.traverse(ast, node => { | ||
visitors.forEach(visitor => { | ||
const fn = visitor[node.name]; | ||
typeof fn === 'function' && fn(node); | ||
}); | ||
}); | ||
return XML.serialize(ast, options); | ||
} | ||
} | ||
module.exports = XML; |
{ | ||
"name": "xml2", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "simple xml reader and parser", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
12694
380