/** * 字符串模板替换工具函数 * 使用单次遍历和正则表达式缓存来提高性能 */ type ReplacementMap = Record; /** * 字符串模板替换函数 * @param template 模板字符串,如 "Hello {name}, you have {count} messages" * @param replacements 替换对象,如 { name: "John", count: "5" } * @param beginSeg 占位符开始符号,默认为 "{" * @param endSeg 占位符结束符号,默认为 "}" * @returns 替换后的字符串 * * @example * ```ts * replaceTemplate("Hello {name}!", { name: "World" }) * // => "Hello World!" * * replaceTemplate("Price: {{amount}}", { amount: "$100" }, "{{", "}}") * // => "Price: $100" * * replaceTemplate("You have {count} items", { count: "5", unused: "test" }) * // => "You have 5 items" (unused 键会被忽略) * * replaceTemplate("Hello ${name}!", { name: "World" }, "${", "}") * // => "Hello World!" * ``` */ export declare function replaceTemplate(template: string, replacements: ReplacementMap, beginSeg?: string, endSeg?: string): string; /** * 批量字符串模板替换函数(用于一次性替换多个模板) * @param templates 模板字符串数组 * @param replacements 替换对象 * @param beginSeg 占位符开始符号,默认为 "{" * @param endSeg 占位符结束符号,默认为 "}" * @returns 替换后的字符串数组 * * @example * ```ts * replaceTemplates( * ["Hello {name}!", "You have {count} items"], * { name: "John", count: "5" } * ) * // => ["Hello John!", "You have 5 items"] * * replaceTemplates( * ["Hello {{name}}!", "Price: {{amount}}"], * { name: "John", amount: "$100" }, * "{{", * "}}" * ) * // => ["Hello John!", "Price: $100"] * ``` */ export declare function replaceTemplates(templates: string[], replacements: ReplacementMap, beginSeg?: string, endSeg?: string): string[]; /** * 从模板字符串中提取所有占位符键名 * @param template 模板字符串 * @param beginSeg 占位符开始符号,默认为 "{" * @param endSeg 占位符结束符号,默认为 "}" * @returns 占位符键名数组(去重) * * @example * ```ts * extractPlaceholders("Hello {name}, you have {count} new {count} messages") * // => ["name", "count"] * * extractPlaceholders("Hello {{name}}, price is {{amount}}", "{{", "}}") * // => ["name", "amount"] * ``` */ export declare function extractPlaceholders(template: string, beginSeg?: string, endSeg?: string): string[]; export {};