How francisrstokes/super-expressive works
Main Components and Architecture
a) Core Builder Component:
• Central SuperExpressive class/builder
• Immutable state management
• Method chain handling
b) API Layer:
• Flag methods (allowMultipleMatches, lineByLine, etc.)
• Pattern methods (anyChar, digit, word, etc.)
• Quantifier methods (exactly, between, oneOrMore, etc.)
• Grouping methods (capture, group, anyOf, etc.)
c) Transformation Layer:
• Regex string generation
• Final RegExp object creation
┌─────────────────────────────────────────────────────────┐
• Super Expressive │
• ┘
• ▼
┌─────────────────────────────────────────────────────────┐
• Builder Core │
• ┤
• State Management │
• Method Chain Processing │
• Validation Logic │
• ┘
• ┌────────────┴───────────┐
• ▼ ▼
┌────────────────────┐ ┌──────────────────────┐
• API Layer │ │ Transformation Layer │
• ┤ ├──────────────────────┤
• Flags │ │ - toRegexString() │
• Patterns │ │ - toRegex() │
• Quantifiers │ └──────────────────────┘
• Groups │
• ┘
Important Elements
a) Method Categories:
• Flag methods (caseInsensitive, unicode, etc.)
• Pattern methods (digit, word, anyChar, etc.)
• Quantifier methods (exactly, between, etc.)
• Methods (capture, anyOf, etc.)
b) Data Flow:
• How method calls build up the internal state
• How the final regex is generated
c) Key Features:
• Immutability
• Method chaining
• Validation
• TypeScript support
Additional Notes
• Notes about the lightweight nature (4kb minified + gzipped)
• Relationship with the final RegExp object
• TypeScript definition file integration
Implementation Details
• The builder pattern implementation
• The fluent interface design
• The transformation process from readable API to regex
• Error handling and validation flow
This design captures the essence of Super Expressive as a tool that transforms human-readable method chains into regular expressions, while maintaining a clean and maintainable architecture.