1.0.0 • Published 3 years ago

itlyx-utils v1.0.0

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

安装

npm install itlyx-utils

导入

const itlyx = require('itlyx-utils')

格式化时间

// 调用 dataFormat 对时间进行格式化
const dt =  itlyx.dataFormat(new Date)
// 2022-03-24 22-37-10
console.log(dt)

转义html 字符串的方法

// 定义一个常量 保存 html 字符串
const html = '<h1 title="abc">这是h1标签<span>123$gt;&nbsp</span></h1>'
// 调用htmlEacape 对 html字符串 进行转义
const str = itlyx.htmlEacape(html)
// 结果:&lt;h1 title=&quot;abc&quot;&gt;这是h1标签&lt;span&gt;123$gt;&ampnbsp&lt;/span&gt;&lt;/h1&gt;
console.log(str)

还原html 字符串的方法

// str = $lt;h1 title=&quot;abc&quot;&gt;这是h1标签$lt;span&gt;123$gt;&ampnbsp$lt;/span&gt;$lt;/h1&gt;
const htmlun = itlyx.htmlunEacape(str);
// 结果: <h1 title="abc">这是h1标签<span>123$gt;&ampnbsp</span></h1>
console.log(htmlun)