Comparing version 1.0.0 to 1.0.1
{ | ||
"name": "xml-js", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "A convertor between XML text and Javascript object / JSON text.", | ||
@@ -58,3 +58,3 @@ "repository": { | ||
"nodemon": "^1.11.0", | ||
"npm-run-all": "^4.0.0", | ||
"npm-run-all": "^4.0.1", | ||
"typescript": "^2.1.5", | ||
@@ -61,0 +61,0 @@ "watch": "^1.0.1" |
@@ -36,3 +36,3 @@ ![XML ⇔ JS/JSON](http://nashwaan.github.io/xml-js/images/logo.svg) | ||
* **Reversible**: | ||
Whether converting xml→json or json→xml, the result should be convertable to its original form. | ||
Whether converting xml→json or json→xml, the result can be converted back to its original form. | ||
@@ -46,5 +46,8 @@ * **Minimal Dependencies**: | ||
* **Support Upwards Traversal**: | ||
By setting `{addParent: true}` option, an extra property named `parent` will be generated along each element so that its parent can be referenced. | ||
Therefore, anywhere during the traversal of an element node, its children **and** its parent can be easily accessed. | ||
* **Portable Code**: | ||
Written purely in JavaScript which means it can be used in Node environment and **browser** environment (via bundlers like browserify/JSPM/Webpack). | ||
Note (this is default behavior, but this can be slow for very large XML text). | ||
@@ -64,9 +67,10 @@ * **Support Command Line**: | ||
While compact output might work in most situations, there are cases when different elements are mixed inside a parent element: `<a x="1"/><b x="2"/><a x="3"/>`. | ||
In this case, the compact output will be something like `{a:[{_:{x:"1"}},{_:{x:"3"}}],b:{_:{x:"2"}}}`, | ||
In this case, the compact output will be something like `{a:[{_:{x:"1"}},{_:{x:"3"}}], b:{_:{x:"2"}}}`, | ||
which has merged both `<a>` elements into an array. If you try to convert this back to xml, you will get `<a x="1"/><a x="3"/><b x="2"/>` | ||
which has not preserved the order of elements! This is an inherit limitation in the compact representation | ||
because output like `{a:{_:{x:"1"}},b:{_:{x:"2"}},a:{_:{x:"3"}}}` is illegal. | ||
Note that this issue does not occur in the non-compact form provided by this library. | ||
because output like `{a:{_:{x:"1"}}, b:{_:{x:"2"}}, a:{_:{x:"3"}}}` is illegal (cannot make two properties of same name). | ||
Although non-compact output is more accurate representation of original XML than compact version, the non-compact consumes more space. | ||
The non-compact output always gurantees the order of the elements as they appeared in the XML file. | ||
Although non-compact output is more accurate representation of original XML than compact version, the non-compact is verbose and consumes more space. | ||
This library provides both options. Use `{compact: false}` if you are not sure because it preserves everything; | ||
@@ -107,2 +111,4 @@ otherwise use `{compact: true}` if you want to save space and you don't care about mixing elements of same type and loosing their order. | ||
Or [run and edit](https://runkit.com/587874e079a2f60013c1f5ac/587874e079a2f60013c1f5ad) this code live in the browser. | ||
## Sample Conversions | ||
@@ -203,3 +209,5 @@ | ||
> TIP: You probably want to set `{textKey: 'value', cdataKey: 'value', commentKey: 'value'}` for non-compact output | ||
Two default values mean the first is used for *non-compact* output and the second is for *compact* output. | ||
> **TIP**: You probably want to set `{textKey: 'value', cdataKey: 'value', commentKey: 'value'}` for *non-compact* output | ||
> to make it more consistent and easier for your client code to go through the contents of text, cdata, and comment. | ||
@@ -215,6 +223,6 @@ | ||
npm install -g xml-js // install this library globally | ||
xml-js test.json --space 4 // xml result will be printed on screen | ||
xml-js test.json --space 4 --out test.xml // xml result will be saved to test.xml | ||
xml-js test.xml --space 4 // json result will be printed on screen | ||
xml-js test.xml --space 4 --out test.json // json result will be saved to test.json | ||
xml-js test.json --spaces 4 // xml result will be printed on screen | ||
xml-js test.json --spaces 4 --out test.xml // xml result will be saved to test.xml | ||
xml-js test.xml --spaces 4 // json result will be printed on screen | ||
xml-js test.xml --spaces 4 --out test.json // json result will be saved to test.json | ||
``` | ||
@@ -255,3 +263,3 @@ | ||
--help, -h Display this help content. | ||
--version, -v Display number of this module. | ||
--version, -v Display version number of this module. | ||
--out Output file where result should be written. | ||
@@ -282,19 +290,8 @@ --spaces Specifies amount of space indentation in the output. | ||
## Comparison with Other Libraries | ||
[xml2js](https://www.npmjs.com/package/xml2js) | ||
[xml2json](https://www.npmjs.com/package/xml2json) | ||
[xml-objects](https://www.npmjs.com/package/xml-objects) | ||
[xml-js-converter](https://www.npmjs.com/package/xml-js-converter) | ||
[fast-xml2js](https://www.npmjs.com/package/fast-xml2js) | ||
[co-xml2js](https://www.npmjs.com/package/co-xml2js) | ||
[xml-simple](https://www.npmjs.com/package/xml-simple) | ||
[xml2js-expat](https://www.npmjs.com/package/xml2js-expat) | ||
## Testing | ||
To perform tests on this project: | ||
To perform tests on this project, download the full repository from GitHub (not from npm): | ||
``` | ||
cd node_modules/xml-js | ||
cd xml-js | ||
npm install | ||
@@ -301,0 +298,0 @@ npm test |
Sorry, the diff of this file is not supported yet
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
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
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
68
8
1
440647
1
2699
300