lupine.web
Version:
lupine.web is a extremely fast, small size and lightweight frontend framework, using React TSX syntax.
26 lines (22 loc) • 631 B
text/typescript
const htmlEscapes: Record<string, string> = {
'&': '&',
'<': '<',
'>': '>',
"'": ''',
'"': '"',
};
export const encodeHtml = (str: any): string => {
if (str === null || str === undefined) return '';
return String(str).replace(/[&<>'"]/g, (tag) => htmlEscapes[tag]);
};
const htmlUnescapes: Record<string, string> = {
'&': '&',
'<': '<',
'>': '>',
''': "'",
'"': '"',
};
export const decodeHtml = (str: string): string => {
if (str === null || str === undefined) return '';
return String(str).replace(/&(?:amp|lt|gt|quot|#39);/g, (tag) => htmlUnescapes[tag]);
};