โก Blazing Fast
Highly optimized tokenization with dual modes. Async mode provides maximum performance with ~0.05ms for JavaScript, while sync mode offers simplicity without sacrificing speed.
See Benchmarks
TypeScript-native syntax highlighter with comprehensive grammar support for modern web languages. Highly optimized for performance.
import { Tokenizer } from 'ts-syntax-highlighter'
// Create tokenizer
const tokenizer = new Tokenizer('javascript')
// Tokenize code (async - faster)
const tokens = await tokenizer.tokenizeAsync(`
const greeting = 'Hello World'
console.log(greeting)
`)
// Process tokens
tokens.forEach(line => {
line.tokens.forEach(token => {
console.log(`${token.type}: "${token.content}"`)
})
})
ts-syntax-highlighter is optimized for speed with efficient tokenization:
Operation | Fast Mode (Async) | Sync Mode |
---|---|---|
JavaScript | 0.05ms | 0.08ms |
TypeScript | 0.08ms | 0.12ms |
HTML | 0.04ms | 0.06ms |
CSS | 0.03ms | 0.05ms |
Library | JavaScript | TypeScript | HTML | CSS |
---|---|---|---|---|
ts-syntax-highlighter | 0.05ms | 0.08ms | 0.04ms | 0.03ms |
highlight.js | 3.8ms | 1.0ms | 1.2ms | 0.9ms |
Prism.js | 2.1ms | 0.6ms | 0.8ms | 0.5ms |
Fast enough for real-time syntax highlighting as you type. View detailed benchmarks โ
Support for the latest language features out-of-the-box:
Real-time syntax highlighting requires speed:
TypeScript-first design for the best DX:
ES2024+, React JSX, BigInt, regex flags
Types, generics, TSX, type operators
HTML5, ARIA, data attributes, entities
CSS4 colors, math, containers, layers
Objects, arrays, proper escapes
Blade-like templating, 50+ directives
Explore all language features โ
# Install
npm install ts-syntax-highlighter
# Or with Bun
bun add ts-syntax-highlighter