workspace/core/constants/regex.constants.ts
rckrdmrd 49155822ae fix: Resolve TypeScript compilation errors across all projects
Platform Marketing Content:
- Add PaginationParams, PaginationMeta, PaginatedResponse interfaces
- Fix JwtAuthGuard import paths (common/guards instead of modules/auth)
- Add missing fields to CRM interfaces (address, keywords, features, benefits)
- Install @nestjs/throttler dependency

ERP Suite - Construccion:
- Create tsconfig.node.json for web frontend
- Add vite-env.d.ts for Vite types
- Fix implicit return errors in Express controllers
- Prefix unused parameters with underscore

ERP Suite - ERP Core:
- Export PoolClient type from database config
- Fix invoice type comparison (customer/supplier vs out_invoice)
- Refactor base.service.ts query handling for proper type inference
- Rename Role type to RoleType to avoid conflict with entity
- Fix ProtectedRoute to use role?.name instead of roles array

ERP Suite - POS Micro:
- Add vite-env.d.ts for Vite types
- Fix Sale property names (discountAmount, changeAmount)
- Export TodaySummary interface from sales service

All projects now pass npm install and npm run build successfully.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-08 22:35:55 -06:00

292 lines
7.1 KiB
TypeScript

/**
* Regular Expression Patterns - Core Constants
*
* Regex patterns compartidos entre todos los proyectos del workspace.
*
* @module @core/constants/regex
* @version 1.0.0
*/
// ============================================================================
// EMAIL & AUTHENTICATION
// ============================================================================
/**
* Email validation pattern
* Matches: user@example.com, user.name+tag@example.co.uk
*/
export const EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
/**
* Strong password pattern
* Requirements: 8+ chars, 1 uppercase, 1 lowercase, 1 number, 1 special char
*/
export const STRONG_PASSWORD_REGEX =
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/;
/**
* Medium password pattern
* Requirements: 8+ chars, 1 uppercase or lowercase, 1 number
*/
export const MEDIUM_PASSWORD_REGEX = /^(?=.*[a-zA-Z])(?=.*\d)[A-Za-z\d]{8,}$/;
/**
* Username pattern
* Requirements: 3-30 chars, alphanumeric + underscore, starts with letter
*/
export const USERNAME_REGEX = /^[a-zA-Z][a-zA-Z0-9_]{2,29}$/;
// ============================================================================
// IDENTIFIERS
// ============================================================================
/**
* UUID v4 pattern
*/
export const UUID_REGEX =
/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
/**
* UUID (any version) pattern
*/
export const UUID_ANY_REGEX =
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
/**
* Slug pattern (url-friendly string)
*/
export const SLUG_REGEX = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
// ============================================================================
// PHONE NUMBERS
// ============================================================================
/**
* International phone number (E.164 format)
*/
export const PHONE_INTERNATIONAL_REGEX = /^\+?[1-9]\d{1,14}$/;
/**
* Mexican phone number (10 digits)
*/
export const PHONE_MEXICO_REGEX = /^(\+?52)?[1-9]\d{9}$/;
/**
* US phone number
*/
export const PHONE_US_REGEX = /^(\+?1)?[2-9]\d{2}[2-9]\d{6}$/;
// ============================================================================
// FINANCIAL
// ============================================================================
/**
* Credit card number (basic validation)
*/
export const CREDIT_CARD_REGEX = /^\d{13,19}$/;
/**
* CVV/CVC (3-4 digits)
*/
export const CVV_REGEX = /^\d{3,4}$/;
/**
* Currency amount (allows decimals)
*/
export const CURRENCY_AMOUNT_REGEX = /^\d+(\.\d{1,2})?$/;
/**
* Percentage (0-100 with optional decimals)
*/
export const PERCENTAGE_REGEX = /^(100(\.0{1,2})?|[0-9]{1,2}(\.\d{1,2})?)$/;
// ============================================================================
// MEXICAN IDS
// ============================================================================
/**
* Mexican RFC (Tax ID)
* Format: XXXX######XXX for companies, XXX######XXXX for individuals
*/
export const RFC_MEXICO_REGEX =
/^([A-ZÑ&]{3,4})(\d{2})(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])([A-Z\d]{2})([A\d])$/i;
/**
* Mexican CURP (Unique Population Registry Code)
*/
export const CURP_MEXICO_REGEX =
/^[A-Z]{4}\d{6}[HM][A-Z]{5}[A-Z\d]\d$/i;
/**
* Mexican Postal Code (5 digits)
*/
export const POSTAL_CODE_MEXICO_REGEX = /^\d{5}$/;
// ============================================================================
// NETWORK
// ============================================================================
/**
* IPv4 address
*/
export const IPV4_REGEX =
/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
/**
* IPv6 address (simplified)
*/
export const IPV6_REGEX = /^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$/;
/**
* MAC address
*/
export const MAC_ADDRESS_REGEX = /^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/;
/**
* URL (http, https)
*/
export const URL_REGEX =
/^https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)$/;
/**
* Domain name
*/
export const DOMAIN_REGEX =
/^(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$/;
// ============================================================================
// DATES & TIMES
// ============================================================================
/**
* Date (YYYY-MM-DD)
*/
export const DATE_REGEX = /^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/;
/**
* Time (HH:MM:SS or HH:MM)
*/
export const TIME_REGEX = /^([01]\d|2[0-3]):([0-5]\d)(:([0-5]\d))?$/;
/**
* ISO 8601 datetime
*/
export const ISO_DATETIME_REGEX =
/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{3})?(Z|[+-]\d{2}:\d{2})?$/;
// ============================================================================
// COLORS
// ============================================================================
/**
* Hex color (#RGB or #RRGGBB)
*/
export const HEX_COLOR_REGEX = /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/;
/**
* RGB color
*/
export const RGB_COLOR_REGEX =
/^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/;
/**
* RGBA color
*/
export const RGBA_COLOR_REGEX =
/^rgba\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(0|1|0?\.\d+)\s*\)$/;
// ============================================================================
// TEXT PATTERNS
// ============================================================================
/**
* Alphanumeric only
*/
export const ALPHANUMERIC_REGEX = /^[a-zA-Z0-9]+$/;
/**
* Alphabetic only
*/
export const ALPHABETIC_REGEX = /^[a-zA-Z]+$/;
/**
* Numeric only
*/
export const NUMERIC_REGEX = /^\d+$/;
/**
* No special characters (alphanumeric + spaces)
*/
export const NO_SPECIAL_CHARS_REGEX = /^[a-zA-Z0-9\s]+$/;
/**
* HTML tags
*/
export const HTML_TAG_REGEX = /<[^>]*>/g;
/**
* Multiple spaces
*/
export const MULTIPLE_SPACES_REGEX = /\s+/g;
// ============================================================================
// FILE PATTERNS
// ============================================================================
/**
* File extension
*/
export const FILE_EXTENSION_REGEX = /\.([a-zA-Z0-9]+)$/;
/**
* Image file extensions
*/
export const IMAGE_EXTENSION_REGEX = /\.(jpg|jpeg|png|gif|webp|svg|bmp|ico)$/i;
/**
* Document file extensions
*/
export const DOCUMENT_EXTENSION_REGEX = /\.(pdf|doc|docx|xls|xlsx|ppt|pptx|txt|csv)$/i;
/**
* Video file extensions
*/
export const VIDEO_EXTENSION_REGEX = /\.(mp4|avi|mov|wmv|flv|mkv|webm)$/i;
/**
* Audio file extensions
*/
export const AUDIO_EXTENSION_REGEX = /\.(mp3|wav|ogg|flac|aac|wma)$/i;
// ============================================================================
// HELPERS
// ============================================================================
/**
* Test if string matches pattern
*/
export const testPattern = (pattern: RegExp, value: string): boolean => {
return pattern.test(value);
};
/**
* Extract matches from string
*/
export const extractMatches = (
pattern: RegExp,
value: string,
): RegExpMatchArray | null => {
return value.match(pattern);
};
/**
* Replace all matches in string
*/
export const replaceAll = (
pattern: RegExp,
value: string,
replacement: string,
): string => {
return value.replace(pattern, replacement);
};