1.0.0 • Published 10 months ago
custom_node_why v1.0.0
安装方式
使用npm进行安装
npm install custom_node_why
导入方式
const tools=require("custom_node_why")
格式化时间
//处理时间模块
//1.定义一个格式化时间的方法
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)
}
转义HTML中的特殊字符
//2.把特殊符号进行转义
// < : <
// > : >
// " : "
// & : &
function htmlEscape(h){
let result = h.replace(/<|>|"|&/g,function(d){
switch(d){
case "<":
return "<"
case ">":
return ">"
case '"':
return """
case "&":
return "&"
}
})
return result
}
##还原HTML中的特殊字符
//2.把转义后的特殊符号再还原回去
// < : <
// > : >
// " : "
// & : &
function htmlunEscape(h){
let result = h.replace(/<|>|"|&/g,function(d){
switch(d){
case "<":
return "<"
case ">":
return ">"
case """:
return '"'
case "&":
return "&"
}
})
return result
}
##开源协议
ISC
1.0.0
10 months ago