tools-ysh

1.1.0 • Public • Published

安装

npm install tools-ysh

导入

const text = require("./tools-ysh");

格式化时间

// 调用时间方法
const timeStr = text.dateFormat(new Date());
// 结果 2021-05-18 10:36:41
console.log(timeStr);

转义 HTML 中的特殊字符

// 标签变量
const str = '<h1 title="abc">这是h1标签<span>123&nbsp;</span></h1>';

// 调用转义 HTML 的方法
const htmlStr = text.htmlEscape(str);

// 结果 &lt;h1 title=&quot;abc&quot;&gt;这是h1标签&lt;span&gt;123&amp;nbsp;&lt;/span&gt;&lt;/h1&gt;
console.log(htmlStr);

还原 HTML 中的特殊字符

// 调用还原 HTML 的方法
const htmlStr2 = text.htmlUnEscape(htmlStr);
// 结果 <h1 title="abc">这是h1标签<span>123&nbsp;</span></h1>
console.log(htmlStr2);

开源协议

ISC

Readme

Keywords

Package Sidebar

Install

npm i tools-ysh

Weekly Downloads

2

Version

1.1.0

License

ISC

Unpacked Size

4.7 kB

Total Files

5

Last publish

Collaborators

  • yangdexxx