sdf-parser
Version:
56 lines • 2 kB
TypeScript
/**
* A molecule entry returned by the {@link iterator} async generator.
* The `molfile` field contains the raw V2000/V3000 molfile block.
* Additional fields are populated from the SDF `> <field>` sections.
*/
export interface IteratorMolecule {
/** The raw V2000/V3000 molfile block. */
molfile: string;
[label: string]: any;
}
/**
* Options for the {@link iterator} async generator.
*/
export interface IteratorOptions {
/**
* End-of-line character used to split field entries.
* @default '\n'
*/
eol?: string;
/**
* Controls EOL normalisation before splitting on `$$$$`.
* - `undefined` (default): inspect the first 10 000 characters; normalise only if `\r` is detected.
* - `true`: always normalise CR and CRLF to LF.
* - `false`: never normalise; use when the file is known to be pure LF.
*/
mixedEOL?: boolean;
/**
* When `true`, numeric string values are automatically converted to numbers.
* @default true
*/
dynamicTyping?: boolean;
/**
* A predicate function to filter molecules. Only molecules for which this
* function returns `true` are yielded.
*/
filter?: (molecule: IteratorMolecule) => boolean;
}
/**
* Asynchronously iterate over molecules from a text-decoded SDF stream.
* @param readStream - A `ReadableStream<string>` supplying SDF text content.
* @param options - Iterator options.
* @yields {IteratorMolecule} Individual molecule objects.
* @example
* ```ts
* import { openAsBlob } from 'node:fs';
* import { iterator } from 'sdf-parser';
*
* const blob = await openAsBlob('compounds.sdf');
* const textDecoder = new TextDecoderStream();
* for await (const molecule of iterator(blob.stream().pipeThrough(textDecoder))) {
* console.log(molecule.molfile);
* }
* ```
*/
export declare function iterator(readStream: ReadableStream<string>, options?: IteratorOptions): AsyncGenerator<IteratorMolecule>;
//# sourceMappingURL=iterator.d.ts.map