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