ilib
Version:
iLib is a cross-engine library of internationalization (i18n) classes written in pure JS
1 lines • 1.11 kB
JavaScript
var Path={dirname:function(pathname){return pathname?"."===(pathname=Path.normalize(pathname))?"..":Path.normalize(pathname+"/.."):pathname},normalize:function(pathname){return pathname&&(1<(pathname=(pathname=(pathname=(pathname=(pathname=(pathname=(pathname=(pathname=(pathname=(pathname=pathname.replace(/\\/g,"/")).replace(/\/\//g,"/")).replace(/\/\//g,"/")).replace(/\/[^/]*[^\./]\/\.\./g,"/.")).replace(/^[^/]*[^\./]\/\.\./g,".")).replace(/\/\.\//g,"/")).replace(/^\.\//,"")).replace(/\/\//g,"/")).replace(/\/\.$/,"")).replace(/\/\//g,"/")).length&&(pathname=pathname.replace(/\/$/,"")),0===pathname.length&&(pathname=".")),pathname},join:function(var_args){for(var arr=[],i=0;i<arguments.length;i++)arr.push(arguments[i]&&0<arguments[i].length?arguments[i]:".");return Path.normalize(arr.join("/"))},basename:function(pathname,extension){var base=pathname,slash=pathname.lastIndexOf("/");if(-1!==slash&&(base=pathname.substring(slash+1)),extension){var ext="."===extension[0]?extension:"."+extension,index=base.lastIndexOf(ext);-1<index&&(base=base.substring(0,index))}return base}};module.exports=Path;