1.0.0 • Published 3 years ago

wmt-tools v1.0.0

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

安装

npm i wmt-tools

导入

const wmt = require('wmt-tools')

格式化时间

//调用dataFormat方法进行时间的格式化
const dtStr = wmt.dataFormat(new Date());
// 结果 2022-02-11 17:21:30
console.log(dtStr)

转义HTML中特殊字符

//待转换的字符串
const htmlStr = '<h1 style="color: tomato">我是h1标签</h1>'
//调用htmlEscape方法进行转换
const str = wmt.htmlEscape(htmlStr);
//转换的结果为&lt;h1 style=&quot;color: tomato&quot;&gt;我是h1标签&lt;/h1&gt;
console.log(str);

还原HTML中特殊字符

//待转换的字符串
const str2 = '&lt;h1 style=&quot;color: tomato&quot;&gt;我是h1标签&lt;/h1&gt;';
//调用htmlUnEscape方法进行转换
const htmlStr2 =wmt.htmlUnEscape(str2);
//转换后的结果为<h1 style="color: tomato">我是h1标签</h1>
console.log(htmlStr2);

开源协议

ISC