Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

xml-js

Package Overview
Dependencies
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xml-js - npm Package Compare versions

Comparing version 0.9.4 to 0.9.5

artwork/logo.svg

10

lib/js2xml.js

@@ -95,2 +95,7 @@ /*jslint node:true */

switch (key) {
case options.textKey:
if (!skipText) {
return true;
}
break; // skip to next key
case options.parentKey:

@@ -103,7 +108,2 @@ case options.attributesKey:

return true;
case options.textKey:
if (!skipText) {
return true;
}
break; // skip to next key
default:

@@ -110,0 +110,0 @@ return true;

/*jslint node:true */
var sax = require('sax');
var expat = {on: function () {}, parse: function () {}};
//var expat = require('node-expat');
var expat /*= require('node-expat');*/ = {on: function () {}, parse: function () {}};
var common = require('./common');

@@ -6,0 +5,0 @@

{
"name": "xml-js",
"version": "0.9.4",
"version": "0.9.5",
"description": "A convertor between XML text and Javascript object / JSON text.",

@@ -22,2 +22,4 @@ "main": "index.js",

"json",
"cdata",
"CDATA",
"Javascript",

@@ -38,5 +40,3 @@ "js2xml",

"parser",
"parsing",
"cdata",
"CDATA"
"parsing"
],

@@ -57,3 +57,3 @@ "bin": "./bin/cli.js",

"istanbul": "^0.4.5",
"jasmine": "^2.5.0",
"jasmine": "^2.4.1",
"node-inspector": "^0.12.8",

@@ -73,8 +73,8 @@ "nodemon": "^1.10.2",

"watch:jasmine": "watch \"npm run jasmine\" lib/ test/",
"bundle:jasmine": "globify test/*_test.js --watch --verbose --list --outfile jasmine/bundle.js",
"live:jasmine": "browser-sync start --port 9991 --server jasmine/ --files jasmine/ --no-open --no-ui --no-online",
"bundle:jasmine": "globify test/*_test.js --watch --verbose --list --outfile test/browse-jasmine/bundle.js",
"live:jasmine": "browser-sync start --port 9991 --server test/browse-jasmine/ --files test/browse-jasmine/ --no-open --no-ui --no-online",
"open:jasmine": "biased-opener --browser chrome http://localhost:9991",
"istanbul": "istanbul cover test/index.js",
"watch:istanbul": "watch \"npm run istanbul\" lib/ test/",
"live:istanbul": "browser-sync start --port 9992 --server coverage/lcov-report/ --files coverage/lcov-report/ --no-open --no-ui --no-online",
"istanbul": "istanbul cover --dir test/browse-coverage -x test/browse-** test/index.js",
"watch:istanbul": "watch \"npm run istanbul\" lib/ test/ --ignoreDirectoryPattern=/browse-.+/",
"live:istanbul": "browser-sync start --port 9992 --server test/browse-coverage/lcov-report/ --files test/browse-coverage/lcov-report/ --no-open --no-ui --no-online",
"open:istanbul": "biased-opener --browser chrome http://localhost:9992",

@@ -88,4 +88,4 @@ "live": "npm-run-all --parallel live:* open:*",

"coverage:a-step": "npm run istanbul",
"coverage:coveralls": "cat ./coverage/lcov.info | coveralls",
"coverage:codacy": "cross-env CODACY_PROJECT_TOKEN=0207815122ea49a68241d1aa435f21f1 cat ./coverage/lcov.info | codacy-coverage",
"coverage:coveralls": "cat ./test/browse-coverage/lcov.info | coveralls",
"coverage:codacy": "cross-env CODACY_PROJECT_TOKEN=0207815122ea49a68241d1aa435f21f1 cat ./test/browse-coverage/lcov.info | codacy-coverage",
"coverage:codeclimate": "cross-env CODECLIMATE_REPO_TOKEN=60848a077f9070acf358b0c7145f0a2698a460ddeca7d8250815e75aa4333f7d codeclimate-test-reporter < coverage\\lcov.info",

@@ -92,0 +92,0 @@ "update-packages": "npm-check-updates --upgrade --loglevel verbose",

@@ -17,7 +17,8 @@ ![XML ⇔ JS/JSON](http://nashwaan.github.io/xml-js/images/logo.svg)

[![Dependency Status](https://david-dm.org/nashwaan/xml-js.svg)](https://david-dm.org/nashwaan/xml-js)
[![Package Quality](http://xxxnpm.packagequality.com/shield/xml-js.svg)](http://xxxpackagequality.com/#?package=xml-js)
[![Package Quality](http://npm.packagequality.com/shield/xml-js.svg)](http://packagequality.com/#?package=xml-js)
# Synopsis
![Convert XML ↔ JS/JSON as compact or non-compact](/synopsis.png?raw=true "Synopsis Diagram")
![Convert XML ↔ JS/JSON as compact or non-compact](http://nashwaan.github.io/xml-js/images/synopsis.svg)
<!---![Convert XML ↔ JS/JSON as compact or non-compact](/synopsis.png?raw=true "Synopsis Diagram")-->

@@ -56,12 +57,15 @@ # Motivation

Most XML parsers (including online parsers) convert `<a/>` to some compact output like `{"a":{}}`
Most XML to JSON convertors (including online convertors) convert `<a/>` to some compact output like `{"a":{}}`
instead of non-compact output like `{"elements":[{"type":"element","name":"a"}]}`.
While compact output might work in most situations, there are cases when different elements are mixed inside a parent element: `<n><a x="1"/><b x="2"/><a x="3"/></n>`.
In this case, the compact output will be `{n:{a:[{_:{x:"1"}},{_:{x:"3"}}],b:{_:{x:"2"}}}}`,
which has merged the second `<a/>` with the first `<a/>` into an array and so the order is not preserved.
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"}}}`,
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.
Although non-compact output is more accurate representation of original XML than compact version, the non-compact consumes more space.
Although non-compact output is more accurate representation of original XML than compact version, the non-compact consumes more space.
This library provides both options. Use `{compact: false}` if you are not sure because it preserves everything;
otherwise use `{compact: true}` if you want to save space and you don't care about mixing elements of same type.
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.

@@ -98,3 +102,3 @@ # Usage

To see the output of this code, see the picture above in *Synopsis* section.
To see the result of this code, see the output above in *Synopsis* section.

@@ -167,3 +171,3 @@ ## Sample Conversions

| `addParent` | `false` | Whether to add `parent` property in each element object that points to parent object. |
| `alwaysChildren` | `false` | Whether to always generate `elements` property even when there are no actual sub elements. |
| `alwaysChildren` | `false` | Whether to always generate `elements` property even when there are no actual sub elements (applicable for non-compact output). |
| `ignoreDeclaration` | `false` | Whether to ignore writing declaration property. That is, no `declaration` property will be generated. |

@@ -170,0 +174,0 @@ | `ignoreAttributes` | `false` | Whether to ignore writing attributes of elements.That is, no `attributes` property will be generated. |

@@ -8,4 +8,3 @@ /*jslint node:true */

if ('spec_dir' in config) {
config.spec_dir = path.join(path.relative(process.cwd(), __dirname), config.spec_dir);
console.log(config.spec_dir);
config.spec_dir = path.join(path.relative(process.cwd(), __dirname), '..', config.spec_dir);
}

@@ -12,0 +11,0 @@

{
"spec_dir": ".",
"spec_dir": "./test",
"spec_files": [
"./**/*_test.js"
"./**/*_[Tt]est.js"
],
"helpers": [
]
],
"stopSpecOnExpectationFailure": false,
"random": false
}

@@ -270,4 +270,4 @@ /*jslint node:true */

describe('case by Jan T. Sott', function () {
var js = {
// see https://github.com/nashwaan/xml-js/issues/2
var js = {
_comment: " Released under The MIT License ",

@@ -296,7 +296,7 @@ snippet: {

it('should output cdata and text for {spaces: 4} option', function () {
expect(convert.js2xml(js, {compact: true})).toEqual(xml.replace(/\n/g, '').replace(/\v/g, ''));
it('should output cdata and text unformatted', function () {
expect(convert.js2xml(js, {compact: true})).toEqual(xml.replace(/\v|\n/g, ''));
});
it('should output cdata and text for {spaces: 4} option', function () {
it('should output cdata and text formatted', function () {
expect(convert.js2xml(js, {compact: true, spaces: 4})).toEqual(xml.replace(/\v/g, ' '));

@@ -303,0 +303,0 @@ });

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc