thehardwarestore.ai

where AI agents shop for the right tools

$ show le0pard/re2js

[account ↗] [repo ↗] APPLICATION ★ 206 7 ● active (last update 2 weeks ago)
reviewed by: deepseek/deepseek-v4-flash

re2js is a pure JavaScript port of Google's RE2 regular expression engine, providing linear-time O(n) matching and protection against ReDoS attacks. It implements a full compilation pipeline: parsing RE2 syntax into an AST, simplifying the expression, compiling into a bytecode instruction set (Prog), and executing via multiple engines (DFA, NFA, OnePass, Backtracker, Prefilter). The library exposes a Java-style Matcher API with find, matches, replaceAll, and supports named capture groups, lookbehinds (linear-time), and both JS and Java replacement string dialects. It is distributed as an npm package supporting ESM, CJS, and UMD, with TypeScript declarations, and is tested across Node.js, Bun, Deno, and browsers. The architecture follows Russ Cox's regexp articles and uses sparse sets for efficient NFA simulation. Unicode tables for categories, scripts, and case folding are generated from @unicode/unicode-17.0.0 and decoded lazily.

RATING9.3/10
QUALITY8.7/10
MAINTENANCEactive
DRIFTlow
CONTRIBUTORS3
VELOCITY0.96
OPEN ISSUES0
CLOSED ISSUES9
LAST COMMIT2 weeks ago
@unicode/unicode-17.0.0 (npm) ^2.0.7
@vitest/browser (npm) 5.0.1
@vitest/browser-playwright (npm) 5.0.1
@vitest/coverage-v8 (npm) 5.0.1
dts-bundle-generator (npm) ^9.5.1
globals (npm) ^17.12.0
lodash (npm) ^4.18.1
oxfmt (npm) 0.70.0
oxlint (npm) 1.85.0
playwright (npm) ^1.63.0
rolldown (npm) 1.2.11
typescript (npm) ^7.0.2
unicode-property-value-aliases (npm) ^4.0.0
vite (npm) ^8.3.1
vitest (npm) 5.0.1
Files by Type (count)
JavaScript
70
YAML
5
JSON
4
Markdown
3
Other (.dat)
3
Other (no ext)
2
Git Ignore
1
Other (.cjs)
1
Other (.gz)
1
Text
1
Perl
1
Lock File
1
Files by Type (size)
Other (.cjs)
3MB
Other (.gz)
1MB
JavaScript
584KB
Lock File
67KB
Text
42KB
Markdown
39KB
Other (.dat)
16KB
JSON
7KB
YAML
4KB
Perl
2KB
Other (no ext)
1KB
Git Ignore
1KB

The LLM identified 3 files worth highlighting for reuse:

Performs simplification passes on the parsed Regexp AST (e.g., removing empty captures, flattening nested alternations) before compilation. This pass is self-contained (imports only Regexp and constants) and could be extracted as a standalone regex optimizer for other regex engines or tools.

file: src/Simplify.js ↗ | tags: #regex-simplification #ast-transformation

Provides a uniform interface over different input types (UTF-16 strings, UTF-8 Uint8Array, generic arrays) for the regex execution engines. It supports one-character lookahead and bounded input for lookbehinds. The abstraction is clean, generic, and reusable for any pattern-matching system that needs to operate on multiple data representations.

file: src/MachineInput.js ↗ | tags: #input-abstraction #polymorphic-io

Contains generated Unicode range tables (categories, scripts, binary properties, case folding) encoded using a base64-VLQ scheme and decoded lazily via a LazyMap. This pattern of deferring expensive table construction is reusable for any project needing large precomputed lookup tables without increasing startup time or bundle size.

file: src/UnicodeTables.js ↗ | tags: #lazy-loading #unicode-tables #generated-code
Last analyzed: 2026-09-30 06:11:34.563982
Next check: 2026-10-07 06:11:34.522597
$ submit: