Skip to content

Instantly share code, notes, and snippets.

@tracend
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tracend/31436d82befafab96d15 to your computer and use it in GitHub Desktop.
Save tracend/31436d82befafab96d15 to your computer and use it in GitHub Desktop.
_.getDir() #underscore #mixin #cc
_.mixin({
// - Returns the directory of a url or full path
// Source: https://gist.github.com/tracend/31436d82befafab96d15
getDir: function ( url ) {
// prerequisite
if( typeof url != "string" ) return "";
//
var location = url.match(/^.*[\\\/]/);
// return if there are any matches...
return ( location !== null ) ? location[0] : "";
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment