xiaoyuan-tools

提供了格式化时间、HTML符号转义等功能

Usage no npm install needed!

<script type="module">
  import xiaoyuanTools from 'https://cdn.skypack.dev/xiaoyuan-tools';
</script>

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);
// 转换的结果:&lt;h1 style=&quot;color:red;&quot;&gt;Hello &amp;World&lt;/h1&gt;
console.log(str);

还原HTML中的特殊字符

// 待转换的普通字符串
const str = `&lt;h1 style=&quot;color:red;&quot;&gt;Hello &amp;World&lt;/h1&gt;`;
// 调用 transHTML 方法进行转换
const htmlStr = xy.transHTML(str);
// 转换的结果:<h1 style="color:red;">Hello &World</h1>
console.log(htmlStr);

开源协议

ISC