1.1.0 • Published 3 years ago

tools-ysh v1.1.0

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

安装

npm install tools-ysh

导入

const text = require("./tools-ysh");

格式化时间

// 调用时间方法
const timeStr = text.dateFormat(new Date());
// 结果 2021-05-18 10:36:41
console.log(timeStr);

转义 HTML 中的特殊字符

// 标签变量
const str = '<h1 title="abc">这是h1标签<span>123&nbsp;</span></h1>';

// 调用转义 HTML 的方法
const htmlStr = text.htmlEscape(str);

// 结果 &lt;h1 title=&quot;abc&quot;&gt;这是h1标签&lt;span&gt;123&amp;nbsp;&lt;/span&gt;&lt;/h1&gt;
console.log(htmlStr);

还原 HTML 中的特殊字符

// 调用还原 HTML 的方法
const htmlStr2 = text.htmlUnEscape(htmlStr);
// 结果 <h1 title="abc">这是h1标签<span>123&nbsp;</span></h1>
console.log(htmlStr2);

开源协议

ISC