itheima-shanhu

1.0.1 • Public • Published

说明

安装

npm install itheima-shanhu

导入

const itheima = require('itheima-shanhu')

格式化时间

const dt = itheima.dateFormat(new Date())
// 输出 2020-01-20 10:47:32
console.log(dt)

转义 HTML 中的特殊字符

// 待转换的 HTML 字符串
const htmlStr = '<h1 style="color: red;">你好!&copy;<span>小黄!</span></h1>'

// 调用 htmlEscape 进行转换
const str = itheima.htmlEscape(htmlStr)

// 输出 &lt;h1 style=&quot;color: red;&quot;&gt;你好!&amp;copy;&lt;span&gt;小黄!&lt;/span&gt;&lt;/h1&gt;
console.log(str)

还原 HTML 中的特殊字符

const rawHTML = itheima.htmlUnEscape(str)

// 输出 <h1 style="color: red;">你好!&copy;<span>小黄!</span></h1>
console.log(rawHTML)

开源协议

/itheima-shanhu/

    Package Sidebar

    Install

    npm i itheima-shanhu

    Weekly Downloads

    0

    Version

    1.0.1

    License

    ISC

    Unpacked Size

    2.58 kB

    Total Files

    5

    Last publish

    Collaborators

    • shanhu666