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

js2xmlparser

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

js2xmlparser - npm Package Compare versions

Comparing version 0.1.4 to 0.1.5

5

CHANGES.md

@@ -0,1 +1,6 @@

## 0.1.5 ##
* Bug fixes
* Minor changes to examples
## 0.1.4 ##

@@ -2,0 +7,0 @@

7

example/example.js

@@ -103,3 +103,8 @@ /* jshint node:true */

var example4 = {
"notes": "John's profile is not complete."
"notes": {
"@": {
"type": "status"
},
"#":"John's profile is not complete."
}
};

@@ -106,0 +111,0 @@

11

lib/js2xmlparser.js

@@ -187,3 +187,3 @@ /* jshint node:true */

xml += " " + attribute + "=\"" +
toString(object[property][attributeString][attribute]) + "\"";
toString(object[property][attributeString][attribute], true) + "\"";
}

@@ -204,3 +204,3 @@ }

else if (lengthExcludingAttributes === 1 && valueString in object[property]) { // Value string only
xml += addBreak(">" + toString(object[property][valueString], true) + "</" + elementName + ">");
xml += addBreak(">" + toString(object[property][valueString], false) + "</" + elementName + ">");
}

@@ -225,3 +225,3 @@ else { // Object with properties

else {
xml += addBreak(addIndent("<" + elementName + ">" + toString(object[property]) + "</" +
xml += addBreak(addIndent("<" + elementName + ">" + toString(object[property], false) + "</" +
elementName + ">", level));

@@ -271,3 +271,3 @@ }

// Convert anything into a valid XML string representation
var toString = function(data) {
var toString = function(data, isAttribute) {
// Recursive function used to handle nested functions

@@ -304,3 +304,4 @@ var functionHelper = function(data) {

if (useCDATA) {
// Output as CDATA instead of escaping if option set (and only if not an attribute value)
if (useCDATA && !isAttribute) {
data = "<![CDATA[" + data.replace(/]]>/gm, "]]]]><![CDATA[>") + "]]>";

@@ -307,0 +308,0 @@ }

@@ -6,3 +6,3 @@ {

"homepage": "http://www.kourlas.net",
"version": "0.1.4",
"version": "0.1.5",
"author": "Michael Kourlas <michael@kourlas.net>",

@@ -9,0 +9,0 @@ "main": "./lib/js2xmlparser.js",

@@ -44,3 +44,3 @@ # js2xmlparser #

* `attributeString` - the name of the property representing an element's attributes; note that any property with a
name equal to the attribute string is ignored except in the context of XML attributes (string, optional, default:
name equal to the attribute string is ignored except in the context of XML attributes (string, optional, default:
"@")

@@ -53,4 +53,4 @@ * `valueString` - the name of the property representing an element's value; note that any property with a name equal

* `indentString` - indent string (string, optional, default: "\t")
* `convertMap` - maps object types (as given by the `Object.prototype.toString.call` method) to functions to convert
those objects to a particular string representation; `*` can be used as a wildcard for all types of objects
* `convertMap` - maps object types (as given by the `Object.prototype.toString.call` method) to functions to convert
those objects to a particular string representation; `*` can be used as a wildcard for all types of objects
(object, optional, default: {})

@@ -141,4 +141,5 @@ * `useCDATA` - specifies whether strings should be enclosed in CDATA tags; otherwise, illegal XML characters will

var data = {
"email": function() {return "john@smith.com";},
"dateOfBirth": new Date(1964, 7, 26)
};
}

@@ -149,2 +150,5 @@ var options = {

return date.toISOString();
},
"[object Function]": function(func) {
return func.toString();
}

@@ -158,2 +162,3 @@ }

> <person>
> <email>function () {return &quot;john@smith.com&quot;;}</email>
> <dateOfBirth>1964-08-26T04:00:00.000Z</dateOfBirth>

@@ -167,3 +172,8 @@ > </person>

var data = {
"notes": "John's profile is not complete."
"notes": {
"@": {
"type": "status"
},
"#": "John's profile is not complete."
}
};

@@ -179,3 +189,3 @@

> <person>
> <notes><![CDATA[John's profile is not complete.]]></notes>
> <notes type="status"><![CDATA[John's profile is not complete.]]></notes>
> </person>

@@ -182,0 +192,0 @@

@@ -1158,3 +1158,3 @@ /* jshint node:true */

res.should.equal("<person type=\"individual\"><firstName>John</firstName><lastName>Smith</lastName>" +
"<dateOfBirth>Wed Aug 26 1964 00:00:00 GMT-0400 (Eastern Daylight Time)</dateOfBirth><address " +
"<dateOfBirth>"+new Date(1964, 7, 26)+"</dateOfBirth><address " +
"type=\"home\"><streetAddress>3212 22nd St</streetAddress><city>Chicago</city><state>Illinois" +

@@ -1207,3 +1207,3 @@ "</state><zip>10000</zip></address><phone type=\"home\">123-555-4567</phone><phone type=\"cell\">" +

res.should.equal("<person type=\"individual\">\n\t<firstName>John</firstName>\n\t<lastName>Smith" +
"</lastName>\n\t<dateOfBirth>Wed Aug 26 1964 00:00:00 GMT-0400 (Eastern Daylight Time)" +
"</lastName>\n\t<dateOfBirth>"+ new Date(1964, 7, 26) +
"</dateOfBirth>\n\t<address type=\"home\">\n\t\t<streetAddress>3212 22nd St</streetAddress>" +

@@ -1217,3 +1217,4 @@ "\n\t\t<city>Chicago</city>\n\t\t<state>Illinois</state>\n\t\t<zip>10000</zip>\n\t</address>" +

var res = js2xmlparser("person", {
"notes": "John's profile is not complete."
"email": function() {return "john@smith.com";},
"dateOfBirth": new Date(1964, 7, 26)
}, {

@@ -1226,5 +1227,13 @@ declaration: {

},
useCDATA: true
convertMap: {
"[object Date]": function (date) {
return date.toISOString();
},
"[object Function]": function(func) {
return func.toString();
}
}
});
res.should.equal("<person><notes><![CDATA[John's profile is not complete.]]></notes></person>");
res.should.equal("<person><email>function () {return &quot;john@smith.com&quot;;}</email>" +
"<dateOfBirth>1964-08-26T04:00:00.000Z</dateOfBirth></person>");
});

@@ -1234,3 +1243,8 @@

var res = js2xmlparser("person", {
"dateOfBirth": new Date(1964, 7, 26)
"notes": {
"@": {
"type": "status"
},
"#":"John's profile is not complete."
}
}, {

@@ -1243,12 +1257,9 @@ declaration: {

},
convertMap: {
"[object Date]": function (date) {
return date.toISOString();
}
}
useCDATA: true
});
res.should.equal("<person><dateOfBirth>1964-08-26T04:00:00.000Z</dateOfBirth></person>");
res.should.equal("<person><notes type=\"status\"><![CDATA[John's profile is not complete.]]></notes>" +
"</person>");
});
});
});
})();
})();
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