Comparing version 0.4.0 to 0.5.0
@@ -0,0 +0,0 @@ |
@@ -0,0 +0,0 @@ var gulp = require('gulp'); |
@@ -0,0 +0,0 @@ 'use strict'; |
{ | ||
"name": "node-ncbi", | ||
"version": "0.4.0", | ||
"version": "0.5.0", | ||
"description": "Access and parse the NCBI eUtils API in Node or the Browser", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -0,0 +0,0 @@ # node-ncbi |
@@ -20,3 +20,3 @@ const update = require('react-addons-update'); | ||
Gateway.getBase = function() { | ||
return this.base = 'http://eutils.ncbi.nlm.nih.gov/entrez/eutils/' + this.settings.utility + '.fcgi?'; | ||
return this.base = 'https://eutils.ncbi.nlm.nih.gov/entrez/eutils/' + this.settings.utility + '.fcgi?'; | ||
} | ||
@@ -23,0 +23,0 @@ |
@@ -72,4 +72,13 @@ 'use strict'; | ||
}); | ||
} | ||
}, | ||
pmcFullText: (id) => createGateway({ | ||
utility: 'efetch', | ||
params: { | ||
db: 'pmc', | ||
retmode: 'xml', | ||
id: id | ||
} | ||
}) | ||
} |
@@ -0,0 +0,0 @@ const parseString = require('xml2js').parseString; |
@@ -73,4 +73,26 @@ 'use strict'; | ||
return gateways.pubmedRecord(pmid).resolve(queries.abstract); | ||
}, | ||
isOa: function(pmid) { | ||
return this.summary(pmid).then(summary => { | ||
if (!summary) { | ||
return null; | ||
} else { | ||
const pmcid = summary.pmc; | ||
return gateways.pmcFullText(pmcid).resolve(queries.isOa); | ||
} | ||
}); | ||
}, | ||
fulltext: function(pmid) { | ||
return this.summary(pmid).then(summary => { | ||
if (!summary) { | ||
return null; | ||
} else { | ||
const pmcid = summary.pmc; | ||
return gateways.pmcFullText(pmcid).send().then(res => res.body); | ||
} | ||
}); | ||
} | ||
} |
@@ -133,2 +133,7 @@ const update = require('react-addons-update'); | ||
return values; | ||
}, | ||
isOa: (data) => { | ||
const nodes = queries.deepSearch('body', data); | ||
return !!nodes.length; | ||
} | ||
@@ -135,0 +140,0 @@ |
@@ -0,0 +0,0 @@ const update = require('react-addons-update'); |
@@ -0,0 +0,0 @@ { |
@@ -0,0 +0,0 @@ { |
@@ -0,0 +0,0 @@ { |
@@ -0,0 +0,0 @@ { |
197
test/test.js
/* eslint-env mocha, node */ | ||
const check = require('check-types').assert; | ||
//test the tests | ||
var assert = require('assert'); | ||
//test the tests | ||
var assert = require('assert') | ||
describe('Array', function() { | ||
@@ -27,3 +26,3 @@ describe('#indexOf()', function() { | ||
it('should build a valid search url from parameters', function() { | ||
assert.equal(search.generateUrl(), 'http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?retmode=json&db=pubmed&term=ydenberg%20ca&retstart=0&retmax=10'); | ||
assert.equal(search.generateUrl(), 'https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?retmode=json&db=pubmed&term=ydenberg%20ca&retstart=0&retmax=10'); | ||
}); | ||
@@ -39,3 +38,3 @@ }); | ||
it('should build a valid link url from parameters', function() { | ||
assert.equal(links.generateUrl(), 'http://eutils.ncbi.nlm.nih.gov/entrez/eutils/elink.fcgi?retmode=json&db=pubmed&dbfrom=pubmed&cmd=neighbor&id=22588722'); | ||
assert.equal(links.generateUrl(), 'https://eutils.ncbi.nlm.nih.gov/entrez/eutils/elink.fcgi?retmode=json&db=pubmed&dbfrom=pubmed&cmd=neighbor&id=22588722'); | ||
}); | ||
@@ -46,189 +45,11 @@ }); | ||
describe('PMC full text gateway', () => { | ||
describe('generateUrl', () => { | ||
/** | ||
* PARSERS | ||
* | ||
*/ | ||
/** | ||
* Define helper functions to get JSON data as JavaScript so that we can | ||
* query it | ||
*/ | ||
function getDoc(filename, callback) { | ||
const parse = require('../src/gateways/parse'); | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
fs.readFile(path.join(__dirname, 'docs', filename), 'UTF-8', (err, data) => { | ||
callback(err, parse(data)); | ||
}); | ||
} | ||
/** Define helper function to determine if an object is a pubmed summary */ | ||
function isPubmedSummary(obj) { | ||
check.number(obj.pmid); | ||
check.object(obj.raw); | ||
check.string(obj.title); | ||
check.string(obj.authors); | ||
check.emptyString(obj.abstract); | ||
check.string(obj.pubDate); | ||
} | ||
describe('Summary parser', function() { | ||
const sq = require('../src/queries/summaries'); | ||
// Parser of a single summary | ||
describe('formatAuthors', function() { | ||
it('should return the article authors as a string', function() { | ||
const authors = [ | ||
{name: 'Ydenberg CA'}, | ||
{name: 'Johnstone A'} | ||
] | ||
var result = sq.formatAuthors(authors); | ||
assert.equal('Ydenberg CA, Johnstone A', result); | ||
it('should build a valid url from parameters', () => { | ||
const fetch = createGateway.pmcFullText(3315798); | ||
assert.equal(fetch.generateUrl(), 'https://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?retmode=xml&db=pmc&id=3315798'); | ||
}); | ||
it("should return an empty string in response to an empty array", function() { | ||
var result = sq.formatAuthors([]) | ||
check.emptyString(result); | ||
}); | ||
}); | ||
describe('summary', function() { | ||
it("should return an object containing the important data at the top level and the entire summary embedded under the 'raw' sub-object", function(done) { | ||
getDoc('summary_single.json', (err, contents) => { | ||
const result = sq.summary(contents); | ||
isPubmedSummary(result); | ||
done(); | ||
}) | ||
}); | ||
}); | ||
describe("sort", function() { | ||
it("should sort by reverse publication date order, by default", function(done) { | ||
const papers = [ | ||
{pubDate: '1990'}, | ||
{pubDate: '2010'}, | ||
{pubDate: '2000'} | ||
]; | ||
const result = sq.sortSummaries(papers); | ||
assert.equal(result[0].pubDate, 2010); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
describe('parser', function() { | ||
var q = require('../src/queries'); | ||
describe('count', function() { | ||
it('should find the count field in a JSON search result', function(done) { | ||
getDoc('search.json', function(err, contents) { | ||
assert.equal(q.count(contents), 9); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
describe('ids', function() { | ||
it('should return an array of ids', function(done) { | ||
getDoc('search.json', function(err, contents) { | ||
assert.equal(q.ids(contents).length, 9); | ||
done(); | ||
}) | ||
}); | ||
}); | ||
describe('summary', function() { | ||
it('should find all of the info for each summary in the result set', function(done) { | ||
getDoc('summary.json', function(err, contents) { | ||
q.summaries(contents).forEach(summary => { | ||
isPubmedSummary(summary); | ||
}) | ||
done(); | ||
}); | ||
}); | ||
}); | ||
describe('abstract', function() { | ||
it('should retrieve the abstract from an xml string', function(done) { | ||
getDoc('fetch.xml', function(err, contents) { | ||
assert.equal(typeof q.abstract(contents), 'string'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
describe('findLinks', function() { | ||
it('should find all of the papers that have cited this one', function(done) { | ||
getDoc('elink.json', function(err, contents) { | ||
assert.equal(q.findLinks('pubmed_pubmed_citedin', contents).length, 2); | ||
done(); | ||
}); | ||
}) | ||
}); | ||
}); | ||
var pubmed = require('../src/pubmed'); | ||
describe('Pubmed module', function() { | ||
this.timeout(10000); | ||
it('should perform a search', function(done) { | ||
pubmed.search('ydenberg ca').then(results => { | ||
results.papers.forEach(isPubmedSummary); | ||
done(); | ||
}) | ||
}); | ||
it('should return papers that cite this one', function(done) { | ||
pubmed.citedBy(19188495).then(results => { | ||
results.forEach(isPubmedSummary); | ||
done(); | ||
}); | ||
}); | ||
it('should return papers that are similar to this one', function(done) { | ||
pubmed.similar(19188495).then(results => { | ||
results.forEach(isPubmedSummary); | ||
done(); | ||
}); | ||
}); | ||
it('should return a count of 0 if the search returns no results', function(done) { | ||
pubmed.search('boioioioioioioioioioioing').then(results => { | ||
assert.equal(results.count, 0); | ||
done(); | ||
}) | ||
}); | ||
it('should return null if an invalid pmid is passed', function(done) { | ||
pubmed.summary(0).then(results => { | ||
assert.equal(results, null); | ||
done(); | ||
}); | ||
}); | ||
it('should return an empty array if an invalid pmid is passed to a linking method', function(done) { | ||
pubmed.citedBy(0).then(results => { | ||
assert.equal(results.length, 0); | ||
done(); | ||
}); | ||
}); | ||
it('should return null if an invalid pmid is passed to the abstract method', function(done) { | ||
pubmed.abstract(0).then(results => { | ||
assert.equal(results, null); | ||
done(); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Network access
Supply chain riskThis module accesses the network.
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
232228
25
2479
1