1.0.1 • Published 3 years ago

bao2 v1.0.1

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

安装

npm install bao2

导入

const bao2 = require('bao2')
或
const bao2 = require('../bao2/index')

格式化时间

const drstr = bao2.dataFormat(new Date())
console.log(drstr)
//输出:2022-03-02 16:26:11

const htmlStr = '<h1 title="abc">这个是h1标签<span>123&nbsp;</span></h1>'
const str = bao2.htmlEscape(htmlStr)
console.log(str)
// &lt;h1 title=&quot;abc&quot;&gt;这个是h1标签&lt;span&gt;123&amp;nbsp;&lt;/span&gt;&lt;/h1&gt;
const str2 = bao2.htmlUnEscape(str)
console.log(str2)
//<h1 title="abc">这个是h1标签<span>123&nbsp;</span></h1>

转义 HTML中的标签为特殊字符,把特殊字符转为HTML字符串

//定义等待转换的HTML字符串
const htmlStr = '<h1 title="abc">这个是h1标签<span>123&nbsp;</span></h1>'
//转义 HTML中的标签为特殊字符
const str = bao2.htmlEscape(htmlStr)
console.log(str)
//输出 &lt;h1 title=&quot;abc&quot;&gt;这个是h1标签&lt;span&gt;123&amp;nbsp;&lt;/span&gt;&lt;/h1&gt;

//把特殊字符还原为HTML字符串
const str2 = bao2.htmlUnEscape(str)
console.log(str2)
//输出 <h1 title="abc">这个是h1标签<span>123&nbsp;</span></h1>

开源协议

ISC

1.0.1

3 years ago

1.0.0

4 years ago