1.0.0 • Published 2 years ago

zhou-firstitheima v1.0.0

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

安装

npm install itheima-zhous

导入

const itheima = require('itheima-zhous')

格式化时间

//调用dateFormat 对时间进行格式化
const dtStr = itheima.dateFormat(new Date())
// 结果 2023-12-28 14:48:07
console.log(dtStr)

转义 HTML 中的特殊字符

// 带转换的HTML字符串
const htmlStr = '<h1 style="color:red">你好!&copy;<span>小黄!</span></h1>'
// 调用 htmlEscape 方法进行转换
const str = index.htmlEscape(htmlStr)
// 转换的结果&lt;h1 style=&quot;color:red&quot;&gt;你好!&amp;copy;&lt;span&gt;小黄!&lt;/span&gt;&lt;/h1&gt;
console.log(str)

还原 HTML 中的特殊字符

// 调用 htmlUnEscape 方法进行转换
const newStr = index.htmlUnEscape(str)
// 转换结果<h1 style="color:red">你好!&copy;<span>小黄!</span></h1>
console.log(newStr)

开源协议

ISC