1.0.0 • Published 1 month ago

snngt-tools v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
1 month ago

安装

npm install snngt-tools

导入

const snngt = require('./snngt-tools')

格式化时间

// 调用 dateFormat 对时间进行格式化
const dtStr = snngt.dateFormat(new Date())

// 打印结果 形如 2024-04-09 17:36:14
console.log(dtStr);

转义 HTML 中的特殊字符

// 定义需要转义的字符串
const htmlStr = '<h1 title="abc">这是h1标签<span>123&nbsp;</span></h1>'

// 调用 htmlEscape 方法进行转义
const str = snngt.htmlEscape(htmlStr)

// 打印结果  形如 &lt;h1 title&#61;&quot;abc&quot;&gt;这是h1标签&lt;span&gt;123&amp;nbsp;&lt;&#47;span&gt;&lt;&#47;h1&gt;
console.log(str);

还原 HTML 中的特殊字符

// 继续调用 htmlEscape 方法进行还原
const unstr = snngt.htmlUnescape(str)

// 打印结果  形如 <h1 title="abc">这是h1标签<span>123&nbsp;</span></h1>
console.log(unstr);

开源协议

ISC

1.0.0

1 month ago