Skip to content

Commit

Permalink
feat(xml): add XML methods (#35)
Browse files Browse the repository at this point in the history
* feat(xml): add XML methods

* chore(eslint): clean up template strings and global var

* refactor(xml): Use Node type constants
  • Loading branch information
pgoldrbx committed Apr 14, 2020
1 parent 0a7ef84 commit 01d312c
Show file tree
Hide file tree
Showing 5 changed files with 1,088 additions and 2 deletions.
57 changes: 57 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,63 @@ Determine if a JsonML node has attributes
- `@param` `{string}` key - attribute name
- `@param` `{any}` value - attribute value

### XML

#### `fromXML( elem, filter )`

Converts XML nodes to JsonML

- `@param` `{Element}` elem - XML DOM node
- `@param` `{Function}` filter - optional method to apply on every created JsonML node
The filter method is called with the signature: `filter( jml, elem ) => jml`
- `@returns` `{JsonML|null}` a JsonML node

#### `fromXMLText( xmlText, filter )`

Converts XML text to JsonML

- `@param` `{string}` xmlText - XML text
- `@param` `{Function}` filter - optional method to apply on every created JsonML node
The filter method is called with the signature: `filter( jml, elem ) => jml`
- `@returns` `{JsonML|null}` a JsonML node

#### `isXML( value )`

- `@param` `{any}` value - Input value to test
- `@returns` `{boolean}` true if an XML DOM node

#### `parseXML( xmlText )`

Converts XML text to XML DOM nodes

- `@param` `{string}` xmlText - XML text
- `@returns` `{XMLDocument}` xml document

#### `renderXML( elem )`

Converts XML DOM nodes to XML text

- `@param` `{Element}` elem - XML DOM node
- `@returns` `{string}` XML string

#### `toXML( jml, filter )`

- `@param` `{JsonML}` jml - JsonML structure
- `@param` `{Function}` filter - optional method applied to each node during render
The filter method is called with the signature: `filter( elem ) => elem`
- `@returns` `{Element}` XML DOM Element

#### `toXMLText( jml, filter )`

Converts JsonML to XML text

- `@param` `{JsonML}` jml - JsonML structure
- `@param` `{Function}` filter - optional method applied to each node during render
The filter method is called with the signature: `filter( elem ) => elem`
- `@returns` `{string}` XML string

-----

## License

MIT
3 changes: 2 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
const utils = require('./utils');
const dom = require('./dom');
const html = require('./html');
Object.assign(module.exports, utils, dom, html);
const xml = require('./xml');
Object.assign(module.exports, utils, dom, html, xml);

0 comments on commit 01d312c

Please sign in to comment.