1.0.0 • Published 2 years ago

andy01-tools v1.0.0

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

Desc

这个包仅仅是用来学习如何构建一个npm包。

安装

npm install andy-tools

开发环境下安装

npm install andy-tools -D 

使用

导入

const andy = require('andy-tools')

格式化时间

// 调用 dateFormat 格式化时间
const dtStr = andy.dateFormat(new Date())
// 结果:2022-01-08 14:24:24
console.log(dtStr)

转移HTML中的特殊字符

const htmlStr = '<h1 title="abc">H1标签&nbsp;</h1>'
const escapeHtml = tools.htmlEscape(htmlStr)
console.log(escapeHtml)
// 结果:&lt;h1 title=&quot;abc&quot;&gt;H1标签&amp;nbsp;&lt;/h1&gt;

还原HTML字符串函数

const str = '&lt;h1 title=&quot;abc&quot;&gt;H1标签&amp;nbsp;&lt;/h1&gt;'
const html = tools.htmlUnEscape(escapeHtml)
console.log(html)
// 结果:<h1 title="abc">H1标签&nbsp;</h1>

License

ISC