1.0.0 • Published 1 year ago

itheima-tools-hq v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

安装

npm install itheima-tools-1

导入

const itheima = require("itheima-tools-1");

格式化时间

// 调用 dataFormat 对时间进行格式化
const data = itheima.dateFormat(new Date());
// 结果 2023-2-12 10:45:16
console.log(data);

转义 HTML 中的特殊字符

//定于带转换的字符串
const htmlStr = "<h1>您好!</h1>";

// 调用 htmlEscape 方法进行转换
const newHtml = itheima.htmlEscape(htmlStr);

// 转换后的结果:&lt;h1&gt;您好!&lt;/h1&gt;
console.log(newHtml);

还原 HTML 中特殊字符

// 带还原的字符串
const newHtml = "&lt;h1&gt;您好!&lt;/h1&gt";

// 调用 htmlUnEscape 方法进行还原
const htmlStr1 = itheima.htmlUnEscape(newHtml);

// 输出结果:<h1>您好!</h1>
console.log(htmlStr1);

开源协议

ISC