RGex now supports modular imports that allow you to import only the parts you need, significantly reducing your bundle size!
Instead of importing the entire 61KB library, you can now import specific modules:
- Full import: 61KB
- Core only: 57KB (6% smaller)
- Utils only: 2.6KB (96% smaller!)
- Human text only: 49KB (20% smaller)
- Password only: 13KB (79% smaller)
- Constants only: 12KB (80% smaller)
import { RGex, rgex } from 'rgex/core';
// Build regex patterns
const emailRegex = new RGex().start().email().end().build();
const phoneRegex = rgex('^\\+?[1-9]\\d{1,14}$');Size: 57KB
import { escapeRegex, extractNumbers, isValidEmail } from 'rgex/utils';
// Utility functions
const escaped = escapeRegex('Hello (world)!');
const numbers = extractNumbers('Order #12345 costs $67.89');
const isValid = isValidEmail('test@example.com');Size: 2.6KB
import { t2r, t2v, humanToRegex } from 'rgex/human-text';
// Convert human text to regex
const phonePattern = t2r('phone number');
const emailValidation = t2v('required email address');Size: 49KB
import { validatePassword, generateStrongPassword } from 'rgex/password';
// Password utilities
const password = generateStrongPassword(12);
const validation = validatePassword('MyPassword123!');Size: 13KB
import { REGEX_PATTERNS, COMMON_PASSWORDS } from 'rgex/constants';
// Pre-built patterns and constants
const emailPattern = REGEX_PATTERNS.EMAIL;
const weakPasswords = COMMON_PASSWORDS;Size: 12KB
// Only 2.6KB instead of 61KB!
import { isValidEmail } from 'rgex/utils';
function validateEmail(email: string): boolean {
return isValidEmail(email);
}// Only 13KB instead of 61KB!
import { generateStrongPassword } from 'rgex/password';
function createPassword(): string {
return generateStrongPassword(16);
}// Only 49KB instead of 61KB!
import { t2r } from 'rgex/human-text';
function createPhoneValidator() {
return t2r('US phone number').pattern;
}| Import Style | Bundle Size | Savings |
|---|---|---|
| Full import | 61KB | - |
| Core only | 57KB | 6% |
| Utils only | 2.6KB | 96% |
| Human text only | 49KB | 20% |
| Password only | 13KB | 79% |
| Constants only | 12KB | 80% |
import { RGex, t2r, validatePassword } from 'rgex';import { RGex } from 'rgex/core';
import { t2r } from 'rgex/human-text';
import { validatePassword } from 'rgex/password';- Use specific modules instead of the full import when possible
- Utils module is perfect for simple validation functions
- Core module when you need the chainable builder
- Human text module for natural language processing
- Password module for authentication features
- Constants module for pre-built patterns
All modules include full TypeScript support with JSDoc comments:
import type { PasswordValidationResult } from 'rgex/password';
import { validatePassword } from 'rgex/password';
const result: PasswordValidationResult = validatePassword('test123');- Faster initial loading: Smaller bundles load faster
- Better tree-shaking: Only include what you use
- Reduced memory usage: Less code in memory
- Improved startup time: Less JavaScript to parse
Choose the right module for your use case and enjoy the significantly smaller bundle sizes! 🎉