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

sdf-parser

Package Overview
Dependencies
Maintainers
6
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.3.1 to 3.0.0

src/stream.browser.js

34

package.json
{
"name": "sdf-parser",
"version": "2.3.1",
"version": "3.0.0",
"description": "SDF parser",
"main": "./src/index.js",
"directories": {
"lib": "src",
"test": "test"
},
"files": [
"src"
],
"scripts": {
"test": "mocha --require should --reporter mocha-better-spec-reporter --recursive",
"eslint": "eslint src __tests__",
"eslint-fix": "npm run eslint -- --fix",
"test": "jest && npm run eslint",
"build": "cheminfo build --root SDFParser"
},
"browser": {
"./src/stream.js": "./src/stream.browser.js"
},
"repository": {

@@ -32,7 +36,17 @@ "type": "git",

"devDependencies": {
"cheminfo-tools": "^1.0.2",
"mocha": "^2.2.5",
"mocha-better-spec-reporter": "^2.1.1",
"should": "^7.0.2"
"callback-stream": "^1.1.0",
"cheminfo-tools": "^1.20.2",
"eslint": "^4.14.0",
"eslint-config-cheminfo": "^1.9.1",
"eslint-plugin-no-only-tests": "^2.0.0",
"jest": "^22.0.4",
"openchemlib": "^5.5.0",
"should": "^13.2.0"
},
"dependencies": {
"multipipe": "^2.0.1",
"split2": "^2.2.0",
"through2": "^2.0.3",
"through2-filter": "^2.0.0"
}
}

@@ -60,13 +60,35 @@ # sdf-parser

## Streams
## Test
This API is only available on Node.js
```bash
npm test
### molecules(options)
Transform an input text stream to a stream of molecule objects.
#### options
- `fullResult`: true to emit the full result of `parse` instead of just the molecules.
- All other options from the `parse` function.
```js
const stream = require('sdf-parser').stream;
fs.createReadStream('test.sdf')
.pipe(stream.molecules())
.on('data', (molecule) => {
console.log(molecule.molfile);
});
```
## Build
### entries()
```bash
npm run build
Transform an input text stream to a stream of sdf entries.
```js
const stream = require('sdf-parser').stream;
fs.createReadStream('test.sdf')
.pipe(stream.entries())
.on('data', (entry) => {
// sdf entry as a string
});
```

@@ -73,0 +95,0 @@

'use strict';
const stream = require('./stream');
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 || {};
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') {

@@ -16,4 +18,4 @@ throw new TypeError('Parameter "sdf" must be a string');

if (options.mixedEOL) {
sdf=sdf.replace(/\r\n/g, "\n");
sdf=sdf.replace(/\r/g, "\n");
sdf = sdf.replace(/\r\n/g, '\n');
sdf = sdf.replace(/\r/g, '\n');
} else {

@@ -29,3 +31,3 @@ // we will find the delimiter in order to be much faster and not use regular expression

var sdfParts = sdf.split(new RegExp(eol+'\\$\\$\\$\\$.*'+eol));
var sdfParts = sdf.split(new RegExp(eol + '\\$\\$\\$\\$.*' + eol));
var molecules = [];

@@ -35,4 +37,4 @@ var labels = {};

var start = Date.now();
for (var i=0; i < sdfParts.length; i++) {
for (var i = 0; i < sdfParts.length; i++) {
var sdfPart = sdfParts[i];

@@ -42,3 +44,3 @@ var parts = sdfPart.split(eol + '>');

var molecule = {};
var currentLabels=[];
var currentLabels = [];
molecule.molfile = parts[0] + eol;

@@ -51,13 +53,15 @@ for (var j = 1; j < parts.length; j++) {

currentLabels.push(label);
if (! labels[label]) {
if (!labels[label]) {
labels[label] = {
counter: 0,
isNumeric: true,
keep:false
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 (
(!exclude || exclude.indexOf(label) === -1) &&
(!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];
}

@@ -74,7 +78,7 @@ }

if (labels[label].modifier) {
var modifiedValue=labels[label].modifier(molecule[label]);
if (modifiedValue===undefined || modifiedValue===null) {
var modifiedValue = labels[label].modifier(molecule[label]);
if (modifiedValue === undefined || modifiedValue === null) {
delete molecule[label];
} else {
molecule[label]=modifiedValue;
molecule[label] = modifiedValue;
}

@@ -89,7 +93,7 @@ }

}
if (! filter || filter(molecule)) {
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];
for (j = 0; j < currentLabels.length; j++) {
var currentLabel = currentLabels[j];
labels[currentLabel].counter++;

@@ -102,8 +106,8 @@ }

// all numeric fields should be converted to numbers
for (var label in labels) {
var currentLabel = labels[label];
for (label in labels) {
currentLabel = labels[label];
if (currentLabel.isNumeric) {
currentLabel.minValue = Infinity;
currentLabel.maxValue = -Infinity;
for (var j = 0; j < molecules.length; j++) {
for (j = 0; j < molecules.length; j++) {
if (molecules[j][label]) {

@@ -129,3 +133,3 @@ var value = parseFloat(molecules[j][label]);

var statistics = [];
for (var key in labels) {
for (key in labels) {
var statistic = labels[key];

@@ -146,1 +150,2 @@ statistic.label = key;

module.exports = parse;
parse.stream = stream;
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