DenReg/jsx-html/node/utils/htmlEncode.ts

13 lines
358 B
TypeScript
Raw Normal View History

2020-10-14 00:56:11 +00:00
export function doubleQuoteEncode(text: string): string {
return text
.replace(/"/g, '"')
}
export function htmlEncode(text: string): string {
return doubleQuoteEncode(text
.replace(/&/g, '&')
.replace(/\//g, '/')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/'/g, '&#39;'));
}