mydemo_scy
v1.0.0
Published
```npm install MyDemo``` ### 2.导入方式 ```const myDemo = require('MyDemo')``` ### 3.格式化时间方法 ```function formatDate() { function formatDate() { var date = new Date(time); var year = date.getFullYear(); var month = date.getMonth() + 1;
Downloads
3
Readme
1.安装方式
npm install MyDemo
2.导入方式
const myDemo = require('MyDemo')
3.格式化时间方法
function formatDate() {
var date = new Date(time);
var year = date.getFullYear();
var month = date.getMonth() + 1;
var day = date.getDate();
var hour = date.getHours();
var minute = date.getMinutes();
var second = date.getSeconds();
return year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second;
}
}
4.html转义方法
function htmlEscape(htmlStr) {
return htmlStr.replace(/<|>|"|&/g,(match)=>{
switch (match) {
case "<":
return "<";
case ">":
return ">";
case "\"":
return """;
case "&":
return "&";
}
})
}
5.html反转义方法
return htmlStr.replace(/<|>|"|&/g,(match)=>{
switch (match) {
case "<":
return "<";
case ">":
return ">";
case """:
return "\"";
case "&":
return "&";
}
})```