sdf-parser 7.0.3 → 7.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -43,8 +43,7 @@ function getEntriesBoundaries(string, substring, eol) {
43
43
  function getMolecule$1(sdfPart, labels, currentLabels, options) {
44
44
  let parts = sdfPart.split(`${options.eol}>`);
45
45
  if (parts.length === 0 || parts[0].length <= 5) return;
46
- let molecule = {};
47
- molecule.molfile = parts[0] + options.eol;
46
+ let molecule = { molfile: parts[0] + options.eol };
48
47
  for (let j = 1; j < parts.length; j++) {
49
48
  let lines = parts[j].split(options.eol);
50
49
  let from = lines[0].indexOf('<');
@@ -108,6 +107,7 @@ function getMolecule$1(sdfPart, labels, currentLabels, options) {
108
107
  * @param {object} [options.modifiers] - Object containing callbacks to apply on some specific fields
109
108
  * @param {boolean} [options.mixedEOL=false] - Set to true if you know there is a mixture between \r\n and \n
110
109
  * @param {string} [options.eol] - Specify the end of line character. Default will be the one found in the file
110
+ * @returns {object} - Object containing the molecules, the labels and the statistics
111
111
  */
112
112
  function parse(sdf, options = {}) {
113
113
  options = { ...options };
@@ -148,7 +148,7 @@ function parse(sdf, options = {}) {
148
148
 
149
149
  for (let i = 0; i < entriesBoundaries.length; i++) {
150
150
  let sdfPart = sdf.slice(...entriesBoundaries[i]);
151
-
151
+ if (sdfPart.length < 40) continue;
152
152
  let currentLabels = [];
153
153
  const molecule = getMolecule$1(sdfPart, labels, currentLabels, options);
154
154
  if (!molecule) continue;
@@ -224,14 +224,16 @@ class MolfileStream extends TransformStream {
224
224
  }
225
225
  const eolLength = this.#buffer[endOfDelimiter - 1] === '\r' ? 2 : 1;
226
226
  // need to remove the last eol because we will split on eol+'>' in getMolecule
227
- controller.enqueue(this.#buffer.slice(begin, index - eolLength));
227
+ if (index - eolLength - begin > 40) {
228
+ controller.enqueue(this.#buffer.slice(begin, index - eolLength));
229
+ }
228
230
  index = endOfDelimiter + eolLength;
229
231
  begin = index;
230
232
  }
231
233
  this.#buffer = this.#buffer.slice(begin);
232
234
  },
233
235
  flush: (controller) => {
234
- if (this.#buffer) {
236
+ if (this.#buffer && this.#buffer.length > 40) {
235
237
  controller.enqueue(this.#buffer);
236
238
  }
237
239
  },
@@ -253,7 +255,6 @@ async function* iterator(readStream, options = {}) {
253
255
 
254
256
  const moleculeStream = readStream.pipeThrough(new MolfileStream({ eol }));
255
257
  for await (const entry of moleculeStream) {
256
- if (entry.length < 20) continue;
257
258
  const molecule = getMolecule(entry, {
258
259
  eol,
259
260
  dynamicTyping,
@@ -276,8 +277,7 @@ function getMolecule(sdfPart, options) {
276
277
  const { eol, dynamicTyping: dynamicTyping$1 } = options;
277
278
  let parts = sdfPart.split(`${eol}>`);
278
279
  if (parts.length === 0 || parts[0].length <= 5) return;
279
- let molecule = {};
280
- molecule.molfile = parts[0] + eol;
280
+ let molecule = { molfile: parts[0] + eol };
281
281
  for (let j = 1; j < parts.length; j++) {
282
282
  let lines = parts[j].split(eol);
283
283
  let from = lines[0].indexOf('<');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sdf-parser",
3
- "version": "7.0.3",
3
+ "version": "7.0.5",
4
4
  "description": "SDF parser",
5
5
  "main": "lib/index.js",
6
6
  "module": "src/index.js",
@@ -39,21 +39,19 @@
39
39
  },
40
40
  "homepage": "https://github.com/cheminfo/sdf-parser",
41
41
  "devDependencies": {
42
- "@babel/plugin-transform-modules-commonjs": "^7.26.3",
43
- "@types/node": "^22.13.5",
44
- "@vitest/coverage-v8": "^3.0.7",
45
- "babel-eslint": "^10.1.0",
42
+ "@types/node": "^25.2.3",
43
+ "@vitest/coverage-v8": "^4.0.18",
46
44
  "callback-stream": "^1.1.0",
47
- "cheminfo-build": "^1.2.1",
45
+ "cheminfo-build": "^1.3.2",
48
46
  "eslint": "^9.21.0",
49
- "eslint-config-cheminfo": "^13.0.0",
50
- "file-collection": "^1.0.0",
51
- "openchemlib": "^8.18.1",
52
- "prettier": "^3.5.2",
53
- "vitest": "^3.0.7"
47
+ "eslint-config-cheminfo": "^17.1.0",
48
+ "file-collection": "^6.6.0",
49
+ "openchemlib": "^9.20.0",
50
+ "prettier": "^3.8.1",
51
+ "vitest": "^4.0.18"
54
52
  },
55
53
  "dependencies": {
56
54
  "dynamic-typing": "^1.0.1",
57
- "ensure-string": "^1.2.0"
55
+ "ensure-string": "^2.0.0"
58
56
  }
59
57
  }
@@ -17,14 +17,16 @@ export class MolfileStream extends TransformStream {
17
17
  }
18
18
  const eolLength = this.#buffer[endOfDelimiter - 1] === '\r' ? 2 : 1;
19
19
  // need to remove the last eol because we will split on eol+'>' in getMolecule
20
- controller.enqueue(this.#buffer.slice(begin, index - eolLength));
20
+ if (index - eolLength - begin > 40) {
21
+ controller.enqueue(this.#buffer.slice(begin, index - eolLength));
22
+ }
21
23
  index = endOfDelimiter + eolLength;
22
24
  begin = index;
23
25
  }
24
26
  this.#buffer = this.#buffer.slice(begin);
25
27
  },
26
28
  flush: (controller) => {
27
- if (this.#buffer) {
29
+ if (this.#buffer && this.#buffer.length > 40) {
28
30
  controller.enqueue(this.#buffer);
29
31
  }
30
32
  },
package/src/iterator.js CHANGED
@@ -16,7 +16,6 @@ export async function* iterator(readStream, options = {}) {
16
16
 
17
17
  const moleculeStream = readStream.pipeThrough(new MolfileStream({ eol }));
18
18
  for await (const entry of moleculeStream) {
19
- if (entry.length < 20) continue;
20
19
  const molecule = getMolecule(entry, {
21
20
  eol,
22
21
  dynamicTyping,
@@ -39,8 +38,7 @@ function getMolecule(sdfPart, options) {
39
38
  const { eol, dynamicTyping } = options;
40
39
  let parts = sdfPart.split(`${eol}>`);
41
40
  if (parts.length === 0 || parts[0].length <= 5) return;
42
- let molecule = {};
43
- molecule.molfile = parts[0] + eol;
41
+ let molecule = { molfile: parts[0] + eol };
44
42
  for (let j = 1; j < parts.length; j++) {
45
43
  let lines = parts[j].split(eol);
46
44
  let from = lines[0].indexOf('<');
package/src/parse.js CHANGED
@@ -13,6 +13,7 @@ import { getMolecule } from './util/getMolecule';
13
13
  * @param {object} [options.modifiers] - Object containing callbacks to apply on some specific fields
14
14
  * @param {boolean} [options.mixedEOL=false] - Set to true if you know there is a mixture between \r\n and \n
15
15
  * @param {string} [options.eol] - Specify the end of line character. Default will be the one found in the file
16
+ * @returns {object} - Object containing the molecules, the labels and the statistics
16
17
  */
17
18
  export function parse(sdf, options = {}) {
18
19
  options = { ...options };
@@ -53,7 +54,7 @@ export function parse(sdf, options = {}) {
53
54
 
54
55
  for (let i = 0; i < entriesBoundaries.length; i++) {
55
56
  let sdfPart = sdf.slice(...entriesBoundaries[i]);
56
-
57
+ if (sdfPart.length < 40) continue;
57
58
  let currentLabels = [];
58
59
  const molecule = getMolecule(sdfPart, labels, currentLabels, options);
59
60
  if (!molecule) continue;
@@ -9,8 +9,7 @@
9
9
  export function getMolecule(sdfPart, labels, currentLabels, options) {
10
10
  let parts = sdfPart.split(`${options.eol}>`);
11
11
  if (parts.length === 0 || parts[0].length <= 5) return;
12
- let molecule = {};
13
- molecule.molfile = parts[0] + options.eol;
12
+ let molecule = { molfile: parts[0] + options.eol };
14
13
  for (let j = 1; j < parts.length; j++) {
15
14
  let lines = parts[j].split(options.eol);
16
15
  let from = lines[0].indexOf('<');