1.0.0 • Published 2 years ago

itheima-tools-xwd v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

安装

    npm install itheima-tools-xwd

导入

const it = require('itheima-tools-xwd')

格式化时间

//调用 dateFormat 对时间进行格式化
const time = it.dateFormat(new Date());
//结果 2022-05-26	19:21:06
console.log(time)

转义 HTML中的特殊字符

//定义了待转换的字符串
const str = '<h1>我是<span>和h1</span>标签</h1>';
//调用 html 方法进行转换
let resu = it.html(str);
//转换结果 &lt;h1&gt;我是&lt;span&gt;和h1&lt;/span&gt;标签&lt;/h1&gt;
console.log(resu);

还原 HTML中的特殊字符

//定义了待还原的字符串
const unstr = '&lt;h1&gt;我是&lt;span&gt;和h1&lt;/span&gt;标签&lt;/h1&gt;'
let unresu = it.unhtml(unstr);
console.log(unresu)

开源协议

ISC