newsdsllissd

提供了格式化时间,HTMLEscape的功能

Usage no npm install needed!

<script type="module">
  import newsdsllissd from 'https://cdn.skypack.dev/newsdsllissd';
</script>

README

安装

npm install little-tools

导入

const littleTools = require('little-tools')

格式化时间

// 调用 dateFormat 对时间进行格式化
const dtStr = littleTools.dateFormat(new Date())
// 结果  2021-08-17 20:46:33
console.log(dtStr);

转义 HTML 中的特殊字符

// 待转换的 HTML 字符串
const htmlStr = '<h1 title="h1">我是一个h1标签&nbsp;!</h1>'
// 调用 htmlEscape 方法进行转换
const str = littleTools.htmlEscape(htmlStr)
// 结果  &lt;h1 title=&quot;h1&quot;&gt;我是一个h1标签&amp;nbsp;!&lt;/h1&gt;
console.log(str);    

还原 HTML 中的特殊字符

// 待还原的 HTML 字符串
const str2 = littleTools.htmlUnEscape(str)
// 结果  <h1 title="h1">我是一个h1标签&nbsp;!</h1>
console.log(str2);   

开源协议

ISC