1.1.0 • Published 3 years ago

itwcytools v1.1.0

Weekly downloads
-
License
LIS
Repository
-
Last release
3 years ago

安装

npm install wcy-tools

导入

const wcy =require('wcy-tools');

格式化化时间的代码

//调用 dateFormat 对时间进行格式化
const dtStr = wcy.dateFormat(new Date());
//结果返回 2022-04-05 14:06:23
console.log(dtStr);  

转义 HTML中的特殊字符

//带转换的 HTML字符串
const htmlStr = '<h1 title="abc">这是h1标签<span>123&nbsp</span>;<h1>'
//调用htmlEscape()进行转化
const str = wcy.htmlEscape(htmlStr);
// 输出结果 &lt;h1 title=&quot;abc&quot;&gt;这是h1标签&lt;span&gt;123&amp;nbsp&lt;/span&gt;;&lt;/h1&gt;
console.log(str);

还原HTML 中的转换字符

//带还原的HTML字符串
const str1 = wcy.htmlUnEscape(str);
//输出结果 <h1 title="abc">这是h1标签<span>123&nbsp</span>;</h1>
console.log(str1);

开源协议

ISC