npm i my-tools
const my = require("my-tools")
//格式化时间
function dateFormat(){
const date = new Date()
const y = date.getFullYear()
//月份从0开始
const m = date.getMonth()+1
const d = date.getDate()
const hh = date.getHours()
const mm = date.getMinutes()
const ss = date.getSeconds()
// 2022-8-11 19:56:40
console.log(y+"-"+m+"-"+d+" "+hh+":"+mm+":"+ss)
}
//转化特殊字符
// < : <
// > : >
// " : "
//输入:<h1>我爱学习</h1>
//结果:<h1>我爱学习</>
function htmlEscape(str){
const s = str.replace(/>|<|"/g,(i)=>{
switch(i){
case ">":
return ">"
case "<":
return "<"
case '"':
return """
}
})
console.log(s)
}
//还原特殊字符
function htmlunEscape(str){
const s = str.replace(/>|<|"/g,(i)=>{
switch(i){
case ">":
return ">"
case "<":
return "<"
case '"':
return '"'
}
})
console.log(s)
}
ISC