README
安装
npm install xiaoyuan-tools
导入
const xy = require('xiaoyuan-tools');
格式化时间
// 获取时间
const date = new Date();
// 调用dateFormat方法对时间进行格式化
const dtStr = xy.dateFormat(date);
// 结果例如:2021-01-06 19:25:25
console.log(dtStr);
转义HTML中的特殊字符
// 待转换的HTML字符串
const htmlStr = `<h1 style="color:red;">Hello &World</h1>`;
// 调用 transSymbol 方法进行转换
const str = xy.transSymbol(htmlStr);
// 转换的结果:<h1 style="color:red;">Hello &World</h1>
console.log(str);
还原HTML中的特殊字符
// 待转换的普通字符串
const str = `<h1 style="color:red;">Hello &World</h1>`;
// 调用 transHTML 方法进行转换
const htmlStr = xy.transHTML(str);
// 转换的结果:<h1 style="color:red;">Hello &World</h1>
console.log(htmlStr);
开源协议
ISC