1.0.0 • Published 2 years ago

whhh-utils v1.0.0

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

安装

npm install whhh-utils

导入

const whhh = require("whhh-utils")

格式化时间

// 调用 dateFormat 对时间进行格式化
const dateStr = whhh.dateFormat(dt)
// dateStr = 2022-01-05 18:44:17
console.log("dateStr = " + dateStr)

转义html字符

// 待转换的字符串
const htmlStr = '<h1 title="abc">这是h1标签<span>123&nbsp;</span></h1>'
// 调用 htmlEscape 方法进行转换
const newHtml = whhh.htmlEscape(htmlStr)
// &lt;h1 title=&quot;abc&quot;&gt;这是h1标签&lt;span&gt;123&amp;nbsp;&lt;/span&gt;&lt;/h1&gt;
console.log(newHtml)

还原 html 字符

// 待还原的 html 字符串
const newHtmlStr = whhh.htmlUnEscape(newHtml)
// <h1 title="abc">这是h1标签<span>123&nbsp;</span></h1>
console.log(newHtmlStr)

开源协议

ISC