npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

chemymass

v2.0.4

Published

Simple chemical molar mass calculator

Downloads

16

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 to g/mol. Available options are g/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.
Creative Commons Attribution 4.0 International License