1.0.0 • Published 3 years ago
wjcdiyige v1.0.0
使用说明
1.下载
npm i D2021x-utils
2.下载
2.1 格式化时间
function dateFormat(dtStr) {
var date = new Date(dtStr)
var y = date.getFullYear()
var m = padZero(date.getMonth() + 1)
var d = padZero(date.getDate())
return y + "-" + m + "-" + d
}
function padZero(n) {
if (n < 10) {
return '0' + n
}
return n
}
// module.exports = {
// dateFormat
// }
2.2 转义HTML
function htmlEscape(htmlStr) {
return htmlStr.replace(/<|>|"|&/g, (match) => {
switch (match) {
case '<':
return '<'
case '>':
return '>'
case '"':
return '"'
case '&':
return '&'
}
})
}
2.3 还原HTML
function htmlUnEscape(htmlStr) {
return htmlStr.replace(/<|>|"|&/g, (mathch) => {
switch (match) {
case '<':
return '<'
case '>':
return '>'
case '"':
return '"'
case '&':
return '&'
}
})
}
1.0.0
3 years ago