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

node-ncbi

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-ncbi - npm Package Compare versions

Comparing version 0.7.0 to 0.7.1

9

package.json
{
"name": "node-ncbi",
"version": "0.7.0",
"version": "0.7.1",
"description": "Access and parse the NCBI eUtils API in Node or the Browser",

@@ -27,6 +27,4 @@ "keywords": [

"dependencies": {
"check-types": "^7.0.1",
"immutability-helper": "^3.1.1",
"popsicle": "^9.2.0",
"react": "^15.3.2",
"react-addons-update": "^15.0.2",
"xml2js": "^0.4.9"

@@ -36,3 +34,4 @@ },

"babel-preset-es2015": "^6.24.1",
"mocha": "^6.1.4",
"check-types": "^7.0.1",
"mocha": "^10.1.0",
"open": "^6.3.0"

@@ -39,0 +38,0 @@ },

@@ -1,5 +0,5 @@

const update = require('react-addons-update');
const popsicle = require('popsicle');
const update = require("immutability-helper");
const popsicle = require("popsicle");
const parse = require('./parse');
const parse = require("./parse");

@@ -11,3 +11,3 @@ /**

* http://www.ncbi.nlm.nih.gov/books/NBK25500/
*/
*/

@@ -20,5 +20,8 @@ var Gateway = {};

*/
Gateway.getBase = function() {
return this.base = 'https://eutils.ncbi.nlm.nih.gov/entrez/eutils/' + this.settings.utility + '.fcgi?';
}
Gateway.getBase = function () {
return (this.base =
"https://eutils.ncbi.nlm.nih.gov/entrez/eutils/" +
this.settings.utility +
".fcgi?");
};

@@ -30,9 +33,9 @@ /**

*/
Gateway.generateUrl = function() {
Gateway.generateUrl = function () {
var url = this.getBase();
for (var key in this.settings.params) {
try {
url += key + '=' + this.settings.params[key].toString();
url += '&';
} catch(e) {
url += key + "=" + this.settings.params[key].toString();
url += "&";
} catch (e) {
//skip if this parameter cannot be converted to a string

@@ -45,3 +48,3 @@ continue;

return encodeURI(url);
}
};

@@ -53,11 +56,10 @@ /**

*/
Gateway.send = function() {
Gateway.send = function () {
var url = this.generateUrl();
return popsicle.get({
method: 'GET',
url: url
method: "GET",
url: url,
});
}
};
/**

@@ -72,4 +74,4 @@ * Send off the request and parse the returned data.

*/
Gateway.resolve = function(query) {
return this.send().then(res => {
Gateway.resolve = function (query) {
return this.send().then((res) => {
const dataObj = parse(res.body);

@@ -81,29 +83,32 @@ return query(dataObj);

/**
* Use an Object literal to instatiate via the setup method:
* @arg: documentType: string | 'esearch', 'esummary', 'efetch', 'einfo', see
* http://www.ncbi.nlm.nih.gov/books/NBK25499/ for more info
* @arg: responseType: string | 'json', 'xml', 'text'
* @arg: params: Object | indexed object of other URL parameters, eg 'term' (for searches),
* 'retstart', 'retmax'
* @arg: test: Boolean | enable test mode. When in test mode, an actual call will
* never happen, the search method will return a simple Promise instead.
*/
module.exports = function(args) {
* Use an Object literal to instatiate via the setup method:
* @arg: documentType: string | 'esearch', 'esummary', 'efetch', 'einfo', see
* http://www.ncbi.nlm.nih.gov/books/NBK25499/ for more info
* @arg: responseType: string | 'json', 'xml', 'text'
* @arg: params: Object | indexed object of other URL parameters, eg 'term' (for searches),
* 'retstart', 'retmax'
* @arg: test: Boolean | enable test mode. When in test mode, an actual call will
* never happen, the search method will return a simple Promise instead.
*/
module.exports = function (args) {
const defaults = {
utility: 'esearch',
utility: "esearch",
params: {
retmode: 'json',
db: 'pubmed'
}
retmode: "json",
db: "pubmed",
},
};
let settings = update(defaults, {$merge: args, params: {$merge: args.params}});
let settings = update(defaults, {
$merge: args,
params: { $merge: args.params },
});
if (process.env.NCBI_API_KEY) {
settings = update(settings, {params:
{$merge: {api_key: process.env.NCBI_API_KEY} }
})
settings = update(settings, {
params: { $merge: { api_key: process.env.NCBI_API_KEY } },
});
}
const gateway = Object.assign(Object.create(Gateway), {
settings: settings
settings: settings,
});
return gateway;
}
};

@@ -1,4 +0,4 @@

const update = require('react-addons-update');
const update = require("immutability-helper");
const summaryQueries = require('./summaries');
const summaryQueries = require("./summaries");

@@ -15,21 +15,21 @@ const queries = {

*/
deepSearch: function _deepSearch(find, data) {
var found = [];
//if data is not an object, return an empty array.
if (typeof data !== 'object') {
return found;
}
//go through each property, and assign it to found if the key
//matches the key we're looking for
Object.keys(data).forEach(key => {
const value = data[key];
if (String(key).toLowerCase() === String(find).toLowerCase()) {
found.push(value);
}
//now add in the nodes from the sub-object. If the value of the
//property is not an object, deepSearch will just return an empty array.
found = found.concat(_deepSearch(find, value));
});
return found;
},
deepSearch: function _deepSearch(find, data) {
var found = [];
//if data is not an object, return an empty array.
if (typeof data !== "object") {
return found;
}
//go through each property, and assign it to found if the key
//matches the key we're looking for
Object.keys(data).forEach((key) => {
const value = data[key];
if (String(key).toLowerCase() === String(find).toLowerCase()) {
found.push(value);
}
//now add in the nodes from the sub-object. If the value of the
//property is not an object, deepSearch will just return an empty array.
found = found.concat(_deepSearch(find, value));
});
return found;
},

@@ -48,7 +48,7 @@ /**

nodeValue: function nodeValue(node) {
if (typeof node === 'string') {
if (typeof node === "string") {
return node;
} else if (Array.isArray(node)) {
return nodeValue(node[0]);
} else if (typeof node === 'object') {
} else if (typeof node === "object") {
return nodeValue(node._);

@@ -65,12 +65,14 @@ } else {

*/
nodeValues: function(nodes) {
return update(nodes, {$apply: (node) => {
return queries.nodeValue(node);
}});
nodeValues: function (nodes) {
return update(nodes, {
$apply: (node) => {
return queries.nodeValue(node);
},
});
},
count: function(data) {
count: function (data) {
try {
return data.esearchresult.count;
} catch(e) {
} catch (e) {
return 0;

@@ -80,6 +82,6 @@ }

ids: function(data) {
ids: function (data) {
try {
return data.esearchresult.idlist;
} catch(e) {
} catch (e) {
return [];

@@ -89,10 +91,10 @@ }

summaries: function(data) {
summaries: function (data) {
var found = [];
try {
var results = data.result;
} catch(e) {
} catch (e) {
return [];
}
Object.keys(results).forEach(key => {
Object.keys(results).forEach((key) => {
//papers are indexed by their uid, so if the key can be a number,

@@ -114,7 +116,7 @@ // we should include it in the summary array. Otherwise we should skip it.

*/
findLinks: function(linkname, data) {
findLinks: function (linkname, data) {
try {
var linksets = [];
//have not found a case where there is more than one linkset
data.linksets[0].linksetdbs.forEach(linksetdb => {
data.linksets[0].linksetdbs.forEach((linksetdb) => {
if (linksetdb.linkname === linkname) {

@@ -125,3 +127,3 @@ linksets = linksets.concat(linksetdb.links);

return linksets;
} catch(e) {
} catch (e) {
return [];

@@ -136,4 +138,4 @@ }

*/
abstract: function(data) {
const nodes = queries.deepSearch('abstracttext', data);
abstract: function (data) {
const nodes = queries.deepSearch("abstracttext", data);
const values = queries.nodeValues(nodes);

@@ -144,8 +146,7 @@ return values;

isOa: (data) => {
const nodes = queries.deepSearch('body', data);
const nodes = queries.deepSearch("body", data);
return !!nodes.length;
}
},
};
}
module.exports = queries;
/* eslint-env mocha, node */
const check = require('check-types').assert;
const check = require("check-types").assert;
module.exports = {
/**

@@ -11,14 +10,17 @@ * Define helper functions to get JSON data as JavaScript so that we can

*/
getDoc: function(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));
});
getDoc: function (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 */
isPubmedSummary: function(obj) {
isPubmedSummary: function (obj) {
check.object(obj.raw);

@@ -29,4 +31,3 @@ check.string(obj.pubDate);

check.number(obj.pmid);
}
}
},
};
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