mirror of
https://github.com/DayuanJiang/next-ai-draw-io.git
synced 2026-01-02 22:32:27 +08:00
15 lines
380 B
TypeScript
15 lines
380 B
TypeScript
|
|
export function formatMessage(
|
||
|
|
template: string | undefined,
|
||
|
|
vars?: Record<string, string | number | undefined>,
|
||
|
|
): string {
|
||
|
|
if (!template) return ""
|
||
|
|
if (!vars) return template
|
||
|
|
|
||
|
|
return template.replace(/\{(\w+)\}/g, (match, name) => {
|
||
|
|
const val = vars[name]
|
||
|
|
return val === undefined ? match : String(val)
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
export default formatMessage
|