/** * Pre-built safe pattern utilities for common string operations. * * These utilities avoid vulnerable regex patterns like alternation with * greedy quantifiers (e.g., /^\/+|\/+$/g) that can cause ReDoS attacks. */ /** * Remove leading occurrences of a character from a string. * * This is a safe alternative to patterns like /^X+/ that avoids * potential ReDoS issues with alternation patterns. * * @param input - String to trim * @param char - Single character to remove from the start * @returns String with leading characters removed * * @example * ```typescript * trimLeading('///path', '/'); // 'path' * trimLeading('---name', '-'); // 'name' * trimLeading('hello', 'x'); // 'hello' * ``` */ export declare function trimLeading(input: string, char: string): string; /** * Remove trailing occurrences of a character from a string. * * This is a safe alternative to patterns like /X+$/ that avoids * potential ReDoS issues with alternation patterns. * * @param input - String to trim * @param char - Single character to remove from the end * @returns String with trailing characters removed * * @example * ```typescript * trimTrailing('path///', '/'); // 'path' * trimTrailing('name---', '-'); // 'name' * trimTrailing('hello', 'x'); // 'hello' * ``` */ export declare function trimTrailing(input: string, char: string): string; /** * Remove both leading and trailing occurrences of a character from a string. * * This is a safe alternative to the vulnerable pattern /^X+|X+$/g * which uses alternation with greedy quantifiers and can cause ReDoS. * * @param input - String to trim * @param char - Single character to remove from both ends * @returns String with leading and trailing characters removed * * @example * ```typescript * trimBoth('///path///', '/'); // 'path' * trimBoth('---name---', '-'); // 'name' * trimBoth('/single/', '/'); // 'single' * ``` */ export declare function trimBoth(input: string, char: string): string; /** * Remove multiple leading/trailing characters from a string. * * @param input - String to trim * @param chars - Set of characters to remove from both ends * @returns String with specified characters removed from both ends * * @example * ```typescript * trimChars(' -name- ', new Set([' ', '-'])); // 'name' * ``` */ export declare function trimChars(input: string, chars: Set): string; /** * Extract parameters from a braced template string safely. * * Uses a non-backtracking approach to parse {param} patterns, * avoiding the vulnerable /\{([^}]+)\}/g pattern. * * @param template - Template string containing {param} placeholders * @param maxLength - Maximum template length to process (default: 50000) * @returns Array of parameter names found in the template * * @example * ```typescript * extractBracedParams('/users/{userId}/posts/{postId}'); * // ['userId', 'postId'] * * extractBracedParams('Hello {name}!'); * // ['name'] * ``` */ export declare function extractBracedParams(template: string, maxLength?: number): string[]; /** * Expand a template string by replacing {param} placeholders with values. * * Uses a safe character-by-character approach instead of regex. * * @param template - Template string containing {param} placeholders * @param values - Object mapping parameter names to values * @param maxLength - Maximum template length to process (default: 50000) * @returns Expanded string with placeholders replaced * * @example * ```typescript * expandTemplate('/users/{userId}', { userId: '123' }); * // '/users/123' * * expandTemplate('Hello {name}!', { name: 'World' }); * // 'Hello World!' * ``` */ export declare function expandTemplate(template: string, values: Record, maxLength?: number): string; /** * Check if a string contains template placeholders. * * Uses a simple indexOf check instead of regex. * * @param str - String to check * @param maxLength - Maximum string length to check (default: 50000) * @returns true if string contains {param} style placeholders */ export declare function hasTemplatePlaceholders(str: string, maxLength?: number): boolean; /** * Collapse multiple consecutive characters into a single occurrence. * * Safe alternative to patterns like /X+/g which can be combined * with other patterns to create ReDoS vulnerabilities. * * @param input - String to process * @param char - Character to collapse * @returns String with consecutive characters collapsed * * @example * ```typescript * collapseChar('foo///bar', '/'); // 'foo/bar' * collapseChar('hello world', ' '); // 'hello world' * ``` */ export declare function collapseChar(input: string, char: string): string; /** * Collapse all whitespace to single spaces. * * Safe alternative to /\s+/g which can be part of vulnerable patterns. * * @param input - String to process * @param maxLength - Maximum input length to process (default: 50000) * @returns String with whitespace collapsed to single spaces * * @example * ```typescript * collapseWhitespace('hello world\n\nfoo'); // 'hello world foo' * ``` */ export declare function collapseWhitespace(input: string, maxLength?: number): string;