全新出发
This commit is contained in:
1 parent
b06c117b1e
commit
fa4edebed6
463 files changed
+181610
-125
No files matched your search
@@ -0,0 +1,43 @@
|
||||
export function escapeHtml(value: string): string {
|
||||
if (!value) return ''
|
||||
return String(value).replace(/[&<>"']/g, c => {
|
||||
switch (c) {
|
||||
case '&': return '&'
|
||||
case '<': return '<'
|
||||
case '>': return '>'
|
||||
case '"': return '"'
|
||||
case "'": return '''
|
||||
default: return c
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export function escapeAttribute(value: string): string {
|
||||
if (!value) return ''
|
||||
return String(value).replace(/[&<>"'`]/g, c => {
|
||||
switch (c) {
|
||||
case '&': return '&'
|
||||
case '<': return '<'
|
||||
case '>': return '>'
|
||||
case '"': return '"'
|
||||
case "'": return '''
|
||||
case '`': return '`'
|
||||
default: return c
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export function renderMultilineText(value: string): string {
|
||||
return escapeHtml(value).replace(/\r?\n/g, '<br />')
|
||||
}
|
||||
|
||||
export function decodeHtmlEntities(value: string): string {
|
||||
if (!value) return ''
|
||||
return String(value)
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, "'")
|
||||
.replace(/`/g, '`')
|
||||
}
|
||||
Reference in new issue
Block a user