itheima-tools-wtf

1.0.0 • Public • Published

安装

npm install itheima-tools-wtf

导入

const itheima = require('itheima-tools-wtf')

格式化时间

// 调用 dataFormat 对时间进行格式化
const dtStr = itheima.dataFormat(new Date())
console.log(dtStr)  //2024-02-04 14:38:03

转义HTML的中的特殊字符

// 定义待转换的 HTML 的字符串
const htmlStr = '<h1 title="abc">这是h1标签<span>123&nbsp;</span></h1>'
// 调用 htmlEscape 方法对字符串进行转换
const newStr = itheima.htmlEscape(htmlStr) 
console.log(newStr)  //&lt;h1 title=&quot;abc&quot;&gt;这是h1标签&lt;span&gt;123&amp;nbsp;&lt;/span&gt;&lt;/h1&gt;

还原HTML的中的特殊字符

// 调用 htmlEscape 方法对字符串进行还原
const oldStr = itheima.htmlUnEscape(newStr)
console.log(oldStr)   //<h1 title="abc">这是h1标签<span>123&nbsp;</span></h1>

Package Sidebar

Install

npm i itheima-tools-wtf

Weekly Downloads

1

Version

1.0.0

License

ISC

Unpacked Size

2.55 kB

Total Files

5

Last publish

Collaborators

  • wtf132333