Skip to content

TypeScript

Ruby
asciichem
gem install asciichemReference implementation.
TypeScriptyou are here
asciichem
npm install asciichemPowers this page.
Python
asciichem
pip install asciichemZero 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";
// The same model as every runtime — the authoritative one is the
// Rust crate; the corpus keeps this package identical to it.
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 · L2 SVG (typographic + structural, deterministic) · L3 stereo (parity-correct canonical SMILES) · SMILES · molfile — 100% of the shared corpus. The CML and linter layers, and the resolver/citation ports, are not yet claimed (asciichem-ts#26 converges them from the Rust contract). 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.
  • The shared parse engine — parsing runs on parsanol’s wasm engine over the one checksummed PARG artifact the Rust crate embeds (0.1.4, asciichem-ts#27; the peggy port is deleted). Same artifact, same engine family, same acceptance — zero drift by construction.
  • 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