美文网首页
js 版本比较

js 版本比较

作者: Zszen | 来源:发表于2018-10-27 21:59 被阅读3次

    如果当前版本大于等于需求版本则返回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;
    }
    

    https://blog.csdn.net/alwxkxk/article/details/72579747

    相关文章

      网友评论

          本文标题:js 版本比较

          本文链接:https://www.haomeiwen.com/subject/ptrjtqtx.html