1.0.1 • Published 2 years ago

itheima-toolssss-apple v1.0.1

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

导入

const itheima = require('itheima-toolssss-apple')

格式化时间

//调用dateFormat 对时间进行格式化
const dtStr = itheima.dateFormat(new Date())
//结果 2022-08-04-20-57-47
consloe.log(daStr)

定义转义 HTML 字符的函数

//带转化的 HTML 字符串
const htmlStr = '<h1 title="123">qwe<span>1111</span></h1>'
// 调用 htmlEscape 方法进行转化
const Str = itheima.htmlEscape(htmlStr)
//转化的结果为 &lt;h1 title=&quot;123&quot;&gt;qwe&lt;span&gt;1111&lt;/span&gt;&lt;/h1&gt;
consloe.log(Str)

定义还原转义 HTML 字符的函数

//带需要还原的 HTML 字符串
const text = '&lt;h1 title=&quot;123&quot;&gt;qwe&lt;span&gt;1111&lt;/span&gt;&lt;/h1&gt;'
// console.log(str);
// 调用 htmlUnEscape 方法进行转化
const str = itheima.htmlUnEscape(text)
//转化的结果为 <h1 title="123">qwe<span>1111</span></h1>
console.log(str);

开源协议

ISC