Introduction to Fast Brake
Pattern detection with zero runtime dependencies. Analyzes JavaScript code to detect text patterns using a plugin-based architecture.
What is fast-brake?
fast-brake is a detection library that analyzes JavaScript code to identify patterns using a plugin-based architecture. It can detect ECMAScript features, telemetry tracking, security patterns, or any custom patterns you define. Instead of AST parsing, fast-brake uses pattern matchingâwhich is faster when detection is the goal.
Why fast-brake?
The Problem
When detection is the goalâfinding ES compatibility issues, SDK usage, analytics callsâfull AST parsing may not be the right tool. AST parsers are designed for code transformation and deep analysis. But if you just need to know âdoes this code use optional chaining?â or âis there a tracking call?â, building a complete syntax tree is unnecessary work.
The Solution
fast-brake uses pattern matching for detection:
- High-performance regex patterns - Carefully crafted patterns for any text matching
- Single-pass scanning - Processes code once for all patterns
- Early exit optimization - Stops on first match when configured
- Plugin architecture - Load only the detection rules you need
- Zero AST overhead - No parsing or tree construction required
- Sync & Async APIs - Choose sync for maximum speed, async for workflow integration
// fast-brake approach - simple and fast
import { fastBrakeSync, check, detect } from 'fast-brake';
// FASTEST: Sync API with no async overhead
const fbSync = fastBrakeSync();
const isCompatible = fbSync.check(code, { target: 'es5' }); // <1ms
// Async API when needed for workflows
const isES5 = await check(code, { target: 'es5' });
const patterns = await detect(code);
Performance Comparison
Parser Comparison - ES2015 Files
| Parser | Time (ms) | Ops/sec | Relative Speed |
|---|---|---|---|
| fast-brake | 0.003 | 360,702 | 1.0x |
| fast-brake (preprocess) | 0.008 | 126,127 | 0.35x |
| meriyah | 0.017 | 59,162 | 0.16x |
| cherow | 0.020 | 49,214 | 0.14x |
| acorn | 0.060 | 16,641 | 0.05x |
| @babel/parser | 0.074 | 13,424 | 0.04x |
Parser Comparison - ES2024 Files
| Parser | Time (ms) | Ops/sec | Relative Speed |
|---|---|---|---|
| fast-brake | 0.001 | 839,395 | 1.0x |
| fast-brake (preprocess) | 0.018 | 56,805 | 0.07x |
| meriyah | 0.023 | 43,862 | 0.05x |
| acorn | 0.048 | 20,845 | 0.02x |
| @babel/parser | 0.057 | 17,639 | 0.02x |
Large File Performance (72KB)
| Parser | Time (ms) | Ops/sec | Relative Speed |
|---|---|---|---|
| fast-brake | 0.002 | 518,269 | 1.0x |
| esprima | 0.032 | 30,963 | 0.06x |
| @babel/parser | 0.090 | 11,088 | 0.02x |
| fast-brake (preprocess) | 0.489 | 2,043 | 0.004x |
Benchmarked on Apple M4, December 2025
About Preprocessing
fast-brake offers two modes:
- Default (no preprocessing): Maximum speed for minified/bundled code
- With preprocessing: Comment stripping for unminified source files
Preprocessing is usually unnecessary because most fast-brake use cases involve analyzing minified or bundled code where comments have already been stripped during the build process. Only enable preprocessing when analyzing raw source files with JavaScript comments.
Key Benefits
- Fast: Detection is 6-19x faster than full parsers, 500k+ ops/sec
- ** Zero Dependencies**: Lightweight with no runtime dependencies
- ** Pattern Matching**: Optimized regex-based detection without AST overhead
- ** Plugin Architecture**: Load only the detection rules you need
- ** Comprehensive Coverage**: Default plugin supports ES5 through ES2025 (40+ patterns)
- ** Simple API**: Intuitive interface with TypeScript support
- ** Location Data**: Optional AST-like location information (line, column, offset)
- ** Performance First**: Optimized for build tools and CI/CD pipelines
Perfect For
Build Tools & Bundlers
import { fastBrakeSync } from 'fast-brake';
// FASTEST: Sync API for build tools
const fb = fastBrakeSync();
if (!fb.check(sourceCode, { target: 'es2015' })) {
console.warn('Code requires transpilation');
}
Linting & CI/CD
import { fastBrakeSync } from 'fast-brake';
// FASTEST: Sync API for CI/CD pipelines
const fb = fastBrakeSync();
const isCompatible = fb.check(code, { target: 'es2018' });
if (!isCompatible) {
console.error('Code is not ES2018 compatible');
process.exit(1);
}
Dynamic Polyfill Loading
import { detect } from 'fast-brake';
// Detect features and determine polyfill needs
const features = await detect(userCode);
const versions = features.map(f => f.version);
if (versions.some(v => v !== 'es5')) {
loadPolyfills(versions);
}
Code Analysis Tools
import { detect } from 'fast-brake';
const features = await detect(codebase);
const modernFeatures = features.filter(f =>
['es2020', 'es2021', 'es2022'].includes(f.version)
);
Installation & Quick Start
npm install fast-brake
import { fastBrakeSync, fastBrake, check } from 'fast-brake';
// FASTEST: Sync API (no async overhead)
const fbSync = fastBrakeSync();
const isES5Compatible = fbSync.check('const x = () => {}', { target: 'es5' });
// false - instant result, no await needed
// Async API (when async is required)
const isCompatible = await check('const x = () => {}', { target: 'es5' });
const results = await fastBrake('const x = () => {}');
// Factory pattern with plugins
const fb = fastBrakeSync({
plugins: [es2015Plugin],
extensions: [locExtension]
});
const features = fb.detect('const x = () => {}');
Default Plugin: ES Version Detection
The default ES version plugin detects 30+ ECMAScript patterns across all major versions:
- ES2015: Arrow functions, classes, template literals, let/const, destructuring, spread/rest, for-of loops
- ES2016: Exponentiation operator (**)
- ES2017: Async/await functions
- ES2018: Async iteration, rest/spread properties
- ES2019: Array.flat(), Array.flatMap()
- ES2020: Optional chaining (?.), nullish coalescing (??), BigInt, Promise.allSettled
- ES2021: Logical assignment (||=, &&=, ??=), numeric separators, String.replaceAll
- ES2022: Private fields (#), static blocks, Array.at(), Object.hasOwn(), top-level await
Advanced Features
Detection Results
const patterns = await detect(code);
// Returns:
// [{
// name: 'arrow_functions', // Pattern name from plugin
// version: 'es2015' // Rule name from plugin
// }]
Plugin-Based Detection
import { Detector } from 'fast-brake';
import { telemetryPlugin } from 'fast-brake/src/plugins/telemetry';
// Use the Detector class with custom plugins
const detector = new Detector();
await detector.initialize(telemetryPlugin);
const result = detector.detectFast(code);
Ready to Get Started?
fast-brake makes pattern detection simple, fast, and accurate. Whether youâre checking ES compatibility, detecting telemetry, finding security issues, or matching custom patterns, fast-brake delivers the performance you need without sacrificing accuracy.