/** * ChemParse * A TypeScript library for parsing chemical formulas. * * Handles nested parentheses, decimal and scientific notation, * dot-separated parts (hydrates), leading coefficients, element lists * with commas, ionic charges (caret and superscript notation), and particles. * * Supported symbols include all IUPAC element symbols and * common particle symbols (e, p, n, α, β, γ, ν, ν̄). * * Methods: * - parse ( formula: string ) : ChemParseResult * - validate ( formula: string ) : boolean * - compareMany ( ...formulas: string[] ) : boolean * - compare ( a: string, b: string ) : boolean * - diffMany ( ...formulas: string[] ) : ( ChemParseResult & { formula: string } )[] * - diff ( a: string, b: string ) : ChemParseResult * * @author Paul Köhler (komed3) * @license MIT * @version 1.2.1 */ /** All supported IUPAC element symbols. */ export declare const ELEMENT_SYMBOLS: readonly [ 'H', 'He', 'Li', 'Be', 'B', 'C', 'N', 'O', 'F', 'Ne', 'Na', 'Mg', 'Al', 'Si', 'P', 'S', 'Cl', 'Ar', 'K', 'Ca', 'Sc', 'Ti', 'V', 'Cr', 'Mn', 'Fe', 'Co', 'Ni', 'Cu', 'Zn', 'Ga', 'Ge', 'As', 'Se', 'Br', 'Kr', 'Rb', 'Sr', 'Y', 'Zr', 'Nb', 'Mo', 'Tc', 'Ru', 'Rh', 'Pd', 'Ag', 'Cd', 'In', 'Sn', 'Sb', 'Te', 'I', 'Xe', 'Cs', 'Ba', 'La', 'Ce', 'Pr', 'Nd', 'Pm', 'Sm', 'Eu', 'Gd', 'Tb', 'Dy', 'Ho', 'Er', 'Tm', 'Yb', 'Lu', 'Hf', 'Ta', 'W', 'Re', 'Os', 'Ir', 'Pt', 'Au', 'Hg', 'Tl', 'Pb', 'Bi', 'Po', 'At', 'Rn', 'Fr', 'Ra', 'Ac', 'Th', 'Pa', 'U', 'Np', 'Pu', 'Am', 'Cm', 'Bk', 'Cf', 'Es', 'Fm', 'Md', 'No', 'Lr', 'Rf', 'Db', 'Sg', 'Bh', 'Hs', 'Mt', 'Ds', 'Rg', 'Cn', 'Nh', 'Fl', 'Mc', 'Lv', 'Ts', 'Og' ]; /** All supported particle symbols. */ export declare const PARTICLE_SYMBOLS: readonly ['e', 'p', 'n', 'α', 'β', 'γ', 'ν', 'ν̄']; /** A supported chemical element symbol. */ export type ElementSymbol = (typeof ELEMENT_SYMBOLS)[number]; /** A supported particle symbol. */ export type ParticleSymbol = (typeof PARTICLE_SYMBOLS)[number]; /** Element counts indexed by their chemical symbols. */ export type ElementCounts = Partial>; /** Particle counts indexed by their symbols. */ export type ParticleCounts = Partial>; /** * Result of parsing a chemical formula or particle expression. * * @property elementCounts Element counts indexed by their symbols. * @property particleCounts (optional) Particle counts indexed by their symbols. * @property charge (optional) Total ionic charge, including any leading coefficient. */ export interface ChemParseResult { elementCounts: ElementCounts; particleCounts?: ParticleCounts; charge?: number; } /** * Parses a chemical formula or particle expression. * * Leading coefficients multiply element counts, particle counts and the total charge. * * @param formula The chemical formula or particle expression. * @returns The parsed element counts, particle counts and optional total charge. * @throws {TypeError} If the formula is not a string. * @throws {Error} If the formula or any of its segments is invalid. */ export declare function parse(formula: string): ChemParseResult; /** * Checks whether a chemical formula or particle expression is valid. * * @param formula The chemical formula or particle expression. * @returns True if the input can be parsed, otherwise false. */ export declare function validate(formula: string): boolean; /** * Compares two or more chemical formulas or particle expressions. * * Compares element counts, particle counts and total charge. * * @param formulas The formulas or particle expressions to compare (at least two). * @returns True if all inputs have identical composition and total charge. * @throws {Error} If fewer than two formulas are provided. */ export declare function compareMany(...formulas: string[]): boolean; /** * Compares two chemical formulas or particle expressions. * * @param a The first formula or particle expression. * @param b The second formula or particle expression. * @returns True if both inputs have identical composition and total charge. */ export declare function compare(a: string, b: string): boolean; /** * Calculates the differences between the first input and each subsequent input. * * @param formulas The formulas or particle expressions to compare (at least two). * @returns Element count, particle count and total charge differences for each input. * @throws {Error} If fewer than two formulas are provided. */ export declare function diffMany(...formulas: string[]): (ChemParseResult & { formula: string })[]; /** * Calculates the difference between two formulas or particle expressions. * * @param a The first formula or particle expression. * @param b The second formula or particle expression. * @returns Element count, particle count and total charge differences. */ export declare function diff(a: string, b: string): ChemParseResult; /** Provides a static API for parsing and comparing chemical formulas and particles. */ export default class ChemParse { /** All supported chemical element symbols. */ static readonly ELEMENT_SYMBOLS: readonly [ 'H', 'He', 'Li', 'Be', 'B', 'C', 'N', 'O', 'F', 'Ne', 'Na', 'Mg', 'Al', 'Si', 'P', 'S', 'Cl', 'Ar', 'K', 'Ca', 'Sc', 'Ti', 'V', 'Cr', 'Mn', 'Fe', 'Co', 'Ni', 'Cu', 'Zn', 'Ga', 'Ge', 'As', 'Se', 'Br', 'Kr', 'Rb', 'Sr', 'Y', 'Zr', 'Nb', 'Mo', 'Tc', 'Ru', 'Rh', 'Pd', 'Ag', 'Cd', 'In', 'Sn', 'Sb', 'Te', 'I', 'Xe', 'Cs', 'Ba', 'La', 'Ce', 'Pr', 'Nd', 'Pm', 'Sm', 'Eu', 'Gd', 'Tb', 'Dy', 'Ho', 'Er', 'Tm', 'Yb', 'Lu', 'Hf', 'Ta', 'W', 'Re', 'Os', 'Ir', 'Pt', 'Au', 'Hg', 'Tl', 'Pb', 'Bi', 'Po', 'At', 'Rn', 'Fr', 'Ra', 'Ac', 'Th', 'Pa', 'U', 'Np', 'Pu', 'Am', 'Cm', 'Bk', 'Cf', 'Es', 'Fm', 'Md', 'No', 'Lr', 'Rf', 'Db', 'Sg', 'Bh', 'Hs', 'Mt', 'Ds', 'Rg', 'Cn', 'Nh', 'Fl', 'Mc', 'Lv', 'Ts', 'Og' ]; /** All supported particles symbols. */ static readonly PARTICLE_SYMBOLS: readonly ['e', 'p', 'n', 'α', 'β', 'γ', 'ν', 'ν̄']; /** @see parse */ static readonly parse: typeof parse; /** @see validate */ static readonly validate: typeof validate; /** @see compare */ static readonly compare: typeof compare; /** @see compareMany */ static readonly compareMany: typeof compareMany; /** @see diff */ static readonly diff: typeof diff; /** @see diffMany */ static readonly diffMany: typeof diffMany; }