Programming Tips - How about a dirname() and basename() for javaScript?

Date: 2011feb4 Language: javaScript Q. How about a dirname() and basename() for javaScript? A. The approach is the same in both - remove the characters we don't want.
function basename(path) { if (path == null) return null; return path.replace(/.*\//, ''); } function dirname(path) { if (path == null) return null; return path.replace(/\/[^\/]*$/,''); }