1.0.1 • Published 1 year ago

ceshi_tools v1.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

安装

npm i my_tools

导入

const my_tools = require('my_tools')

格式化时间

//调用dataFormat对时间进行格式化
const dt = my_tools.dataFormat(new Date())

console.log(dt)

//结果 2022-11-06 21:17:11

转义HTML中的特殊字符

//待转换的 HTML 字符串
const html = '<h1 title="abc">我是h1 &nmsp</h1>'

//调用 htmlEscape 方法进行转换
const newStr = htmlStr.htmlEscape(html)

//结果 &lth1 title=&quotabc&quot&gt我是h1 &ampnmsp&lt/h1&gt

还原HTML中的特殊字符

//待还原的 HTML 字符串
const html2 = '&lth1 title=&quotabc&quot&gt我是h1 &ampnmsp&lt/h1&gt'

//调用 htmlEscape 方法进行转换
const newS = htmlStr.htmlUnEscape(html2)

//结果 <h1 title="abc">我是h1 &nmsp</h1>
console.log(newS);

开源协议

ISC