1.0.0 • Published 1 year ago

ff-tools v1.0.0

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

安装

npm install ff-tools

导入

// 调用
const ff = require('ff-tools'); 

格式化时间

// 调用 dateFormat 对时间进行格式化
const dtStr = ff.dateFormat(new Date());
// 结果 2023-01-15 18-05-59
console.log(dtStr);

转义 html 中的特殊字符

// 会替换掉 html 中全部的 < | > | " | & 
const htmlStr = '<h1 title="abc"> 这是h1标签,<span>123&nbsp;456</span> </h1>';
// 调用 htmlEscape方法 进行转换
const newHtml = ff.htmlEscape(htmlStr);

console.log(newHtml);
// 结果: &lth1 title=&quotabc&quot&gt 这是h1标签,&ltspan&gt123&ampnbsp;456&lt/span&gt &lt/h1&gt

还原HTML中的特殊字符

// 调用 还原 HTML字符串中的  &lt &gt  &quot  &amp
const unHtml = ff.htmlUnEscape(newHtml)

console.log(unHtml);
// 结果: <h1 title="abc"> 这是h1标签,<span>123&nbsp;456</span> </h1>

开源协议

ISC