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'))
  • 相关阅读:
    vue中v-slot使用
    Angular服务
    Angular的使用
    Angular介绍
    缓存组件
    mvvm和mvc的区别
    vue项目优化
    windows环境安装和使用curl与ES交互
    Java自定义注解
    ajax异步请求后台数据处理
  • 原文地址:https://www.cnblogs.com/littleboyck/p/15676527.html
Copyright © 2011-2022 走看看