zoukankan      html  css  js  c++  java
  • path.resolve源码实现(简单版)

    //解析文件路径。类似于path.resolve
      resolve(...paths){
            let resolvePath = '';
            let isAbsolutePath = false;
            for(let i = paths.length-1; i > -1; i--){
                let path = paths[i];
                if(isAbsolutePath){
                    break;
                }
                if(!path){
                    continue
                }
                resolvePath = path + '/' + resolvePath;
                isAbsolutePath = path.charCodeAt(0) === 47;
            }
            if(/^\/+$/.test(resolvePath)){
                resolvePath = resolvePath.replace(/(\/+)/,'/')
            }else{
                resolvePath = resolvePath.replace(/(?!^)\w+\/+\.{2}\//g, '')
                .replace(/(?!^)\.\//g,'')
                .replace(/\/+$/, '')
            }
            return resolvePath;
        }
    console.log(resolve('/aa','../bb','cc','dd'))
    console.log(resolve('/aa','../bb','./cc','dd'))
    console.log(resolve('/','/system','user','userIndex'))
  • 相关阅读:
    Shooting Algorithm
    Subgradient Algorithm
    Factorization Machine
    支持向量机
    Hashing Trick
    Science上发表的超赞聚类算法
    Contractive Auto-Encoder
    Shell之数学计算
    牛顿方法(Newton-Raphson Method)
    泊松回归(Poisson Regression)
  • 原文地址:https://www.cnblogs.com/littleboyck/p/15676527.html
Copyright © 2011-2022 走看看