从Ruby源代码翻译过来的
function split_path(path){
return path.split(/\/+/);
}
function merge_path(base,rel){
// RFC2396, Section 5.2, 5)
if (rel[0] == '#'){
// RFC2396, Section 5.2, 5)
return rel;
}
// RFC2396, Section 5.2, 6)
var base_path = split_path(base);
var rel_path = split_path(rel);
// RFC2396, Section 5.2, 6), a)
if(base_path[base_path.length-1] == '..'){
base_path.push('');
}
var i;
while ((i = base_path.indexOf('..'))+1){
base_path = base_path.slice(i - 1, 2);
}
if (base_path.length == 0){
base_path = ['']; // keep '/' for root directory
}else{
base_path.pop();
}
// RFC2396, Section 5.2, 6), c)
// RFC2396, Section 5.2, 6), d)
if (rel_path[rel_path.length-1] == '.' || rel_path[rel_path.length-1] == '..'){
rel_path.push('');
}
var old_rel_path = rel_path;
rel_path = [];
for(var i=0,l=old_rel_path.length;i<l;i++){
if(old_rel_path[i]!='.'){
rel_path.push(old_rel_path[i]);
}
}
// RFC2396, Section 5.2, 6), e)
var tmp = []
for(var i=0,l=rel_path.length;i<l;i++){
var x = rel_path[i];
if ( x == '..' && !(tmp.length == 0 || tmp[tmp.length-1]=='..')){
tmp.pop();
}else{
tmp.push(x);
}
}
var add_trailer_slash = true;
var x;
while (x = tmp.shift()){
if (x == '..' && base_path.length > 1){
// RFC2396, Section 4
// a .. or . in an absolute path has no special meaning
base_path.pop();
}else{
base_path.push(x);
for(var i=0,l=tmp.length;i<l;i++){
var t=tmp[i];
base_path.push(t);
}
add_trailer_slash = false;
break;
}
}
if (add_trailer_slash){
base_path.push('') ;
}
return base_path.join('/')
}
//merge_path("/abc/def/gy","./dde")
分享到:
相关推荐
merge-driver(1)-用于自动合并锁文件的git merge驱动程序自动设置(推荐): 要立即开始使用它: $ npx npm-merge-driver install --global或按项目在本地安装: $ cd /path/to/git/repository$ npx npm-merge-...
// path to all files to load/merge together ] } files数组中列出的每个文件都必须是JSON文件。 每个文件的路径必须是从应用程序模块的根开始的相对路径(例如src / filesToMerge / file1.json)。 安装 npm ...
Practical instruction on using JavaScript Object Notation (JSON) with MySQL This hands-on guide teaches, step by step, how to use JavaScript Object Notation (JSON) with MySQL. Written by a MySQL ...
language-javascript-jsx linter linter-eslint linter-flow mac-fix-path merge-conflicts minimap minimap-autohide minimap-bookmarks minimap-find-and-replace minimap-git-diff minimap-hide minimap-...
文档合并 用于将 Polymer 元素文档合并在一起的工具。 示例用法 查看demo.js文件 ...var generate = require('doc-merge'); generate(FIXTURES, OUTPUT, {config: 'test/fixtures/config.json' });
fis-postprocessor-jswrapper Fis的后处理器插件,用于使用闭包或amd定义包装JavaScript。设定$ vi path/to/project/fis-conf.jsfis . config . merge ( { settings : { postprocessor : { jswrapper : { //wrap ...
"output_path": "D:\\projects\\github_project\\merge_js_css\\examples\\output", //输出合并后js、css的目录 "tmp_js_json_dir": "D:\\projects\\github_project\\merge_js_css\\examples\\json\\js", //js合并...
var merge = require ( 'merge-stream' ) ; var source = require ( 'vinyl-source-stream' ) ; var factor = require ( '../lib/factor' ) ; var fixtures = path . resolve . bind ( path , __di
目前支持 Java, C++, C#, Python, Ruby, JavaScript, Swift, Scala, Clojure, 将来还会支持更多编程语言。 在线阅读 https://www.gitbook.com/book/soulmachine/algorithm-essentials/ 内容目录 介绍 线性表 ...
yyl-base-webpack-config安装yarn add yyl - base - ... merge ( { context : __dirname , env , alias : { '~' : path . join ( __dirname , './src' ) , '~@' : path . join ( __dirname , './src/components/' )
fis-helper 一切便于开发的新特性,都将以 helper 的形式提供,这些 helper 不一定是完全符合 ...roadmap.path 将以用户的优先,而不是执行纯粹的 merge modules 插件不再是覆盖,而是 Append fis.config.append 给插
fis解析器指南针 用于 fis 编译 sass 文件的解析... merge ( { roadmap : { ext : { //compile *.scss or *.sass into *.css scss : 'css' , sass : 'css' } } , modules : { parser : { scss : 'compass' ,
时代广场 :cityscape: 使用整个色彩范围 语义突出显示 在所有前景色和背景之间: 使用算法的相同感知对比度 AA 7.0旨在提高可读性和可访问性 ...cp ./build/Times \ Square.sublime-color-scheme path/to/your/s
在urbit上: |merge %home ~middev %kids 从来源: 安装节点和npm 在dojo中使用|mount %来安装urbit-您应该在/path/to/pier/home下的unix中看到您的文件 更改config/urbitrc-sample' to point your mounted ...
应用程序接口 这是。 patch(target, source, patches) 将中的补丁应用到目标文档。 参数 target (对象或数组) :接收补丁的文档。... [ merge ] (布尔值) :将源值与目标值合并。 [ unique ] (布
因为很重要,所以写在最前面如果希望在pure的基础上添加自己的目录规范,即修改 roadmap.path 时,不可以 使用fis.config.merge或者fis.config.set,而必须按照下面的方式进行配置fis.config.get('roadmap.path')....
Javascript小技巧一箩筐 事件源对象 event.srcElement.tagName event.srcElement.type 捕获释放 event.srcElement.setCapture(); event.srcElement.releaseCapture(); 事件按键 event.keyCode ...
// get the configuration that provides the lazo 'empty:' paths and sets the loader (l, text, & json) paths// perfroms a deep merge of the application conf.json (requirejs property) with the lazo ...
安装 npm install -g spr用法 $spr -hOptions: -b, --base Specify the base branch to merge the pull request into -h, --help This help -v, --verbose Be verbose -t, --template Path to template to be used ...
冒纳GraphQL GraphQL模式和mauna的常见查询。 参考文档可以在找到。... 运行bundle install --path vendor/bundle 运行npm run docs 提交所有更改, 然后git checkout gh-pages和git merge git push origin gh-pa