@kreuzberg/tree-sitter-language-pack
v1.4.0
Published
Tree-sitter language pack - pre-compiled parsers for 248 languages (Node.js NAPI bindings)
Maintainers
Readme
tree-sitter-language-pack — Node.js
Node.js NAPI bindings for tree-sitter-language-pack with on-demand parser downloads.
Installation
npm install @kreuzberg/tree-sitter-language-packpnpm add @kreuzberg/tree-sitter-language-packyarn add @kreuzberg/tree-sitter-language-packQuick Start
const { init, download, availableLanguages, hasLanguage, process } = require("@kreuzberg/tree-sitter-language-pack");
// Optional: Pre-download specific languages for offline use
init(["python", "javascript", "rust"]);
console.log(availableLanguages());
console.log(hasLanguage("python")); // true
// Auto-downloads language if not cached
const result = process('function hello() {}', { language: 'javascript' });
console.log('Functions:', result.structure.length);
// Pre-download languages for offline use
download(["python", "javascript"]);
// With chunking (auto-downloads if needed)
const result2 = process(source, { language: 'javascript', chunkMaxSize: 1000 });
console.log('Chunks:', result2.chunks.length);API Reference
Language Discovery
availableLanguages()-- list all supported language nameshasLanguage(name)-- check if a language is availablelanguageCount()-- total number of supported languages
Language Detection
detectLanguage(path)-- detect language from file pathdetectLanguageFromExtension(ext)-- detect language from a bare file extensiondetectLanguageFromPath(path)-- detect language from a file pathdetectLanguageFromContent(content)-- detect language from shebang lineextensionAmbiguity(ext)-- check if an extension is ambiguous (returns assigned language + alternatives)
Parsing
getParser(name)/parseString(source, language)-- parse source code into a syntax tree
Download API
init(languages)-- pre-download specific languages for offline usedownload(languages)-- download parsers on demand
Intelligence
process(source, config)-- extract structured analysis (functions, classes, imports, comments, chunks) from source code
Syntax Highlighting Queries
getHighlightsQuery(language)-- get bundled highlights.scm query for a languagegetInjectionsQuery(language)-- get bundled injections.scm querygetLocalsQuery(language)-- get bundled locals.scm query
For full documentation, see kreuzberg.dev.
License
MIT -- see LICENSE for details.
Part of tree-sitter-language-pack -- A comprehensive collection of tree-sitter language parsers with polyglot bindings.
