rtf-to-text
Extracted from a production text pipeline that had to ingest pasted RTF, then rebuilt as a standalone zero-dependency package.
Strip RTF down to clean plaintext. One exported function with zero runtime dependencies, shipped as ESM and CJS with bundled types. It decodes unicode escapes (including negative wrapped values), skips control groups like font and color tables wholesale, maps escaped literals and smart punctuation to real characters, and passes non-RTF input through unchanged so it can run over mixed piles of files without sniffing each one. Built with tsdown and verified with publint and arethetypeswrong so the published package actually resolves everywhere it claims to.
Context
Text pipelines that accept pasted input eventually meet RTF: a user copies from Word or TextEdit, pastes into a form, and the payload arrives wrapped in control words and brace groups. A production app of mine hit exactly that, and the existing npm options were either heavyweight document parsers or abandoned regex one-liners that leaked \fonttbl noise into output.
Approach
The extractor throws formatting away on purpose. The goal is the text a human would read, suitable for search indexing, analysis, or just showing the user what they pasted. It handles the messy parts that break naive strippers: \*-marked ignorable destinations that Word sprinkles through real documents, negative unicode escape values, and escaped literals that carry meaning. Anything that is not RTF passes through unchanged, so callers can run it over mixed .rtf and .txt files without sniffing first.
Packaging got the same care as parsing. The build runs through tsdown to dual ESM and CJS outputs with types, and CI gates on publint and arethetypeswrong so module-resolution claims are verified rather than assumed. Publishing to npm uses Trusted Publishing (OIDC), so no long-lived token sits in repository secrets.
Outcome
A small, finished package: one function that does its documented job, verified packaging, and a test suite built from the RTF real word processors emit rather than idealized fixtures.