UNPKG

sdf-parser

Version:
106 lines 3.68 kB
/** * A parsed SDF molecule entry. The `molfile` field contains the raw molfile * string. Additional fields are populated from the SDF `> <field>` sections. */ export interface Molecule { /** The raw V2000/V3000 molfile block. */ molfile: string; [label: string]: any; } /** * Options for the {@link parse} function. */ export interface ParseOptions { /** * Modifier functions applied to field values after parsing. The function * receives the raw string value and may return a transformed value. Returning * `undefined` or `null` removes the field from the molecule. */ modifiers?: Record<string, (value: string) => unknown>; /** * Callback functions called for each field value. The callbacks are stored * on the label info and available in statistics. */ forEach?: Record<string, (value: unknown) => void>; /** * When `true`, numeric string values are automatically converted to numbers. * @default true */ dynamicTyping?: boolean; /** * End-of-line character. Auto-detected from the file content when not set. * Detected as `'\r\n'` for Windows-style files; falls back to `'\n'`. * @default '\n' */ eol?: string; /** * When `true`, normalises all `\r\n` sequences to `\n` before parsing. * Useful for SDF files with Windows-style line endings. * @default false */ mixedEOL?: boolean; /** * Only include fields whose names appear in this list. * When combined with `exclude`, the field must satisfy both constraints. */ include?: string[]; /** * Exclude fields whose names appear in this list. * When combined with `include`, the field must satisfy both constraints. */ exclude?: string[]; /** * A predicate function to filter molecules. Only molecules for which this * function returns `true` are included in the result. */ filter?: (molecule: Molecule) => boolean; } /** * Statistics for a single SDF field label, as returned in * {@link ParseResult.statistics}. */ export interface LabelStatistic { /** Field label name. */ label: string; /** Number of molecules that contain this field. */ counter: number; /** Whether all parsed values are numeric. */ isNumeric: boolean; /** Whether this field is included in the output (not excluded). */ keep: boolean; /** Minimum numeric value, only set when `isNumeric` is `true`. */ minValue?: number; /** Maximum numeric value, only set when `isNumeric` is `true`. */ maxValue?: number; /** Whether every molecule in the result contains this field. */ always: boolean; } /** * Return value of the {@link parse} function. */ export interface ParseResult { /** Wall-clock time taken to parse, in milliseconds. */ time: number; /** Parsed molecule entries. */ molecules: Molecule[]; /** Sorted list of all field label names found in the file. */ labels: string[]; /** Per-label statistics. */ statistics: LabelStatistic[]; } /** * Synchronously parse an SDF file into an array of molecule objects. * @param sdf - The SDF content as a string, `ArrayBuffer`, or `ArrayBufferView`. * @param options - Parsing options. * @returns A {@link ParseResult} containing molecules and statistics. * @example * ```ts * import { readFileSync } from 'node:fs'; * import { parse } from 'sdf-parser'; * * const sdf = readFileSync('compounds.sdf', 'utf8'); * const { molecules, statistics } = parse(sdf); * ``` */ export declare function parse(sdf: unknown, options?: ParseOptions): ParseResult; //# sourceMappingURL=parse.d.ts.map