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 🙏

© 2026 – Pkg Stats / Ryan Hefner

oxyd

v0.1.1

Published

Oxidise chemical formulas — convert any formula into its fully oxidised equivalent

Readme

oxyd

Convert a chemical formula into its fully oxidised equivalent.

oxyd parses a chemical formula, maps each element to its common (highest) oxide, and returns the stoichiometrically balanced set of oxide products — the same products you would get from complete combustion.

Install

npm install oxyd

Usage

The package is ESM-only and exports oxidise as both the default and a named export, alongside the OXIDES lookup table.

import oxidise from 'oxyd';
// or: import { oxidise, OXIDES } from 'oxyd';

oxidise('CH4');      // 'CO2 + 2H2O'
oxidise('Fe');       // 'Fe2O3'
oxidise('C6H12O6');  // '6CO2 + 6H2O'
oxidise('Ca(OH)2');  // 'CaO + H2O'
oxidise('C2H5OH');  // '2CO2 + 3H2O'
oxidise('O2');       // 'O2' — already fully oxidised

More examples

| Input | Output | | --- | --- | | CH4 | CO2 + 2H2O | | S | SO3 | | Na | Na2O | | NH3 | N2O5 + 3H2O | | Fe3O4 | 3Fe2O3 | | KMnO4 | K2O + 2MnO2* |

* oxygen passes through as part of the oxides, so oxygen in the input is not listed separately.

API

oxidise(formula)

  • formula — a chemical formula string. Multi-letter symbols, subscripts and nested parentheses are supported (Ca(OH)2, Fe3(SO4)2). Whitespace is ignored.
  • Returns the oxidised equivalent as a string, with multiple products joined by +.

When oxide units would be fractional, all terms are scaled by the smallest factor that makes every coefficient an integer. For example, a single sodium atom formally yields half a unit of Na2O, so the result is scaled and reported as Na2O; likewise Fe reports Fe2O3. Ratios between products are always exact.

OXIDES

A map of element symbol to [oxideFormula, atomsPerUnit], for example H: ['H2O', 2]. To support additional elements, extend the exported object:

import { OXIDES } from 'oxyd';

OXIDES['Xe'] = ['XeO3', 1];
oxidise('Xe'); // 'XeO3'

Elements not present in the table throw an error rather than guessing an oxidation state.

Errors

oxidise throws on invalid input with a descriptive message:

| Problem | Example message | | --- | --- | | Non-string argument | formula must be a string | | Empty formula | formula must not be empty | | Unrecognised character | Unexpected character "c" in "ch4" | | Unbalanced brackets | Unbalanced "(" in "C(" | | Unsupported element | No known oxide for element "Xe" |

License

Not yet licensed. Add a LICENSE file before publishing.