{"library":"sdf-parser","title":"SDF Parser","description":"sdf-parser is a JavaScript/TypeScript library designed to parse Structure-Data File (SDF) format files, which are commonly used in cheminformatics to represent chemical structures and associated data. It efficiently converts the content of SDF files into an array of JavaScript objects, where each object represents a chemical entry including its molfile and associated data fields. The current stable version is 8.0.0. The package maintains an active release cadence, with frequent updates. Key features include robust parsing with options for field inclusion/exclusion, custom data transformations via modifiers, and filtering capabilities based on entry properties. For processing large SDF files, it offers an `iterator` API that leverages web streams for memory-efficient handling, compatible with both Node.js and browser environments.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install sdf-parser"],"cli":null},"imports":["import { parse } from 'sdf-parser';","import { iterator } from 'sdf-parser';","import type { SDFEntry } from 'sdf-parser';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { parse, iterator } from 'sdf-parser';\nimport { Readable } from 'node:stream'; // For Node.js to create a stream from string\nimport { TextDecoderStream } from 'node:stream/web'; // For Node.js compatibility with Web Streams API\n\n// Example SDF content with multiple entries\nconst sdfData = `\nMOLFILE\n  -OEChem-0104201804252D\n\n  5  5  0  0  0  0  0  0  0  0999 V2000\n    0.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n    1.5000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n    0.0000    1.5000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n    1.5000    1.5000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n    3.0000    0.0000    0.0000 O   0  0  0  0  0  0  0  0  0  0  0  0\n  1  2  1  0  0  0  0\n  1  3  1  0  0  0  0\n  2  4  1  0  0  0  0\n  3  4  1  0  0  0  0\n  2  5  1  0  0  0  0\nM  END\n> <ID>\nCHEM_1\n> <CLogP>\n2.5\n$$$$\nMOLFILE\n  -OEChem-0104201804252D\n\n  3  2  0  0  0  0  0  0  0  0999 V2000\n    0.0000    0.0000    0.0000 N   0  0  0  0  0  0  0  0  0  0  0  0\n    1.5000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n    3.0000    0.0000    0.0000 O   0  0  0  0  0  0  0  0  0  0  0  0\n  1  2  1  0  0  0  0\n  2  3  1  0  0  0  0\nM  END\n> <ID>\nCHEM_2\n> <CLogP>\n-1.2\n$$$$\n`;\n\n// --- Example 1: Parsing a full SDF string synchronously ---\nconst parsedEntries = parse(sdfData, {\n  include: ['ID', 'CLogP'],\n  modifiers: {\n    CLogP: (value: string) => parseFloat(value) // Convert CLogP field to a number\n  },\n  filter: (entry: any) => entry.CLogP > 0 // Keep only entries with positive CLogP\n});\n\nconsole.log('Parsed Entries (filtered by CLogP > 0):', parsedEntries);\n\n// --- Example 2: Iterating over an SDF stream (for large files) ---\nasync function processSDFStream() {\n  // In Node.js, create a ReadableStream from string data.\n  // For actual files, use `fs.createReadStream('your.sdf').pipeThrough(new TextDecoderStream())`\n  const streamFromData = Readable.from([sdfData])\n    .pipeThrough(new TextDecoderStream()); // Crucial for v7.0.0+ for iterator\n\n  const iteratedEntries = [];\n  try {\n    for await (const entry of iterator(streamFromData)) {\n      iteratedEntries.push(entry);\n    }\n    console.log('Iterated Entries (all from stream):', iteratedEntries);\n  } catch (error) {\n    console.error('Error during stream iteration:', error);\n  }\n}\n\nprocessSDFStream();","lang":"typescript","description":"This quickstart demonstrates both the synchronous `parse` function for smaller SDF strings, including options for filtering and modifying fields, and the asynchronous `iterator` function for efficient processing of larger SDF data via streams, highlighting the `TextDecoderStream` requirement.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}