1.0.0 • Published 1 year ago

nancy-package v1.0.0

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

安装

npm install nancy-package

导入

const nancy = require("nancy-package");

格式化时间

//调用dateFormat对时间进行格式化
const dateStr = new Date();
const res1 = nancy.dateFormat(dateStr);
//结果: 2024-06-01 22:37:41
console.log(res1);

转义 HTML 中的特殊字符

//带转换的html字符串
const htmlStr = '<h1 title="abc"> 这是一个h1标签<span>124&nbsp;</span><h1>';
//调用escape方法进行转换
const res2 = nancy.escape(htmlStr);
//结果:&lt;h1 title=&quot;abc&quot;&gt; 这是一个h1标签&lt;span&gt;124&amp;nbsp;&lt;/span&gt;&lt;h1&gt;
console.log(res2);

还原 HTML 中特殊字符

//待还原的html字符串
const res23 = nancy.htmlUnescape(res2);
//结果:<h1 title="abc"> 这是一个h1标签<span>124&nbsp;</span><h1>
console.log(res23);

开源协议

ISC

1.0.0

1 year ago