1.0.0 • Published 3 years ago

my-private-node-zj v1.0.0

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

1.安装方式

1.1安装npm安装

npm i my_tools

2.导入方式

const my = require("my_tools")

3.格式化时间

function dateFormat(){
	//自带date时间类
	var date = new Date();
	console.log(date);
	var year = date.getFullYear();
	//console.log(year);
	var mouth = date.getMonth()+1;
	//console.log(mouth);
	var day = date.getDate();
	//console.log(date);
	var hour = date.getHours();
	//console.log(hour);
	var minute = date.getMinutes();
	//console.log(minute);
	var second = date.getSeconds();
	//console.log(second);
	date = year+"年"+mouth+"月"+day+"日  "+hour+":"+minute+":"+second;
	return date;
}

4.转义HTML中的字符

function zhuanHTML(html){
	return html.replace(/<|>|"|&/g,(i)=>{
			switch(i){
				case "<":
					return "&lt";
				case ">":
					return "&gt";
				case '"':
					return "&quot";
				case "&":
					return "&amp";
			}
	})

5.转义HTML中的特殊字符

function huanHTML(html){
	return  html.replace(/&lt|&gt|&quot|&amp/g,(i)=>{
			switch(i){
				case "&lt":
					return "<";
				case "&gt":
					return ">";
				case '&quot':
					return '"';
				case "&amp":
					return "&";
			}
	})
}

6.开源协议