@dgnight/dg-tools

1.0.0 • Public • Published

安装

npm i dg-tools

导入

const dg = require('./index');

格式化时间

const dt = dg.dateFormat(new Date());
// 输出 2023-02-22 22:13:10
console.log(dt);

转义HTML中的特殊字符

const htmlstr = '<h1 style="color: red">Hello&nbsp;<span>World</span></h1>';
const str = dg.htmlEscape(htmlstr);
// 输出 &lt;h1 style=&quot;color: red&quot;
// &gt;Hello&ampnbsp;&lt;span&gt;World&lt;/span&gt;&lt;/h1&gt;
console.log(str);

还原HTML中的转义字符

const rawHtml = dg.htmlUnEscape(str);
// 输出 <h1 style="color: red">Hello&nbsp;<span>World</span></h1>
console.log(rawHtml);

开源协议

ISC

Readme

Keywords

Package Sidebar

Install

npm i @dgnight/dg-tools

Weekly Downloads

0

Version

1.0.0

License

ISC

Unpacked Size

3.07 kB

Total Files

6

Last publish

Collaborators

  • dgnight