18 lines
585 B
TypeScript
18 lines
585 B
TypeScript
// 문자열에 들어있는 [$SID], [$헤더명] 치환 토큰을 values에 있는 값으로 바꾼다.
|
|
// 값이 없는 토큰은 빈 문자열로 치환한다.
|
|
export const substituteVariables = (contents: string, values: Record<string, string>) =>
|
|
contents.replace(/\[\$([^\]]+)\]/g, (_, key: string) => values[key] ?? "");
|
|
|
|
export const escapeHtml = (value: string) =>
|
|
value.replace(
|
|
/[&<>"']/g,
|
|
(character) =>
|
|
({
|
|
'&': '&',
|
|
'<': '<',
|
|
'>': '>',
|
|
'"': '"',
|
|
"'": ''',
|
|
})[character] ?? character,
|
|
);
|