1.0.0 • Published 2 years ago

gxcnb v1.0.0

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

1.安装方式

1.1使用npm安装

npm i my-tools

2.导入方式

const my = require("my-tools")

3.格式化时间

//格式化时间
function dateFormat(){
	const date = new Date()
	const y = date.getFullYear()
	//月份从0开始
	const m = date.getMonth()+1
	const d = date.getDate()
	const hh = date.getHours()
	const mm = date.getMinutes()
	const ss = date.getSeconds()
	// 2022-8-11 19:56:40
	console.log(y+"-"+m+"-"+d+" "+hh+":"+mm+":"+ss)
}

4.转义HTML中的特殊字符

//转化特殊字符
// < : &lt;
// > : &gt;
// " : &quot;
//输入:<h1>我爱学习</h1>
//结果:&lt;h1&gt;我爱学习&lt;/&gt;
function htmlEscape(str){
	const s = str.replace(/>|<|"/g,(i)=>{
		switch(i){
			case ">":
			  return "&gt;"
			case "<":
			  return "&lt;"
			case '"':
			  return "&quot;"
		}
	})
	
	console.log(s)
}

5.还原HTML中的特殊字符

//还原特殊字符
function htmlunEscape(str){
	const s = str.replace(/&gt;|&lt;|&quot;/g,(i)=>{
		switch(i){
			case "&gt;":
			  return ">"
			case "&lt;":
			  return "<"
			case '&quot;':
			  return '"'
		}
	})
	console.log(s)
}

6.开源协议

ISC