yuhuan-itheima-tools

1.0.0 • Public • Published

安装

npm install yuhuan-itheima-tools

导入

const itheima = require('../yuhuan-itheima-tools'

格式化时间用法

//调用dateFormat对时间进行格式化
const str = itheima.dateFormat(new Date())
//结果2024-01-29 10:24:03

转义HTML中的特殊字符为字符实体

//带转换的HTML字符串,调用htmlEscape方法进行转换
const str2 = itheima.htmlEscape('<h1 title="abc"><span>123</span></h1>')
//转换结果&lt;h1 title=&quot;abc&quot;&gt;&lt;span&gt;123&lt;/span&gt;&lt;/h1&gt;
console.log(str2)

还原 HTML 中的特殊字符

//带还原的HTML字符串,调用htmlUnEscape方法进行还原
const str3 = itheima.htmlUnEscape('&lt;h1 title=&quot;abc&quot;&gt;&lt;span&gt;123&lt;/span&gt;&lt;/h1&gt;')
//输出结果<h1 title="abc"><span>123</span></h1>
console.log(str3)

开源协议

ISC

/yuhuan-itheima-tools/

    Package Sidebar

    Install

    npm i yuhuan-itheima-tools

    Weekly Downloads

    0

    Version

    1.0.0

    License

    ISC

    Unpacked Size

    3.3 kB

    Total Files

    6

    Last publish

    Collaborators

    • yuhuan