Skip to content

Instantly share code, notes, and snippets.

@konobi
Created April 1, 2010 22:34
Show Gist options
  • Save konobi/352459 to your computer and use it in GitHub Desktop.
Save konobi/352459 to your computer and use it in GitHub Desktop.
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