/** * @file Comprehensive Formatting Extension * @description Enterprise-grade formatting utilities for runtime use * * Features: * - String case converters (camelCase, PascalCase, snake_case, kebab-case, SCREAMING_SNAKE) * - Template helpers for use in template strings * - Number formatting (currency, percentage, decimal precision) * - Date formatting (ISO, relative, localized) * - Pluralization with smart singular/plural handling * - Truncation with ellipsis and word-aware * - Sanitization (HTML escape, URL encode, SQL escape) * - Code formatting (JSON pretty print, code highlighting) * - i18n support with locale-aware formatting * - Extensible custom formatter registry * * @version 2.0.0 */ export interface FormatOptions { locale?: string; timezone?: string; [key: string]: unknown; } export interface NumberFormatOptions extends Intl.NumberFormatOptions { locale?: string; } export interface CurrencyFormatOptions extends NumberFormatOptions { currency?: string; symbol?: boolean; } export interface DateFormatOptions extends Intl.DateTimeFormatOptions { locale?: string; relative?: boolean; format?: 'short' | 'medium' | 'long' | 'full' | 'iso' | 'custom'; } export interface TruncateOptions { length: number; ellipsis?: string; wordBoundary?: boolean; preserveWords?: boolean; } export interface PluralizeOptions { count?: number; inclusive?: boolean; irregulars?: Record; } export interface SanitizeOptions { allowedTags?: string[]; allowedAttributes?: Record; stripAll?: boolean; } export type FormatterFunction = (value: T, options?: FormatOptions) => R; export interface FormatterRegistry { register(name: string, formatter: FormatterFunction): void; unregister(name: string): boolean; get(name: string): FormatterFunction | undefined; has(name: string): boolean; list(): string[]; clear(): void; } /** * Convert string to camelCase * @example toCamelCase('hello-world') // 'helloWorld' */ export declare function toCamelCase(str: string): string; /** * Convert string to PascalCase * @example toPascalCase('hello-world') // 'HelloWorld' */ export declare function toPascalCase(str: string): string; /** * Convert string to snake_case * @example toSnakeCase('helloWorld') // 'hello_world' */ export declare function toSnakeCase(str: string): string; /** * Convert string to kebab-case * @example toKebabCase('helloWorld') // 'hello-world' */ export declare function toKebabCase(str: string): string; /** * Convert string to SCREAMING_SNAKE_CASE * @example toScreamingSnakeCase('helloWorld') // 'HELLO_WORLD' */ export declare function toScreamingSnakeCase(str: string): string; /** * Convert string to specific case type */ export declare function toCase(str: string, caseType: 'camel' | 'pascal' | 'snake' | 'kebab' | 'screaming'): string; /** * Format number with locale-aware formatting * @example formatNumber(1234.56, { locale: 'en-US', maximumFractionDigits: 2 }) // '1,234.56' */ export declare function formatNumber(value: number, options?: NumberFormatOptions): string; /** * Format number as currency * @example formatCurrency(1234.56, { currency: 'USD' }) // '$1,234.56' */ export declare function formatCurrency(value: number, options?: CurrencyFormatOptions): string; /** * Format number as percentage * @example formatPercentage(0.1234) // '12.34%' */ export declare function formatPercentage(value: number, options?: NumberFormatOptions): string; /** * Format number with decimal precision * @example formatDecimal(1234.5678, 2) // '1234.57' */ export declare function formatDecimal(value: number, precision?: number): string; /** * Format bytes to human-readable size * @example formatBytes(1024) // '1.00 KB' */ export declare function formatBytes(bytes: number, decimals?: number): string; /** * Format date with locale-aware formatting * @example formatDate(new Date(), { format: 'medium', locale: 'en-US' }) */ export declare function formatDate(date: Date | string | number, options?: DateFormatOptions): string; /** * Format relative time (e.g., "2 hours ago", "in 3 days") */ export declare function formatRelativeTime(date: Date | string | number, locale?: string): string; /** * Pluralize a word based on count * @example pluralize('person', 1) // 'person' * @example pluralize('person', 2) // 'people' * @example pluralize('item', 5, true) // '5 items' */ export declare function pluralize(word: string, count?: number, options?: PluralizeOptions): string; /** * Singularize a word * @example singularize('people') // 'person' */ export declare function singularize(word: string, options?: PluralizeOptions): string; /** * Truncate string to maximum length * @example truncate('Hello World', { length: 8 }) // 'Hello...' * @example truncate('Hello World', { length: 8, wordBoundary: true }) // 'Hello...' */ export declare function truncate(str: string, options: TruncateOptions): string; /** * Truncate string to number of words * @example truncateWords('Hello beautiful world', 2) // 'Hello beautiful...' */ export declare function truncateWords(str: string, wordCount: number, ellipsis?: string): string; /** * Escape HTML entities * @example escapeHtml('') // '<script>alert("XSS")</script>' */ export declare function escapeHtml(str: string): string; /** * Unescape HTML entities */ export declare function unescapeHtml(str: string): string; /** * Strip HTML tags * @example stripHtml('

Hello World

') // 'Hello World' */ export declare function stripHtml(str: string, options?: SanitizeOptions): string; /** * URL encode string * @example encodeUrl('hello world') // 'hello%20world' */ export declare function encodeUrl(str: string): string; /** * URL decode string */ export declare function decodeUrl(str: string): string; /** * Escape SQL string (basic protection, use parameterized queries in production) * @example escapeSql("'; DROP TABLE users--") // "''DROP TABLE users--" */ export declare function escapeSql(str: string): string; /** * Escape RegExp special characters * @example escapeRegex('hello.world') // 'hello\\.world' */ export declare function escapeRegex(str: string): string; /** * Pretty print JSON * @example formatJson({ name: 'John', age: 30 }) // '{\n "name": "John",\n "age": 30\n}' */ export declare function formatJson(value: unknown, indent?: number): string; /** * Compact JSON (remove whitespace) * @example compactJson('{\n "name": "John"\n}') // '{"name":"John"}' */ export declare function compactJson(json: string): string; /** * Format code with syntax highlighting (returns ANSI colored string for terminal) * Note: For web use, consider using a library like highlight.js or prism.js */ export declare function highlightCode(code: string, _language?: string): string; /** * Set default locale for all formatting operations */ export declare function setDefaultLocale(locale: string): void; /** * Get current default locale */ export declare function getDefaultLocale(): string; /** * Set default timezone */ export declare function setDefaultTimezone(timezone: string): void; /** * Get current default timezone */ export declare function getDefaultTimezone(): string | undefined; /** * Format value using locale-specific formatter */ export declare function formatLocalized(value: T, formatter: (value: T, locale: string) => string, locale?: string): string; /** * Global formatter registry instance */ export declare const formatterRegistry: FormatterRegistry; /** * Generic format function that uses the registry */ export declare function format(type: string, value: T, options?: FormatOptions): unknown; /** * Template helpers that can be used in template literals */ export declare const fmt: { camel: typeof toCamelCase; pascal: typeof toPascalCase; snake: typeof toSnakeCase; kebab: typeof toKebabCase; screaming: typeof toScreamingSnakeCase; number: (value: number, options?: NumberFormatOptions) => string; currency: (value: number, currency?: string, locale?: string) => string; percent: (value: number, options?: NumberFormatOptions) => string; bytes: typeof formatBytes; date: (date: Date | string | number, format?: DateFormatOptions) => string; relative: (date: Date | string | number, locale?: string) => string; iso: (date: Date | string | number) => string; truncate: (str: string, length: number, ellipsis?: string) => string; truncateWords: typeof truncateWords; plural: typeof pluralize; singular: typeof singularize; escape: typeof escapeHtml; stripTags: typeof stripHtml; urlEncode: typeof encodeUrl; json: typeof formatJson; highlight: typeof highlightCode; }; /** * Extension interface matching the enzyme extension system * This would need to be adjusted based on the actual enzyme extension types */ export interface EnzymeExtension { name: string; version?: string; description?: string; client?: Record unknown>; template?: { helpers?: Record unknown>; filters?: Record unknown>; }; } /** * Comprehensive formatting extension for Enzyme */ export declare const formattingExtension: { name: string; version: string; description: string; client: { $format: typeof format; $toCase: typeof toCase; $toCamelCase: typeof toCamelCase; $toPascalCase: typeof toPascalCase; $toSnakeCase: typeof toSnakeCase; $toKebabCase: typeof toKebabCase; $toScreamingSnakeCase: typeof toScreamingSnakeCase; $formatNumber: typeof formatNumber; $formatCurrency: typeof formatCurrency; $formatPercentage: typeof formatPercentage; $formatDecimal: typeof formatDecimal; $formatBytes: typeof formatBytes; $formatDate: typeof formatDate; $formatRelativeTime: typeof formatRelativeTime; $pluralize: typeof pluralize; $singularize: typeof singularize; $truncate: typeof truncate; $truncateWords: typeof truncateWords; $escapeHtml: typeof escapeHtml; $unescapeHtml: typeof unescapeHtml; $stripHtml: typeof stripHtml; $encodeUrl: typeof encodeUrl; $decodeUrl: typeof decodeUrl; $escapeSql: typeof escapeSql; $escapeRegex: typeof escapeRegex; $formatJson: typeof formatJson; $compactJson: typeof compactJson; $highlightCode: typeof highlightCode; $setLocale: typeof setDefaultLocale; $getLocale: typeof getDefaultLocale; $setTimezone: typeof setDefaultTimezone; $getTimezone: typeof getDefaultTimezone; $registerFormatter: (name: string, formatter: FormatterFunction) => void; $unregisterFormatter: (name: string) => boolean; $getFormatter: (name: string) => FormatterFunction | undefined; $listFormatters: () => string[]; }; template: { helpers: { camelCase: typeof toCamelCase; pascalCase: typeof toPascalCase; kebabCase: typeof toKebabCase; snakeCase: typeof toSnakeCase; screamingSnakeCase: typeof toScreamingSnakeCase; formatNumber: typeof formatNumber; formatCurrency: typeof formatCurrency; formatPercentage: typeof formatPercentage; formatDate: typeof formatDate; formatRelativeTime: typeof formatRelativeTime; pluralize: typeof pluralize; singularize: typeof singularize; truncate: (str: string, length: number) => string; escapeHtml: typeof escapeHtml; stripHtml: typeof stripHtml; formatJson: typeof formatJson; }; filters: { camel: typeof toCamelCase; pascal: typeof toPascalCase; kebab: typeof toKebabCase; snake: typeof toSnakeCase; screaming: typeof toScreamingSnakeCase; currency: (value: unknown, currency?: string) => string; percent: (value: unknown) => string; date: (value: unknown, format?: DateFormatOptions) => string; relative: (value: unknown) => string; plural: (value: unknown, count?: number) => string; singular: (value: unknown) => string; truncate: (value: unknown, length?: number) => string; escape: (value: unknown) => string; json: (value: unknown, indent?: number) => string; }; }; }; export default formattingExtension;