1.0.0 • Published 2 years ago
my-tools-lyz v1.0.0
1.安装方式
1.1使用npm安装
npm i my-tools
2.导入方式
const my = require("my-tools")
3.格式化时间
function dataFormat(){
//自带了data时间类
var date = new Date()
//获取年
var year = date.getFullYear()
//获取月份,从0开始
var month =date.getMonth()+1
//获取日
var dates = date.getDate()
var day = date.getDay()
var shi=date.getHours()
var fen=date.getMinutes()
var miao=date.getSeconds()
console.log(year+"年"+month+"月"+dates+"日"+shi+"时"+fen+"分"+miao+"秒")
//理想的时间格式:2022年9月29日 19:20:30
}
module.exports={
dataFormat
}
4.转义HTML中的特殊字符
function dataFormat(){
}
//转义特殊字符
//<:<
//>:>
//":"
//&:&
function zhuanHtml(html){
return html.replace(/<|>|"|&/g,(i)=>{
switch(i){
case "<" :
return "<";
case ">" :
return ">";
case '"' :
return """;
case '&':
return "&";
}
})
}
5.还原HTML中的特殊字符
function huanHtml(html){
return html.replace(/<|>|"|&/g,(i)=>{
switch(i){
case "<":
return "<";
case ">" :
return ">";
case """:
return '"';
case "&":
return '&';
}
})
}
6.开源协议
ISC
1.0.0
2 years ago