xml-parser-xo
Advanced tools
Comparing version 4.0.0 to 4.0.1
@@ -53,2 +53,6 @@ export declare type XmlParserOptions = { | ||
}; | ||
export declare class ParsingError extends Error { | ||
readonly cause: string; | ||
constructor(message: string, cause: string); | ||
} | ||
/** | ||
@@ -55,0 +59,0 @@ * Parse the given XML string into an object. |
@@ -0,1 +1,7 @@ | ||
export class ParsingError extends Error { | ||
constructor(message, cause) { | ||
super(message); | ||
this.cause = cause; | ||
} | ||
} | ||
let parsingState; | ||
@@ -27,4 +33,7 @@ function nextChild() { | ||
if (!documentRootNode) { | ||
throw new Error('Failed to parse XML'); | ||
throw new ParsingError('Failed to parse XML', 'Root Element not found'); | ||
} | ||
if (parsingState.xml.length !== 0) { | ||
throw new ParsingError('Failed to parse XML', 'Not Well-Formed XML'); | ||
} | ||
return { | ||
@@ -93,14 +102,12 @@ declaration: declaration ? declaration.node : null, | ||
match(/\??>/); | ||
if (!excluded) { | ||
// children | ||
let child = nextChild(); | ||
while (child) { | ||
if (!child.excluded) { | ||
node.children.push(child.node); | ||
} | ||
child = nextChild(); | ||
// children | ||
let child = nextChild(); | ||
while (child) { | ||
if (!child.excluded) { | ||
node.children.push(child.node); | ||
} | ||
child = nextChild(); | ||
} | ||
// closing | ||
match(/^<\/[\w-:.]+>/); | ||
match(/^<\/\s*[\w-:.\u00C0-\u00FF]+>/); | ||
return { | ||
@@ -213,2 +220,3 @@ excluded, | ||
} | ||
module.exports = parseXml; | ||
export default parseXml; |
@@ -53,2 +53,6 @@ export declare type XmlParserOptions = { | ||
}; | ||
export declare class ParsingError extends Error { | ||
readonly cause: string; | ||
constructor(message: string, cause: string); | ||
} | ||
/** | ||
@@ -55,0 +59,0 @@ * Parse the given XML string into an object. |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ParsingError = void 0; | ||
class ParsingError extends Error { | ||
constructor(message, cause) { | ||
super(message); | ||
this.cause = cause; | ||
} | ||
} | ||
exports.ParsingError = ParsingError; | ||
let parsingState; | ||
@@ -29,4 +37,7 @@ function nextChild() { | ||
if (!documentRootNode) { | ||
throw new Error('Failed to parse XML'); | ||
throw new ParsingError('Failed to parse XML', 'Root Element not found'); | ||
} | ||
if (parsingState.xml.length !== 0) { | ||
throw new ParsingError('Failed to parse XML', 'Not Well-Formed XML'); | ||
} | ||
return { | ||
@@ -95,14 +106,12 @@ declaration: declaration ? declaration.node : null, | ||
match(/\??>/); | ||
if (!excluded) { | ||
// children | ||
let child = nextChild(); | ||
while (child) { | ||
if (!child.excluded) { | ||
node.children.push(child.node); | ||
} | ||
child = nextChild(); | ||
// children | ||
let child = nextChild(); | ||
while (child) { | ||
if (!child.excluded) { | ||
node.children.push(child.node); | ||
} | ||
child = nextChild(); | ||
} | ||
// closing | ||
match(/^<\/[\w-:.]+>/); | ||
match(/^<\/\s*[\w-:.\u00C0-\u00FF]+>/); | ||
return { | ||
@@ -215,2 +224,3 @@ excluded, | ||
} | ||
module.exports = parseXml; | ||
exports.default = parseXml; |
{ | ||
"name": "xml-parser-xo", | ||
"version": "4.0.0", | ||
"version": "4.0.1", | ||
"repository": "github:chrisbottin/xml-parser", | ||
@@ -5,0 +5,0 @@ "bugs": { |
# xml-parser-xo | ||
XML parser based on [xml-parser](https://www.npmjs.com/package/xml-parser). | ||
An XML parser based on [xml-parser](https://www.npmjs.com/package/xml-parser). | ||
@@ -16,6 +16,6 @@ [![Build Status](https://github.com/chrisbottin/xml-parser/actions/workflows/ci.yml/badge.svg)](https://github.com/chrisbottin/xml-parser/actions/workflows/ci.yml) [![npm version](https://img.shields.io/npm/v/xml-parser-xo.svg)](https://npmjs.org/package/xml-parser-xo) | ||
JavaScript: | ||
### Usage: | ||
```js | ||
var parse = require('xml-parser-xo'); | ||
import xmlParser from 'xml-parser-xo'; | ||
@@ -28,6 +28,6 @@ var xml = `<?xml version="1.0" encoding="utf-8"?> | ||
console.log(parse(xml)); | ||
xmlParser(xml); | ||
``` | ||
Output: | ||
### Output: | ||
@@ -66,4 +66,55 @@ ```json | ||
# License | ||
## Options | ||
MIT | ||
- `filter` (`function(node) => boolean`) Function to filter out unwanted nodes by returning `false`. | ||
### Usage: | ||
```js | ||
import xmlParser from 'xml-parser-xo'; | ||
const xml = `<?xml version="1.0" encoding="utf-8"?> | ||
<!-- Load the stylesheet --> | ||
<?xml-stylesheet href="foo.xsl" type="text/xsl" ?> | ||
<!DOCTYPE foo SYSTEM "foo.dtd"> | ||
<foo><![CDATA[some text]]> content</foo>`; | ||
xmlParser(xml, { | ||
filter: (node) => { | ||
return node.type === 'Element' || node.type === 'Text'; | ||
} | ||
}); | ||
``` | ||
### Output: | ||
```json | ||
{ | ||
"declaration": { | ||
"type": "ProcessingInstruction", | ||
"attributes": {"version": "1.0", "encoding": "utf-8"} | ||
}, | ||
"root": { | ||
"type": "Element", | ||
"name": "foo", | ||
"attributes": {}, | ||
"children": [ | ||
{"type": "Text", "content": " content"} | ||
] | ||
}, | ||
"children": [ | ||
{ | ||
"type": "Element", | ||
"name": "foo", | ||
"attributes": {}, | ||
"children": [ | ||
{"type": "Text", "content": " content"} | ||
] | ||
} | ||
] | ||
} | ||
``` | ||
## License | ||
MIT |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
20314
564
118
0