//判断字符串是否为json字符串String.prototype.isJsonString=function(){let str =thistry{if(typeof(JSON.parse(str))==='object'){returntrue}}catch(e){returnfalse}returnfalse}//将值写入cookeString.prototype.setCooke=function(key, time){if(isNullOrEmpty(time)){
time =1000*60*60*24*7//默认存储7天}let val =thisvar date =newDate()//获取当前时间var expiresDays = time //将date设置为n天以后的时间
date.setTime(date.getTime()+ expiresDays)//格式化为cookie识别的时间
document.cookie = key +'='+ val +';expires='+ date.toGMTString()//设置cookie}//将时间格式转换为浏览器兼容的2020/01/01 01:01:00格式的字符串String.prototype.toDateStr=function(){let value =thisreturn value.replace(/-/g,'/')}//隐藏指定位数的字符为*号String.prototype.hide=function(start, end){const val =thislet result =''if(val.length >= start){
result += val.substring(0, start -1)if(val.length<end){
end=val.length
}for(let i = start; i <= end; i++){
result +='*'}if(val.length > end){
result += val.substring(end, val.length)}}else{
result=val
}return result
}//两端去空格函数String.prototype.trim=function(){returnthis.replace(/(^\s*)|(\s*$)/g,'')}