使用说明: 该包来自吴氏龙腾集团,如需转载请联系本集团获得授权后方可转载!
安装
npm install trachinoid-bloc
导入
const trach = require('trachinoid');
格式化代码
function dateform(dadastr) {
const date = new Date(dadastr);
const y = date.getFullYear();
const m = date.getMonth() + 1 > 9 ? date.getMonth() + 1 : '0' + (date.getMonth() + 1);
const d = date.getDay() > 9 ? date.getDay() : '0' + date.getDay();
const HH = date.getHours() > 9 ? date.getHours() : '0' + date.getHours();
const MM = date.getMinutes() > 9 ? date.getMinutes() : '0' + date.getMinutes();
const SS = date.getSeconds() > 9 ? date.getSeconds() : '0' + date.getSeconds();
return `${y}-${m}-${d} ${HH}:${MM}:${SS}`;
}
// 使用dateform()并传入new date()即可获得标准的时间格式;
转义HTML的特殊字符
function HTMLEscape(htmlstr) {
if (htmlstr == '') {
throw Error('请输入要转换的内容!');
return
}
return htmlstr.replace(/<|>|"|&/g, (match) => {
switch (match) {
case '<':
return '<'
case '>':
return '>'
case '"':
return '"'
case '&':
return '&'
}
})
}
// 使用HTMLescape() 输入字符串,将<,>,",&符号转换成转义符
开源协议
ISC