UNPKG

mytools-dxf

Version:

提供了格式化事件,HTMLEscape的功能

45 lines (39 loc) 1.3 kB
<!-- * @Author: error: git config user.name && git config user.email & please set dead value or install git * @Date: 2022-08-22 10:42:23 * @LastEditors: error: git config user.name && git config user.email & please set dead value or install git * @LastEditTime: 2022-08-22 17:55:12 * @FilePath: \nodeText\myTools-dxf\README.md * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE --> ## 安装 ```js npm install mytools-dxf ``` ## 导入 ```js const dxf = require('mytools-dxf') ``` ## 格式化时间 ```js const dtStr = dxf.dateFormat(new Date()) console.log(dtStr) // 结果:2022-08-22-14-53-42 ``` ## 转义 HTML 中的特殊字符串 ```js // 待转换的HTML字符串 const htmlStr = '<h1 title="abc">这是h1标签<span>123&nbsp;</span></h1>' // 调用htmlEscape 方法进行转换 const str = dxf.htmlEscape(htmlStr) console.log(str) // &lt;h1 title=&quot;abc&quot;&gt;这是h1标签&lt;span&gt;123&amp;nbsp;&lt;/span&gt;&lt;/h1&gt; ``` ## 还原 HTML 中的特殊字符 ```js const str2 = dxf.htmlUnEscape(str) console.log(str2) // <h1 title="abc">这是h1标签<span>123&nbsp;</span></h1> ``` ## 开源协议 ISC