hg-first

提供了格式化时间、HTMLEscape相关的功能

Usage no npm install needed!

<script type="module">
  import hgFirst from 'https://cdn.skypack.dev/hg-first';
</script>

README

安装

npm install/i hg-first

导入

const hgfirst=require('hg-first')

格式化时间

// 调用 dateFormat 对时间进行格式化
const dateFormat=hgfirst.dataFormat(new Date())
// 结果  2020-04-03 17:20:58
console.log(dateFormat)

转义html字符

//如
const html='<h1 title="abc">这是h1标签<span>123&nbsp;</span></h1>'
// 调用 htmlEscape 转换字符
const htmlEscape=hgbirth.htmlEscape(html)
// 结果 &lt;h1 title=&quot;abc&quot;&gt;这是h1标签&lt;span&gt;123&amp;nbsp;&lt;/span&gt;&lt;/h1&gt;
console.log(htmlEscape)

还原html特殊字符

//如
const str='&lt;h1 title=&quot;abc&quot;&gt;这是h1标签&lt;span&gt;123&amp;nbsp;&lt;/span&gt;&lt;/h1&gt;'
// 调用 htmlUnEscape 转换字符
const htmlUnEscape = itheima.htmlUnEscape(str)
// 结果 '<h1 title="abc">这是h1标签<span>123&nbsp;</span></h1>'
console.log(htmlUnEscape)