1.0.0 • Published 3 years ago

itheima88-tools v1.0.0

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

安装

npm install itheima88-tools

导入

const itheima = require('itheima88-tools')

格式化时间

// 调用dateFormat方法格式化时间
const time = itheima.dateFormat(new Date())
// 结果 2021-02-08 17:00:22
console.log(time);

转译 HTML

// 调用htmlEscape 这个方法 对HTML字符进行转译
const str = itheima.htmlEscape('<h1>转移成功<span>&nbsp</span></h1>')
// 结果  &lt;h1&gt;转移成功&lt;span&gt;&amp;nbsp&lt;/span&gt;&lt;/h1&gt;
console.log(str);

把转译的HTML字符还原

// 调用 htmlUnEscape 这个方法,还原HTML字符
const str2 = itheima.htmlUnEscape(str)
// 结果 <h1>转移成功<span>&nbsp</span></h1>
console.log(str2);

开源协议

ISC