Skip to content

TypeScript

Ruby
asciichem
gem install asciichemReference implementation.
TypeScriptyou are here
asciichem-ts
npm install asciichemPowers this page.
Python
asciichem-py
pip install asciichem-pyZero runtime deps.
Terminal window
npm install asciichem

Published to npm via trusted publishing (OIDC, no stored credentials) with SLSA provenance attestations — see the provenance on npm.

import { parse, parseSmiles, parseMolfile, renderMathml } from "asciichem";
// Same model as the Ruby reference — every format the gem emits, in
// the browser or Node.
parse("2H_2 + O_2 ->[heat] 2H_2O").toText();
parse("C1-C-C-C-C-C1").toStructuralSvg(); // cyclohexane hexagon
// Structures from databases, straight into the model
const aspirin = parseSmiles("CC(=O)OC1=CC=CC=C1C(=O)O");
aspirin.toStructuralSvg();
aspirin.toSmiles(); // deterministic writer — round-trips exactly
parseMolfile(v2000Text); // coordinates preserved for rendering
// MathML goldens — byte-identical with the reference implementation.
console.log(renderMathml(parse("^14C")));

Parse / reject · L0 emission · L1 text · L2 MathML · SMILES · molfile — 100% of the shared corpus. See the Implementations matrix for the full table.

This is the package that powers this site’s live renderer and every diagram on this page. Highlights:

  • Runs in the browser — the live playground uses it directly. No server, no build step beyond import.
  • Peggy parser — a faithful port of the reference grammar, with the same atoms, same precedence, same round-trip guarantees. Zero runtime dependencies.
  • All formats in TS — Text, typographic SVG, 2D structural SVG, presentation MathML (L2 goldens), wire JSON, SMILES writer, molfile reader/writer.
  • Three-pane live diff (above) — type once, three identical outputs across Ruby / TypeScript / Python, the live demonstration of the single-contract rule.

github.com/asciichem/asciichem-ts — powers this page.

Play