fast-xml-parser
Advanced tools
Comparing version 4.0.0 to 4.0.1
Note: If you find missing information about particular minor version, that version must have been changed without any functional change in this library. | ||
**4.0.1 / 2022-01-08** | ||
* fix builder for pi tag | ||
* fix: support suppressBooleanAttrs by builder | ||
**4.0.0 / 2022-01-06** | ||
@@ -4,0 +8,0 @@ * Generating different combined, parser only, builder only, validator only browser bundles |
{ | ||
"name": "fast-xml-parser", | ||
"version": "4.0.0", | ||
"version": "4.0.1", | ||
"description": "Validate XML, Parse XML, Build XML without C/C++ based libraries", | ||
@@ -5,0 +5,0 @@ "main": "./src/fxp.js", |
# [fast-xml-parser](https://www.npmjs.com/package/fast-xml-parser) | ||
[![Backers on Open Collective](https://opencollective.com/fast-xml-parser/backers/badge.svg)](#backers) [![Sponsors on Open Collective](https://opencollective.com/fast-xml-parser/sponsors/badge.svg)](#sponsors) [![Known Vulnerabilities](https://snyk.io/test/github/naturalintelligence/fast-xml-parser/badge.svg)](https://snyk.io/test/github/naturalintelligence/fast-xml-parser) | ||
[![NPM quality][quality-image]][quality-url] | ||
[![Travis ci Build Status](https://travis-ci.org/NaturalIntelligence/fast-xml-parser.svg?branch=master)](https://travis-ci.org/NaturalIntelligence/fast-xml-parser) | ||
[![Coverage Status](https://coveralls.io/repos/github/NaturalIntelligence/fast-xml-parser/badge.svg?branch=master)](https://coveralls.io/github/NaturalIntelligence/fast-xml-parser?branch=master) | ||
@@ -120,5 +119,5 @@ [<img src="https://img.shields.io/badge/Try-me-blue.svg?colorA=FFA500&colorB=0000FF" alt="Try me"/>](https://naturalintelligence.github.io/fast-xml-parser/) | ||
4. [XML Validator](./docs/v4/4.XMLValidator.md) | ||
5. [Entites](./docs/5.Entities.md) | ||
6. [HTML Document Parsing](./docs/6.HTMLParsing.md) | ||
7. [PI Tag processing](./docs/7.PITags.md) | ||
5. [Entites](./docs/v4/5.Entities.md) | ||
6. [HTML Document Parsing](./docs/v4/6.HTMLParsing.md) | ||
7. [PI Tag processing](./docs/v4/7.PITags.md) | ||
## Performance | ||
@@ -125,0 +124,0 @@ |
@@ -71,2 +71,3 @@ 'use strict'; | ||
this.replaceEntitiesValue = replaceEntitiesValue; | ||
this.buildAttrPairStr = buildAttrPairStr; | ||
} | ||
@@ -94,3 +95,5 @@ | ||
} else if (jObj[key] === null) { | ||
val += this.indentate(level) + '<' + key + '/' + this.tagEndChar; | ||
if(key[0] === "?") val += this.indentate(level) + '<' + key + '?' + this.tagEndChar; | ||
else val += this.indentate(level) + '<' + key + '/' + this.tagEndChar; | ||
// val += this.indentate(level) + '<' + key + '/' + this.tagEndChar; | ||
} else if (jObj[key] instanceof Date) { | ||
@@ -102,5 +105,3 @@ val += this.buildTextNode(jObj[key], key, '', level); | ||
if (attr) { | ||
let val = this.options.attributeValueProcessor(attr, '' + jObj[key]); | ||
val = this.replaceEntitiesValue(val); | ||
attrStr += ' ' + attr + '="' + val + '"'; | ||
attrStr += this.buildAttrPairStr(attr, '' + jObj[key]); | ||
}else { | ||
@@ -123,3 +124,5 @@ //tag value | ||
} else if (item === null) { | ||
val += this.indentate(level) + '<' + key + '/' + this.tagEndChar; | ||
if(key[0] === "?") val += this.indentate(level) + '<' + key + '?' + this.tagEndChar; | ||
else val += this.indentate(level) + '<' + key + '/' + this.tagEndChar; | ||
// val += this.indentate(level) + '<' + key + '/' + this.tagEndChar; | ||
} else if (typeof item === 'object') { | ||
@@ -137,5 +140,3 @@ val += this.processTextOrObjNode(item, key, level) | ||
for (let j = 0; j < L; j++) { | ||
let val = this.options.attributeValueProcessor(Ks[j], '' + jObj[key][Ks[j]]); | ||
val = this.replaceEntitiesValue(val); | ||
attrStr += ' ' + Ks[j] + '="' + val + '"'; | ||
attrStr += this.buildAttrPairStr(Ks[j], '' + jObj[key][Ks[j]]); | ||
} | ||
@@ -150,2 +151,10 @@ } else { | ||
function buildAttrPairStr(attrName, val){ | ||
val = this.options.attributeValueProcessor(attrName, '' + val); | ||
val = this.replaceEntitiesValue(val); | ||
if (this.options.suppressBooleanAttributes && val === "true") { | ||
return ' ' + attrName; | ||
} else return ' ' + attrName + '="' + val + '"'; | ||
} | ||
function processTextOrObjNode (object, key, level) { | ||
@@ -161,30 +170,20 @@ const result = this.j2x(object, level + 1); | ||
function buildObjectNode(val, key, attrStr, level) { | ||
let tagEndExp = '</' + key + this.tagEndChar; | ||
let piClosingChar = ""; | ||
if(key[0] === "?") { | ||
piClosingChar = "?"; | ||
tagEndExp = ""; | ||
} | ||
if (attrStr && val.indexOf('<') === -1) { | ||
return ( | ||
this.indentate(level) + | ||
'<' + | ||
key + | ||
attrStr + | ||
'>' + | ||
this.indentate(level) + '<' + key + attrStr + piClosingChar + '>' + | ||
val + | ||
//+ this.newLine | ||
// + this.indentate(level) | ||
'</' + | ||
key + | ||
this.tagEndChar | ||
); | ||
tagEndExp ); | ||
} else { | ||
return ( | ||
this.indentate(level) + | ||
'<' + | ||
key + | ||
attrStr + | ||
this.tagEndChar + | ||
this.indentate(level) + '<' + key + attrStr + piClosingChar + this.tagEndChar + | ||
val + | ||
//+ this.newLine | ||
this.indentate(level) + | ||
'</' + | ||
key + | ||
this.tagEndChar | ||
); | ||
this.indentate(level) + tagEndExp ); | ||
} | ||
@@ -197,4 +196,4 @@ } | ||
} else { | ||
return this.indentate(level) + '<' + key + attrStr + '/' + this.tagEndChar; | ||
//+ this.newLine | ||
if(key[0] === "?") return this.indentate(level) + '<' + key + attrStr+ '?' + this.tagEndChar; | ||
else return this.indentate(level) + '<' + key + attrStr + '/' + this.tagEndChar; | ||
} | ||
@@ -208,12 +207,5 @@ } | ||
return ( | ||
this.indentate(level) + | ||
'<' + | ||
key + | ||
attrStr + | ||
'>' + | ||
this.indentate(level) + '<' + key + attrStr + '>' + | ||
textValue + | ||
'</' + | ||
key + | ||
this.tagEndChar | ||
); | ||
'</' + key + this.tagEndChar ); | ||
} | ||
@@ -237,3 +229,4 @@ | ||
} else { | ||
return this.indentate(level) + '<' + key + attrStr + '/' + this.tagEndChar; | ||
if(key[0] === "?") return this.indentate(level) + '<' + key + attrStr+ '?' + this.tagEndChar; | ||
else return this.indentate(level) + '<' + key + attrStr + '/' + this.tagEndChar; | ||
} | ||
@@ -240,0 +233,0 @@ } |
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
91988
1756
189