molmass-js
v0.9.4
Published
Parse chemical formulas and compute molar mass from standard atomic weights.
Maintainers
Readme
molar-mass
Parse a chemical formula and get its molar mass in g/mol. No dependencies, CommonJS.
Supports nested groups ((NH4)2SO4), square brackets (K4[Fe(CN)6]), and
dot-separated hydrates (CuSO4.5H2O or CuSO4·5H2O).
const { molarMass, massPercent, parseFormula } = require('molar-mass');
molarMass('H2O'); // 18.015
molarMass('C6H12O6'); // 180.156
molarMass('CuSO4.5H2O'); // 249.685
parseFormula('(NH4)2SO4'); // { N: 2, H: 8, S: 1, O: 4 }
massPercent('H2O'); // { H: 11.19..., O: 88.81... }Atomic weights are the IUPAC 2021 conventional values, abridged. Elements 1–92 are covered. Isotopic masses and radioactive-element edge cases are out of scope — if you need those you probably want a proper cheminformatics toolkit.
License
ISC
