Files
nodecrypt/web/util.string.js
T
2025-05-24 16:18:47 +08:00

16 lines
356 B
JavaScript

export function escapeHTML(str) {
if (typeof str !== 'string') return '';
return str.replace(/[&<>"']/g, function(c) {
return {
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
'\'': '&#39;'
} [c]
})
}
export function textToHTML(text) {
if (typeof text !== 'string') return '';
return escapeHTML(text).replace(/\n/g, '<br>')
}