1.0.0 • Published 3 years ago

itzhu-tools v1.0.0

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

安装

npm install itzhu-tools

导入

const itzhu = require('itzhu-tools');

格式化时间

// 调用itzhu.dateFormat对时间进行格式化
const time = itzhu.dateFormat(new Date());
//结果
console.log(time);

转义 html 中的特殊字符

const htmlStr = '<h1 title="你好啊">这是h1标签<span>123&nbsp;</span></h1>';
//调用itzhu.htmlEscape进行转义;
const str = itzhu.htmlEscape(htmlStr);
//转义的结果:&lth1 title=&quot你好啊&quot&gt这是h1标签&ltspan&gt123&ampnbsp;&lt/span&gt&lt/h1&gt
console.log(str);

还原 html 中的特殊字符

const htmlStr =
  '&lth1 title=&quot你好啊&quot&gt这是h1标签&ltspan&gt123&ampnbsp;&lt/span&gt&lt/h1&gt';

//调用itzhu.htmlUnEscape进行还原;
const str = itzhu.htmlUnEscape(htmlStr);
//还原的结果:<h1 title="你好啊">这是h1标签<span>123&nbsp;</span></h1>
console.log(str);

开源协议

ISC