js-cfb/bits/35_path.js

12 lines
410 B
JavaScript
Raw Normal View History

2017-09-14 21:14:22 +00:00
function dirname(p/*:string*/)/*:string*/ {
if(p.charAt(p.length - 1) == "/") return (p.slice(0,-1).indexOf("/") === -1) ? p : dirname(p.slice(0, -1));
var c = p.lastIndexOf("/");
return (c === -1) ? p : p.slice(0, c+1);
}
function filename(p/*:string*/)/*:string*/ {
if(p.charAt(p.length - 1) == "/") return filename(p.slice(0, -1));
var c = p.lastIndexOf("/");
return (c === -1) ? p : p.slice(c+1);
}