1.0.0 • Published 5 years ago

nd-tools v1.0.0

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

安装包

npm install itheima-tools

导入方式

const itheima = require('./itheima-tools')

格式化时间

// 调用 dateFormat 格式化时间
const dt = itheima.dateFormat(new Date())
// 结果 2020-11-08 09:43:22
console.log(dt);

转义 HTML 中的特殊字符

// 定义 html特殊字符
const htmlStr = '<h1>时间&nbsp;</h2>'
// 调用 htmlEscape 转义特殊字符
const html = itheima.htmlEscape(htmlStr)
// 结果 &lt;h1&gt;时间&nbsp;&lt;/h2&gt;
console.log(html);

还原 HTML 中的特殊字符

// 调用 htmlUnEscape 还原HTML 中的特殊字符
const str = itheima.htmlUnEscape 还原(html)
// 结果 <h1>时间&nbsp;</h2>
console.log(str);
1.0.0

5 years ago