( template: string, values: Record<string, ErrorMessageTemplateValue>, )
| 258 | * @param values A map of variable names to their values. |
| 259 | */ |
| 260 | export function applyErrorMessageTemplate( |
| 261 | template: string, |
| 262 | values: Record<string, ErrorMessageTemplateValue>, |
| 263 | ): string { |
| 264 | return template.replaceAll(/{(.*?)}/g, (_match, variableName) => { |
| 265 | const rawValue = values[variableName]; |
| 266 | |
| 267 | if (rawValue === undefined) { |
| 268 | return "undefined"; |
| 269 | } |
| 270 | |
| 271 | if (rawValue === null) { |
| 272 | return "null"; |
| 273 | } |
| 274 | |
| 275 | if (typeof rawValue === "bigint") { |
| 276 | return `${rawValue}n`; |
| 277 | } |
| 278 | |
| 279 | if (Array.isArray(rawValue)) { |
| 280 | return JSON.stringify(rawValue); |
| 281 | } |
| 282 | |
| 283 | return rawValue.toString(); |
| 284 | }); |
| 285 | } |
no test coverage detected