tools_lch

1.0.0 • Public • Published

安装方式

###使用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

Readme

Keywords

Package Sidebar

Install

npm i tools_lch

Weekly Downloads

0

Version

1.0.0

License

ISC

Unpacked Size

3.23 kB

Total Files

5

Last publish

Collaborators

  • nodejslch