1.0.0 • Published 3 years ago

itqinjiu-tools v1.0.0

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

安装

 npm i itqinjiu-tools

导入

const itqinjiu = require('itqinjiu-tools')
const htmlSwitch = require('./itqinjiu-tools')
const html = require("./itqinjiu-tools")

格式化时间

// 调用 deteTime 对时间格式化
const dtStr = itqinjiu.dateTime(new Date())
// 结果 2022-11-17  10:28:15
console.log(dtStr)

转义 HTML 中的字符串

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

还原 HTML 中字符串

// 待还原的字符串
const htmls = '&lt;h1 title="abc" &gt;这是h1标签&lt;span &gt;123 &nbsp;&lt;/span&gt;&lt;/h1 &gt;'
// 调用对应的 rehtml 方法进行转换
const rehtmls = html.rehtml(htmls)
// 结果 <h1 title="abc"> 这是h1标签<span>123 &nbsp;</span></h1>
console.log(rehtmls);

开源协议

ISC