1.0.0 • Published 2 years ago

tools_lch v1.0.0

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

安装方式

###使用npm进行安装

npm install tools_lch

导入方式

const tools = require("tools_lch")

格式化时间

//1.实现时间格式化功能
function dateFormat(){
	const dt = new Date();
	const y = dt.getFullYear()
	const m = dt.getMonth()+1
	const d = dt.getDate()
	const hh = dt.getHours()
	const mm = dt.getMinutes()
	const ss = dt.getSeconds()
	return `${y}年${m}月${d}日${hh}:${mm}:${ss}`
}

转义HTML中的特殊字符

function htmlEscape(h){
	let result = h.replace(/<|>|"|&/g,function (d) {
		switch(d){
			case "<":
			   return "&lt;"
			case ">":
			   return "&gt;"
			case '"':
			   return "&quot;"
			case "&":
			   return "&amp;"
		}
	})
	return result
}

还原HTML中的特殊字符

function htmlEscape2(h){
	let result = h.replace(/&lt|&gt|&quot|&amp/g,function (h) {
		switch(d){
			case "&lt":
			   return "<"
			case "&gt":
			   return ">"
			case "&quot":
			   return '"'
			case "&amp":
			   return "&"
		}
	})
	return result
}

开源协议

ISC