1.0.1 • Published 3 years ago
bao2 v1.0.1
安装
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 </span></h1>'
const str = bao2.htmlEscape(htmlStr)
console.log(str)
// <h1 title="abc">这个是h1标签<span>123&nbsp;</span></h1>
const str2 = bao2.htmlUnEscape(str)
console.log(str2)
//<h1 title="abc">这个是h1标签<span>123 </span></h1>
转义 HTML中的标签为特殊字符,把特殊字符转为HTML字符串
//定义等待转换的HTML字符串
const htmlStr = '<h1 title="abc">这个是h1标签<span>123 </span></h1>'
//转义 HTML中的标签为特殊字符
const str = bao2.htmlEscape(htmlStr)
console.log(str)
//输出 <h1 title="abc">这个是h1标签<span>123&nbsp;</span></h1>
//把特殊字符还原为HTML字符串
const str2 = bao2.htmlUnEscape(str)
console.log(str2)
//输出 <h1 title="abc">这个是h1标签<span>123 </span></h1>
开源协议
ISC