UNPKG

itheima-zwhy

Version:

提供了格式化时间日期,转换特殊字符,yyds

35 lines (34 loc) 815 B
// 定义转换HTML字符函数 function changeStr(htmlStr) { return htmlStr.replace(/<|>|"|&/g, (str) => { switch (str) { case '<': return '&lt' case '>': return '&gt' case '"': return '&quot' case '&': return '&amp' } }) } // 定义还原HTML字符函数 function deacidizing(abc) { return abc.replace(/&lt|&gt|&quot|&amp/g, (str1) => { switch (str1) { case '&lt': return '<' case '&gt': return'>' case '&quot ': return '"' case '&amp': return '&' } }) } module.exports = { changeStr, deacidizing }