1.0.0 • Published 3 years ago

smile-tools v1.0.0

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

安装

npm install smile-tools

引入

const itheima = require('./smile-tools') 

格式化时间

调用dateFormat对时间进行格式化转换
const itheima = time.dateFormat(new Date())
//结果为:2020-11-09  20:31:19
console.log(itheima);

转换HTML字符串

// 待转换的HTML字符串
const htmlStr = '<h1 tittle="box">这是转换的html字符串<span>哈哈</span></h1>'
//调用htmlEscape方法进行转换
const str = itheima.htmlEscape(htmlStr)
// 转换结果为:&lth1 tittle&quot"box"&gt这是转换的html字符串&ltspan&gt哈哈&lt/span&gt&lt/h1&gt
console.log(str);

还原HTML中的特殊字符

// 待还原的HTML字符串
const str1 = itheima.unHtmlEscape(str)


// 转换结果为:<h1 tittle="box">这是转换的html字符串<span>哈哈</span></h1>
console.log(str1);

##开源协议 ISC