22 lines
420 B
JavaScript
22 lines
420 B
JavaScript
"use strict"
|
|
/* istanbul ignore file */
|
|
|
|
function getEncodeHtml() {
|
|
const encodeHTMLRules = {
|
|
"&": "&",
|
|
"<": "<",
|
|
">": ">",
|
|
'"': """,
|
|
"'": "'",
|
|
"/": "/",
|
|
}
|
|
|
|
const matchHTML = /&(?!#?\w+;)|<|>|"|'|\//g
|
|
|
|
return function encodeHtml(s) {
|
|
return typeof s === "string" ? s.replace(matchHTML, (m) => encodeHTMLRules[m] || m) : s
|
|
}
|
|
}
|
|
|
|
module.exports = getEncodeHtml
|