nimokiko-tools

1.0.0 • Public • Published

安装

npm install nimokiko-tools

导入

const nimokiko = require('nimokiko-tools')

格式化时间

// 调用dateFormat()对时间进行格式化
const dtStr = nimokiko.dateFormat(new Date());

console.log(dtStr);

转义HTML中的特殊字符

//待转换的html字符串
const htmlStr = "<h1 style='color:red'> this is a h1 label <span>123&nbsp;</span></h1>"
//调用htmlEscape()方法进行转换
const str = nimokiko.htmlEscape(htmlStr);
// 转换的结果
console.log(str); 
//转换的结果:&lt;h1 style='color:red'&gt; this is a h1 label &lt;span&gt;123&amp;nbsp;&lt;/span&gt;&lt;/h1&gt;

还原HTML中的特殊字符

// 待转换的字符串
const htmlStr = "&lt;h1 style='color:red'&gt; this is a h1 label &lt;span&gt;123&amp;nbsp;&lt;/span&gt;&lt;/h1&gt;"
// 调用htmlUnescape()方法还原转义字符
const str = nimokiko.htmlUnescape(htmlStr);
// 转换的结果
console.log(str);
// <h1 style='color:red'> this is a h1 label <span>123&nbsp;</span></h1>

开源协议

ISC

Package Sidebar

Install

npm i nimokiko-tools

Weekly Downloads

1

Version

1.0.0

License

ISC

Unpacked Size

3.16 kB

Total Files

6

Last publish

Collaborators

  • nimokiko