UNPKG

ith-tool

Version:

提供了格式化时间,HTMLEsacpe的功能

63 lines (56 loc) 1.36 kB
## 安装方式 ``` npm install ith-tool ``` ## 导入方式 ```js const ith = require('./ith-tool') ``` ## 格式化时间 ```js // 传入一个时间对象给dataFormat函数进行格式化 console.log(ith.dataFormat(new Date('2018-6-7 9:9:9'))) // 格式化结果 // ===> // 2018年6月7日 星期四 09:09:09 ``` ## 转义HTML中的特殊字符 ```js // 定义一个html字符串 const str = '<h1>hello "ith" &</h1>' // 转义HTML中的特殊字符 console.log(ith.htmlEscape(str)) // 转换结果 // ===> // &lt;h1&gt;hello &quot;ith&quot; &amp;&lt;/h1&gt; ``` ## 还原HTML中的特殊字符 ```js // 还原HTML中的特殊字符 console.log(ith.htmlUnEscape(ith.htmlEscape(str))) // 还原结果 // ===> // <h1>hello "ith" &</h1> ``` ## 开源协议 ISC ## 描述 今夕是何年 hyl❤hj ## 版本1.1.0新增功能获取当前城市和天气 ```js // 获取promise const getLocationAndWeatherPromise = getLocationAndWeather() // promise getLocationAndWeatherPromise.then((state) => { // 输出得到的结果 console.log(state) // { weather: '多云', city: '武汉' } // 输出城市和天气 console.log('当前城市:', state.city, '今天天气:', state.weather); // 当前城市: 武汉 今天天气: 多云 }).catch((err) => { // 处理错误 console.log(err) }) ```