matt123-tools

1.0.0 • Public • Published

安装

 npm install matt-tools

导入

   const tools=require("matt-tools")

格式化时间

    //调用formatTime对时间进行格式化
    let time=tools.formatTime(new Date())
    //输出结果 2023-12-01 16:09:14
    console.log(time)

转义HTML中的特殊字符

    //调用htmlEncode对HTML中的特殊字符
    let str=tools.htmlEncode('<h1 style="color:#f12">哈哈哈&nbsp;</h1>')
    //输出结果 &lt;h1 style=&quot;color:#f12&quot;&gt;哈哈哈&amp;nbsp;&lt;/h1&gt;
    console.log(str)

还原HTML中特殊字符

    //调用htmlEncode对HTML中的特殊字符
    let str="&lt;h1 style=&quot;color:#f12&quot;&gt;哈哈哈&amp;nbsp;&lt;/h1&gt;"
    //输出结果 <h1 style="color:#f12">哈哈哈&nbsp;</h1>
    console.log(tools.htmlDecode(str))

开源协议

ISC

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i matt123-tools

      Weekly Downloads

      3

      Version

      1.0.0

      License

      ISC

      Unpacked Size

      2.47 kB

      Total Files

      5

      Last publish

      Collaborators

      • matt123