Skip to content
This repository has been archived by the owner on Jun 1, 2021. It is now read-only.

Commit

Permalink
make xml2json an optionnal dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackYoup committed Oct 24, 2016
1 parent ad020f7 commit 6a20876
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
"license": "BSD-3-Clause",
"dependencies": {
"baconjs": "^0.7.70",
"request": "^2.60.0",
"xml2json": "^0.7.1"
"request": "^2.60.0"
},
"devDependencies": {
"body": "^5.1.0",
Expand Down
13 changes: 12 additions & 1 deletion wadl-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@ var WadlClient = (function() {
/* Dependency aliases (to make WadlClient work on both node and browser environments) */
var B = typeof require == "function" && require("baconjs") ? require("baconjs") : Bacon;
var request = typeof XMLHttpRequest != "undefined" ? null : require("request");
var parser = typeof XMLHttpRequest != "undefined" ? null : require("xml2json");

// If you want xml2json support, add it as a dependency of your project
var parser;
try{
parser = typeof XMLHttpRequest != "undefined" ? null : require("xml2json");
} catch(err){
parser = null;
}

/* Utils */
var Utils = {};
Expand Down Expand Up @@ -32,6 +39,10 @@ var WadlClient = (function() {
return JSON.parse(typeof response.responseText != "undefined" ? response.responseText : body);
}
else if(Utils.elem(contentType || "", ["text/xml", "application/rss+xml", "application/rdf+xml", "application/atom+xml"])) {
if(!response.responseXML && !parser){
throw new Error("Parser is undefined. Please add xml2json as a dependency in your project");
}

return response.responseXML ? response.responseXML : parser.toJson(body, {
object: true,
arrayNotation: true
Expand Down

0 comments on commit 6a20876

Please sign in to comment.