/** * Strings manipulation module * * @module strings * * @example * Import all string utilities: * ```typescript * import { fillTemplate, isTextMatch, getRandomString, f } from '@vvlad1973/utils'; * ``` * * @example * Import specific utilities: * ```typescript * import { getRandomString, f } from '@vvlad1973/utils'; * ``` */ /** * Fills placeholders in a template string using values from a context object. * Supports @TAGS, handlebars {{...}}, format-style %d/%s, regex-based inclusion. * * @param template - The template string * @param context - Values to insert * @returns Promise resolving to filled template string * * @example * ```typescript * const context = { name: 'John', age: 30 }; * const result = await fillTemplate('Hello @name, you are %d years old:[age]', context); * // result: 'Hello John, you are 30 years old' * ``` */ export declare function fillTemplate(template: string, context: any): Promise; /** * Checks if a text string matches a specified pattern * * @param text - Text string for pattern matching * @param pattern - Pattern for matching * @param isRegExp - Flag indicating that the pattern is a regular expression * @param flags - String with flags for regular expression matching * @returns True if pattern matches, false otherwise * * @example * ```typescript * isTextMatch('test', 'Te.*', true, 'i'); // true * isTextMatch('test', 'test'); // true * isTextMatch('test', 'other'); // false * ``` */ export declare function isTextMatch(text: string, pattern: string, isRegExp?: boolean, flags?: string): boolean; /** * Generates a random string of specified length and character set * * @param len - The length of the random string * @param charSet - The character set to use. Defaults to alphanumeric * @returns Generated random string * @throws {Error} If len is not a positive integer or if charSet is empty * * @example * ```typescript * const random = getRandomString(10); * // returns a 10-character random alphanumeric string * * const randomDigits = getRandomString(6, '0123456789'); * // returns a 6-digit random number string * ``` */ export declare function getRandomString(len: number, charSet?: string): string; /** * Counts the number of placeholders in a template string * * @param template - The template string to count placeholders in * @returns The number of placeholders found * * @example * ```typescript * countPlaceholders('Hello %s, you are %d years old'); // 2 * countPlaceholders('No placeholders here'); // 0 * ``` */ export declare function countPlaceholders(template: string): number; /** * Checks if a text string matches any of the regular expressions in the given array * * @param str - The text string to match * @param regexArray - An array of regular expressions to match against * @returns True if text matches any regex, false otherwise * * @example * ```typescript * matchesAnyRegExp('test@example.com', [/\w+@\w+\.\w+/, /\d+/]); // true * matchesAnyRegExp('hello', [/\d+/, /world/]); // false * ``` */ export declare function matchesAnyRegExp(str: string, regexArray: RegExp[]): boolean; /** * Formats a string using placeholders similar to util.format * * Supports the following format specifiers: * - %s for string conversion * - %d for integer conversion * - %j for JSON string conversion * - %% for literal percent signs * * @param template - The string template containing format specifiers * @param args - Values to replace the format specifiers * @returns The formatted string * * @example * ```typescript * f('My name is %s, I am %d years old.', 'John', 30); * // returns: "My name is John, I am 30 years old." * * f('JSON object: %j', { name: 'John', age: 30 }); * // returns: "JSON object: {\"name\":\"John\",\"age\":30}" * * f('Percent: %%'); * // returns: "Percent: %" * ``` */ export declare function f(template: string, ...args: any[]): string;