clinical-trials-gov
Advanced tools
Comparing version 1.0.0 to 1.1.0
{ | ||
"name": "clinical-trials-gov", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "A way to interface with the clinicaltrials.gov api", | ||
@@ -16,4 +16,7 @@ "main": "src/index.js", | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/arronhunt/clinical-trials-gov" | ||
}, | ||
"dependencies": { | ||
"node-fetch": "^1.7.3", | ||
"xml2js": "^0.4.19" | ||
@@ -20,0 +23,0 @@ }, |
@@ -1,2 +0,2 @@ | ||
const fetch = require('node-fetch'); | ||
const https = require('https'); | ||
const parseString = require('xml2js').parseString; | ||
@@ -10,22 +10,2 @@ | ||
class ClinicalTrial { | ||
/* | ||
* Internal request function that parses xml response and returns a JSON result | ||
*/ | ||
static async request(query) { | ||
return new Promise(resolve => { | ||
fetch(query) | ||
.then(response => response.text()) | ||
.then(xml => { | ||
parseString(xml, {explicitArray: false}, function (err, result) { | ||
if (err) { | ||
throw err; | ||
} else { | ||
resolve(result); | ||
} | ||
}); | ||
}); | ||
}); | ||
} | ||
/** | ||
@@ -57,3 +37,3 @@ * @typedef {object} SearchProps | ||
return await this.request(query).then(result => result.search_results.clinical_study); | ||
return await httpGetAsync(query).then(result => result.search_results.clinical_study); | ||
} | ||
@@ -70,6 +50,42 @@ | ||
return await this.request(query).then(result => result.clinical_study); | ||
return await httpGetAsync(query).then(result => result.clinical_study); | ||
} | ||
} | ||
/* | ||
* Parse response XML and return formatted JSON | ||
*/ | ||
const parseXML = (xml) => { | ||
let response; | ||
parseString(xml, { | ||
explicitArray: false, | ||
mergeAttrs: true, | ||
normalize: true, | ||
}, (err, result) => { | ||
if (!err) { | ||
response = result; | ||
} else { throw err }; | ||
}); | ||
return response; | ||
} | ||
/* | ||
* Make an async request using https | ||
*/ | ||
const httpGetAsync = async (query, callback) => { | ||
return new Promise((resolve, reject) => { | ||
const request = https.get(query, response => { | ||
if (response.statusCode < 200 || response.statusCode > 299) { | ||
reject(new Error('Failed to load page, status code: ' + response.statusCode)); | ||
}; | ||
let data = ''; | ||
response.on('data', chunk => {data += chunk}); | ||
response.on('end', () => { | ||
resolve(parseXML(data)); | ||
}); | ||
}); | ||
request.on('error', (error) => reject(error)); | ||
}); | ||
} | ||
module.exports = ClinicalTrial; |
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
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
38516
1
7
1010
0
2
- Removednode-fetch@^1.7.3
- Removedencoding@0.1.13(transitive)
- Removediconv-lite@0.6.3(transitive)
- Removedis-stream@1.1.0(transitive)
- Removednode-fetch@1.7.3(transitive)
- Removedsafer-buffer@2.1.2(transitive)