sdf-parser
Advanced tools
Comparing version 2.2.0 to 2.3.1
{ | ||
"name": "sdf-parser", | ||
"version": "2.2.0", | ||
"version": "2.3.1", | ||
"main": [ | ||
@@ -5,0 +5,0 @@ "dist/sdf-parser.js", |
{ | ||
"name": "sdf-parser", | ||
"version": "2.2.0", | ||
"version": "2.3.1", | ||
"description": "SDF parser", | ||
@@ -5,0 +5,0 @@ "main": "./src/index.js", |
@@ -10,3 +10,3 @@ # sdf-parser | ||
## Use of the pacakge | ||
## Use of the package | ||
@@ -39,2 +39,3 @@ ```bash | ||
* filter : function that allows to filter the result | ||
* mixedEOL : if set to true will try to deal with mixed End Of Line separator | ||
@@ -41,0 +42,0 @@ ## Advanced example with filtering and modifiers |
@@ -13,12 +13,18 @@ 'use strict'; | ||
} | ||
// we will find the delimiter in order to be much faster and not use regular expression | ||
var header = sdf.substr(0, 1000); | ||
var crlf = '\n'; | ||
if (header.indexOf('\r\n') > -1) { | ||
crlf = '\r\n'; | ||
} else if (header.indexOf('\r') > -1) { | ||
crlf = '\r'; | ||
var eol = '\n'; | ||
if (options.mixedEOL) { | ||
sdf=sdf.replace(/\r\n/g, "\n"); | ||
sdf=sdf.replace(/\r/g, "\n"); | ||
} else { | ||
// we will find the delimiter in order to be much faster and not use regular expression | ||
var header = sdf.substr(0, 1000); | ||
if (header.indexOf('\r\n') > -1) { | ||
eol = '\r\n'; | ||
} else if (header.indexOf('\r') > -1) { | ||
eol = '\r'; | ||
} | ||
} | ||
var sdfParts = sdf.split(crlf + '$$$$' + crlf); | ||
var sdfParts = sdf.split(new RegExp(eol+'\\$\\$\\$\\$.*'+eol)); | ||
var molecules = []; | ||
@@ -31,9 +37,9 @@ var labels = {}; | ||
var sdfPart = sdfParts[i]; | ||
var parts = sdfPart.split(crlf + '>'); | ||
var parts = sdfPart.split(eol + '>'); | ||
if (parts.length > 0 && parts[0].length > 5) { | ||
var molecule = {}; | ||
var currentLabels=[]; | ||
molecule.molfile = parts[0] + crlf; | ||
molecule.molfile = parts[0] + eol; | ||
for (var j = 1; j < parts.length; j++) { | ||
var lines = parts[j].split(crlf); | ||
var lines = parts[j].split(eol); | ||
var from = lines[0].indexOf('<'); | ||
@@ -59,3 +65,3 @@ var to = lines[0].indexOf('>'); | ||
if (molecule[label]) { | ||
molecule[label] += crlf + lines[k]; | ||
molecule[label] += eol + lines[k]; | ||
} else { | ||
@@ -66,3 +72,8 @@ molecule[label] = lines[k]; | ||
if (labels[label].modifier) { | ||
molecule[label]=labels[label].modifier(molecule[label]); | ||
var modifiedValue=labels[label].modifier(molecule[label]); | ||
if (modifiedValue===undefined || modifiedValue===null) { | ||
delete molecule[label]; | ||
} else { | ||
molecule[label]=modifiedValue; | ||
} | ||
} | ||
@@ -69,0 +80,0 @@ if (labels[label].isNumeric) { |
Sorry, the diff of this file is not supported yet
209225
9
155
85