1.0.0 • Published 1 year ago

itheima-tools-yaooo v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

安裝

... npm install itheima-tools ...

導入

const itheima = require('itheima-tools')

格式化時間

//調用dateFormat 對時間進行格式化
const dtStr = itheima.dateFormat(new Date())
//結果
console.log(dtStr)

轉義 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

1.0.0

1 year ago