Skip to content

Instantly share code, notes, and snippets.

@ajschlosser
Created December 25, 2014 00:09
Show Gist options
  • Save ajschlosser/e6df9433409824abe82b to your computer and use it in GitHub Desktop.
Save ajschlosser/e6df9433409824abe82b to your computer and use it in GitHub Desktop.
/**
* Checks to see if a given string ends with a particular file extension
* @param {string} f String representing a possible file name with extension
* @param {string} e The sought extension
* @returns {boolean}
*/
function hasExtension (f, e) {
if (e[0] !== '.') {
e = '.' + e;
}
if (f.substring(f.length-e.length,f.length) !== e) {
return false;
} else {
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment