code-fns (v0.11.0) is a JavaScript/TypeScript library for syntax highlighting and code visualization that outputs raw text and hex color tokens instead of HTML/CSS. It is designed for non-web rendering targets such as animations and videos, and is the primary highlighting engine for Motion Canvas. The library supports many languages via tree-sitter grammars, includes a diffing function to compute token-level transformations between code blocks (useful for animations), and ships TypeScript types. It is released on npm with an irregular cadence and requires modern EcmaScript features, so bundling/transpilation is left to the consumer. Key differentiators: output is language-agnostic token arrays, not DOM elements; built-in diff/morph support for transitions; no built-in theming—colors come straight from tree-sitter.
npm install code-fnsNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates basic usage: import, initialize a language, parse a code string into tokens with colors.
Use a bundler or transpiler (e.g., Babel, esbuild, Webpack) in your build step.
Always call `await ready({ langs: [...] })` before parsing.Refer to the list of supported tree-sitter grammars; use exact spelling.
Handle the 'morph' field when rendering (e.g., for animations).
Add `await ready({ langs: ['javascript'] });` before accessing `language.javascript`.Switch to ES module import syntax: `import { ready } from 'code-fns'`.Use the exact language identifier (e.g., 'javascript' for JS).