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

sdf-parser

Package Overview
Dependencies
Maintainers
3
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sdf-parser - npm Package Compare versions

Comparing version 2.0.1 to 2.2.0

2

bower.json
{
"name": "sdf-parser",
"version": "2.0.1",
"version": "2.2.0",
"main": [

@@ -5,0 +5,0 @@ "dist/sdf-parser.js",

{
"name": "sdf-parser",
"version": "2.0.1",
"version": "2.2.0",
"description": "SDF parser",

@@ -5,0 +5,0 @@ "main": "./src/index.js",

@@ -31,3 +31,31 @@ # sdf-parser

## require('sdf-parser') (sdf, options)
options:
* exclude : array of string containing the fields to discard
* include : array of string containing the fields to keep
* modifiers : object of functions that need to be converted during the parsing
* filter : function that allows to filter the result
## Advanced example with filtering and modifiers
```
var result = parse(sdf, {
exclude:["Number of H-Donors"],
include:["Number of H-Donors",'CLogP','Code'],
modifiers: {
CLogP: function(field) {
return {
low: field*1-0.2,
high: field*1+0.2
}
}
},
filter: function(entry) {
return (entry.CLogP && entry.CLogP.low>4);
}
});
```
## Test

@@ -34,0 +62,0 @@

'use strict';
function parse(sdf) {
function parse(sdf, options) {
var options=options || {};
var include=options.include;
var exclude=options.exclude;
var filter=options.filter;
var modifiers=options.modifiers || {};
var forEach=options.forEach || {};
if (typeof sdf !== 'string') {

@@ -21,38 +27,55 @@ throw new TypeError('Parameter "sdf" must be a string');

var start = Date.now();
var i = 0, ii = sdfParts.length,
sdfPart, parts, molecule, j, jj,
lines, from, to, label, k, kk;
for (; i < ii; i++) {
sdfPart = sdfParts[i];
parts = sdfPart.split(crlf + '>');
for (var i=0; i < sdfParts.length; i++) {
var sdfPart = sdfParts[i];
var parts = sdfPart.split(crlf + '>');
if (parts.length > 0 && parts[0].length > 5) {
molecule = {};
molecules.push(molecule);
var molecule = {};
var currentLabels=[];
molecule.molfile = parts[0] + crlf;
jj = parts.length;
for (j = 1; j < jj; j++) {
lines = parts[j].split(crlf);
from = lines[0].indexOf('<');
to = lines[0].indexOf('>');
label = lines[0].substring(from + 1, to);
if (labels[label]) {
labels[label].counter++;
} else {
labels[label] = {counter: 1, isNumeric: true};
}
kk = lines.length - 1;
for (k = 1; k < kk; k++) {
if (molecule[label]) {
molecule[label] += crlf + lines[k];
} else {
molecule[label] = lines[k];
for (var j = 1; j < parts.length; j++) {
var lines = parts[j].split(crlf);
var from = lines[0].indexOf('<');
var to = lines[0].indexOf('>');
var label = lines[0].substring(from + 1, to);
currentLabels.push(label);
if (! labels[label]) {
labels[label] = {
counter: 0,
isNumeric: true,
keep:false
};
if (exclude && exclude.indexOf(label)>-1) {
} else if (! include || include.indexOf(label)>-1) {
labels[label].keep=true;
if (modifiers[label]) labels[label].modifier=modifiers[label];
if (forEach[label]) labels[label].forEach=forEach[label];
}
}
if (labels[label].isNumeric) {
if (!isFinite(molecule[label])) {
labels[label].isNumeric = false;
if (labels[label].keep) {
for (var k = 1; k < lines.length - 1; k++) {
if (molecule[label]) {
molecule[label] += crlf + lines[k];
} else {
molecule[label] = lines[k];
}
}
if (labels[label].modifier) {
molecule[label]=labels[label].modifier(molecule[label]);
}
if (labels[label].isNumeric) {
if (!isFinite(molecule[label])) {
labels[label].isNumeric = false;
}
}
}
}
if (! filter || filter(molecule)) {
molecules.push(molecule);
// only now we can increase the counter
for (var j=0; j<currentLabels.length; j++) {
var currentLabel=currentLabels[j];
labels[currentLabel].counter++;
}
}
}

@@ -62,3 +85,2 @@ }

// all numeric fields should be converted to numbers
var numericFields = [];
for (var label in labels) {

@@ -65,0 +87,0 @@ var currentLabel = labels[label];

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