Introduction to Fast Brake

Pattern detection with zero runtime dependencies. Analyzes JavaScript code to detect text patterns using a plugin-based architecture.

npm versionGitHub starsTypeScript ReadyLicense: MIT

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

ParserTime (ms)Ops/secRelative Speed
fast-brake0.003360,7021.0x
fast-brake (preprocess)0.008126,1270.35x
meriyah0.01759,1620.16x
cherow0.02049,2140.14x
acorn0.06016,6410.05x
@babel/parser0.07413,4240.04x

Parser Comparison - ES2024 Files

ParserTime (ms)Ops/secRelative Speed
fast-brake0.001839,3951.0x
fast-brake (preprocess)0.01856,8050.07x
meriyah0.02343,8620.05x
acorn0.04820,8450.02x
@babel/parser0.05717,6390.02x

Large File Performance (72KB)

ParserTime (ms)Ops/secRelative Speed
fast-brake0.002518,2691.0x
esprima0.03230,9630.06x
@babel/parser0.09011,0880.02x
fast-brake (preprocess)0.4892,0430.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.

Get Started → | View Architecture → | See Examples →