如果当前版本大于等于需求版本则返回true,如果当前版本小于需求版本则返回false
public requireVersion(nowVersion:string,requestVersion:string){
let reg=/(\d+)\.(\d+)\.(\d+)/;
let nowArr=[];
let requestArr=[];
//参数检查
try{
if(nowVersion.match(reg).length !== 4 || requestVersion.match(reg).length !== 4){
console.log("Error compareVersion","param");
return ;
}
}
catch(e){
console.log("Error compareVersion","param");
return ;
}
nowArr = nowVersion.match(reg).slice(1,4);
requestArr = requestVersion.match(reg).slice(1,4);
//console.log(nowArr,requestArr);
for(let i = 0;i < 3;i++){
//console.log(i);
if(nowArr[i] < requestArr[i]){
//console.log("requestVersion is bigger.");
return false;
}else if(nowArr[i] > requestArr[i]){
return true;
}
}
return true;
}
网友评论