@codemirror/language-data

Language metadata and dynamic loading for every language mode in the CodeMirror 6 editor

Library
npm
v6.5.2
13 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
24 /100 Needs Attention
Development Activity 4
Maintenance 0
Community 20
Maturity 60
Momentum 12

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
68 /100 Good
Architecture 75
Code Quality 70
Innovation 60
Learning Curve 65

@codemirror/language-data is the language registry for CodeMirror 6. Rather than bundling every language package into your editor, it exposes a single languages array of LanguageDescription objects, one per supported language, each carrying filename/extension matchers and a dynamic import() loader for that language’s actual mode package. This lets an editor offer language auto-detection and a full language picker while only downloading the parser code a user actually needs.

What You Get

  • A languages array of LanguageDescription entries covering ~40 languages, ready to feed into a language-picker UI
  • LanguageDescription.matchFilename and matchLanguageName helpers for auto-detecting a language from a file path or name
  • Dynamic import()-based lazy loading so unused language packages never ship to the browser
  • A single dependency surface that transitively pulls in the full set of official @codemirror/lang-* packages for convenience installs

Common Use Cases

  • Building a browser-based code editor (like an in-browser IDE or playground) that needs to auto-detect a file’s language from its extension
  • Populating a ‘change language’ dropdown in a CodeMirror-based editor without manually importing every language package
  • Loading syntax highlighting and language support on demand to keep initial bundle size small in a documentation or notebook tool
  • Powering multi-language snippet or gist editors where the language isn’t known until runtime

Under The Hood

Architecture The entire package is a single 1,000-line file, src/language-data.ts, that constructs one flat languages array of LanguageDescription.of({...}) calls, each entry pairing a name, filename/extension regex, optional MIME/alias list, and a load function that returns import('@codemirror/lang-x'). There is no runtime logic beyond this declarative table plus the LanguageDescription class it re-exports from @codemirror/language; matching (matchFilename, matchLanguageName) is delegated entirely to that upstream class. Tech Stack Written in TypeScript, built with CodeMirror’s shared @codemirror/buildhelper tool, and shipped as both ESM (dist/index.js) and CJS (dist/index.cjs) with bundled .d.ts types. Its dependencies list every official @codemirror/lang-* package (JSON, Python, Rust, SQL, YAML, etc.) plus @codemirror/legacy-modes, but none of them are imported eagerly — they only load through the dynamic import() inside each entry’s load function. Code Quality There are no dedicated unit tests in this repository; correctness is exercised indirectly via CodeMirror’s shared cm-runtests harness used across the monorepo-like family of @codemirror/* packages. The single source file is consistent and readable — one repeated object-literal pattern per language — which keeps the risk surface low despite the absence of local tests. API Design The public surface is minimal and ergonomic: import languages and call LanguageDescription.matchFilename(languages, filename) to get a matching description, then .load() to lazily fetch the actual language support. No configuration objects, no build-step wiring, and no boilerplate beyond that one call — the tradeoff is that customizing the language list (adding a custom language) means constructing your own LanguageDescription array rather than extending this one.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers