chemymass
v2.0.4
Published
Simple chemical molar mass calculator
Downloads
16
Maintainers
Readme
📝 Description
chemymass - Simple molar mass calculator. Calculates molar mass for any valid formula.
🔧 Installation
chemymass is easy to install, just do:
npm i chemymass
📕 Usage
chemymass from v2 is an ESM-only module - you are not able to import it with require()
.
If you cannot switch to ESM, please use v1 which remains compatible with CommonJS.
npm i chemymass@1
Ways to call the module from your program:
// Standard Long Mode - Get molar mass and element percentages.
import chemymass from "chemymass";
const formula = "H₂SO₄";
const precision = 3;
const units = "g/mol";
console.log(chemymass(formula, precision, units));
/* Output:
H₂SO₄:
2 H · 1.007825 = 2.016 (2.055% of mass)
1 S · 32.066 = 32.066 (32.694% of mass)
4 O · 15.9994 = 63.998 (65.251% of mass)
Total: 98.079 g/mol
*/
// Standard Short Mode - Get only molar mass.
import { short } from "chemymass";
const formula = "CuSO₄ · 5H₂O";
const precision = 7;
const units = "amu";
console.log(chemymass.short(formula, precision, units));
/* Output:
249.6848500 amu
*/
// Standard Verbal Mode - Get molar mass and element percentages from query.
import { verbal } from "chemymass";
const query = "Sugar";
const precision = 7;
const units = "Da";
chemymass.verbal(query, precision, units)
.then(output => console.log(output));
/* Output:
Sugar - C₁₂H₂₂O₁₁:
12 C · 12.011 = 144.1320000 (42.1072251% of mass)
22 H · 1.007825 = 22.1721500 (6.4774492% of mass)
11 O · 15.9994 = 175.9934000 (51.4153256% of mass)
Total: 342.2975500 Da
*/
// Short Verbal Mode - Get only molar mass from query.
import { verbalShort } from "chemymass";
const query = "58-08-2";
const precision = 7;
const units = "u";
chemymass.verbalShort(query, precision, units)
.then(output => console.log(output));
/* Output:
194.1918500 u
*/
// Standard Bulk Mode - Get molar mass and element percentages.
import { bulk } from "chemymass";
const formula = ["H₂SO₄", "H₂O", "CuSO₄"];
const precision = 3;
const units = "g/mol";
console.log(chemymass.bulk(formula, precision, units));
/* Output:
H₂SO₄:
1 S · 32.066 = 32.066 (32.694% of mass)
4 O · 15.9994 = 63.998 (65.251% of mass)
Total: 98.079 g/mol
H₂O:
2 H · 1.007825 = 2.016 (11.189% of mass)
1 O · 15.9994 = 15.999 (88.811% of mass)
Total: 18.015 g/mol
CuSO₄:
1 Cu · 63.546 = 63.546 (39.813% of mass)
1 S · 32.066 = 32.066 (20.090% of mass)
4 O · 15.9994 = 63.998 (40.096% of mass)
Total: 159.610 g/mol
*/
// Standard Short Mode - Get only molar mass.
import { bulkShort } from "chemymass";
const formula = ["H2SO4", "H2O", "CuSO4"];
const precision = 7;
const units = "amu";
console.log(chemymass.short(formula, precision, units));
/* Output:
98.0792500 amu
18.0150500 amu
159.6096000 amu
*/
📰 Notes
This module understands both normal numbers and subscripts. You don't have to specifically convert them.
Crystal Hydrates work without any modifications. Formulas can be with signs
·
,×
or*
.Verbal mode supported query types:
Plain Text Name
,CAS number
,SMILES
,IUPAC
,FICTS identifier
,Cactvs HASHISY
,uuuuu identifier
.units
is optional parameter which defaults tog/mol
. Available options areg/mol
(Grams per mole);kg/mol
(Kilograms per mole);Da
(Daltons);amu
(Atomic mass unit);u
(Same as amu) or""
(No units - just number).(^2.0.3) Bulk options is now available. Just pass an array of formulas and all of them will be calculated.
precision
is optional parameter which defaults to 3 if not passed to function.Verbal mode is made possible by NIH NCI/CADD Group! Without their API, verbal mode probably wouldn't be a thing.
👨⚖️ License
chemymass by EEHoveckis is licensed under a Creative Commons Attribution 4.0 International License.
Permissions beyond the scope of this license may be available on request.