Created
April 1, 2010 22:34
-
-
Save konobi/352459 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.normalizeArray = function(arr) { | |
var [final_array, items, item] = [ [], arr.slice(0), null ]; | |
while(items.length){ | |
item = items.shift(); | |
if( (item == undefined) || (item == '') || (item == '.') ){ | |
// do nothing | |
} else if(item == '..'){ | |
final_array.pop(); | |
} else { | |
final_array.push(item); | |
} | |
} | |
return final_array; | |
}; | |
exports.normalize = function(p) { | |
var final_array = exports.normalizeArray(p.split('/')); | |
var start = (p.charAt(0) == '/') ? '/' : ''; | |
return start + final_array.join('/'); | |
}; | |
exports.join = function() { | |
var items = Array.prototype.slice.call(arguments); | |
return exports.normalize(items.join('/')); | |
}; | |
exports.extname = function(p) { | |
var ext = p.match(/\.([^\.]+)$/); | |
return ext[1]; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment