html.ts
This file
Path
src/utils/html.ts
13 lines 路 383 bytes 路 TypeScript
Last changed by
refactor(html): make `html` as middleware (#319)Yusuke Wadabefore adoption5976a60
History of this fileTake it
1234567891011121314export type HtmlEscapedString = string & { isEscaped: true }
const entityMap: Record<string, string> = { '&': '&', '<': '<', '>': '>', '"': '"',}const escapeRe = new RegExp(`[${Object.keys(entityMap).join('')}]`, 'g')const replaceFn = (m: string) => entityMap[m]export const escape = (str: string): string => { return str.replace(escapeRe, replaceFn)}