1.0.0 • Published 3 years ago

itheima-tools-xiaobai v1.0.0

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

安装

npm install itheima-tools-bai

祝福介绍

白老板您好,祝您以后洪福齐天、长命百岁、永远不死~

导入

const itheima = require('itheima-tools-bai')

格式化时间

// 调用dateFormat 对时间进行格式化
const dtStr = itheima.dateForamt(new Date())
console.log(dtStr)
// 结果 : 2021-10-13 16:51:35

转义 HTML 中的特殊字符

// 定义了待转换的HTML字符串 
const htmlStr = '<h1 title="abc">这是h1便签<span>123&nbsp;</span></h1>'
// 调用了 htmlEscape 方法进行转换
const str = itheima.htmlEscape(htmlStr)
// 转换的结果:&lt;h1 title=&quot;abc&quot;&gt;这是h1便签&lt;span&gt;123&amp;nbsp;&lt;/span&gt;&lt;/h1&gt;
console.log(str)

还原 HTML 字符串

// 带还原得 HTML 字符串
const str2 = itheima.htmlUnEscape(Str)
// 输出得结果: <h1 title="abc">这是h1便签<span>123&nbsp;</span></h1>
console.log(str2)

开源协议

ISC