Comparing version 0.4.23 to 0.5.0
@@ -144,3 +144,3 @@ // Generated by CoffeeScript 1.12.7 | ||
var key, newValue, obj, processedKey, ref; | ||
obj = {}; | ||
obj = Object.create(null); | ||
obj[charkey] = ""; | ||
@@ -152,3 +152,3 @@ if (!_this.options.ignoreAttrs) { | ||
if (!(attrkey in obj) && !_this.options.mergeAttrs) { | ||
obj[attrkey] = {}; | ||
obj[attrkey] = Object.create(null); | ||
} | ||
@@ -203,3 +203,7 @@ newValue = _this.options.attrValueProcessors ? processItem(_this.options.attrValueProcessors, node.attributes[key], key) : node.attributes[key]; | ||
if (isEmpty(obj)) { | ||
obj = _this.options.emptyTag !== '' ? _this.options.emptyTag : emptyStr; | ||
if (typeof _this.options.emptyTag === 'function') { | ||
obj = _this.options.emptyTag(); | ||
} else { | ||
obj = _this.options.emptyTag !== '' ? _this.options.emptyTag : emptyStr; | ||
} | ||
} | ||
@@ -228,3 +232,3 @@ if (_this.options.validator != null) { | ||
if (!_this.options.preserveChildrenOrder) { | ||
node = {}; | ||
node = Object.create(null); | ||
if (_this.options.attrkey in obj) { | ||
@@ -244,3 +248,3 @@ node[_this.options.attrkey] = obj[_this.options.attrkey]; | ||
s[_this.options.childkey] = s[_this.options.childkey] || []; | ||
objClone = {}; | ||
objClone = Object.create(null); | ||
for (key in obj) { | ||
@@ -262,3 +266,3 @@ if (!hasProp.call(obj, key)) continue; | ||
old = obj; | ||
obj = {}; | ||
obj = Object.create(null); | ||
obj[nodeName] = old; | ||
@@ -265,0 +269,0 @@ } |
@@ -9,3 +9,3 @@ { | ||
"homepage": "https://github.com/Leonidas-from-XIV/node-xml2js", | ||
"version": "0.4.23", | ||
"version": "0.5.0", | ||
"author": "Marek Kubica <marek@xivilization.net> (https://xivilization.net)", | ||
@@ -57,3 +57,4 @@ "contributors": [ | ||
"Lovell Fuller (http://lovell.info/)", | ||
"d3adc0d3 (https://github.com/d3adc0d3)" | ||
"d3adc0d3 (https://github.com/d3adc0d3)", | ||
"James Crosby (https://github.com/autopulated)" | ||
], | ||
@@ -60,0 +61,0 @@ "main": "./lib/xml2js", |
@@ -116,3 +116,3 @@ node-xml2js | ||
var parser = new xml2js.Parser(/* options */); | ||
parser.parseStringPromise(data).then(function (result) { | ||
parser.parseStringPromise(xml).then(function (result) { | ||
console.dir(result); | ||
@@ -126,3 +126,3 @@ console.log('Done'); | ||
// Without parser | ||
xml2js.parseStringPromise(data /*, options */).then(function (result) { | ||
xml2js.parseStringPromise(xml /*, options */).then(function (result) { | ||
console.dir(result); | ||
@@ -185,3 +185,13 @@ console.log('Done'); | ||
``` | ||
will result in: | ||
```xml | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
<root> | ||
<name>Super</name> | ||
<Surname>Man</Surname> | ||
<age>23</age> | ||
</root> | ||
``` | ||
At the moment, a one to one bi-directional conversion is guaranteed only for | ||
@@ -201,2 +211,7 @@ default configuration, except for `attrkey`, `charkey` and `explicitArray` options | ||
``` | ||
will result in: | ||
```xml | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
<root id="my id">my inner text</root> | ||
``` | ||
@@ -316,3 +331,4 @@ ### Adding xmlns attributes | ||
content. Version 0.1 default was `#`. | ||
* `explicitCharkey` (default: `false`) | ||
* `explicitCharkey` (default: `false`) Determines whether or not to use | ||
a `charkey` prefix for elements with no attributes. | ||
* `trim` (default: `false`): Trim the whitespace at the beginning and end of | ||
@@ -324,3 +340,6 @@ text nodes. | ||
node in the resulting object. | ||
* `emptyTag` (default: `''`): what will the value of empty nodes be. | ||
* `emptyTag` (default: `''`): what will the value of empty nodes be. In case | ||
you want to use an empty object as a default value, it is better to provide a factory | ||
function `() => ({})` instead. Without this function a plain object would | ||
become a shared reference across all occurrences with unwanted behavior. | ||
* `explicitArray` (default: `true`): Always put child nodes in an array if | ||
@@ -327,0 +346,0 @@ true; otherwise an array is created only if there is more than one. |
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
44373
615
508