Skip to content

Instantly share code, notes, and snippets.

@stoyan-scava
Created March 28, 2021 18:29
Show Gist options
  • Save stoyan-scava/154fbcdbbda656931b3fbd18d7082c3e to your computer and use it in GitHub Desktop.
Save stoyan-scava/154fbcdbbda656931b3fbd18d7082c3e to your computer and use it in GitHub Desktop.
Detector for file extensions
/**
* Detect file extension from filename
* @param filename
* @param extension including the dot
*/
export class ExtensionDetector {
constructor() {
}
/**
* E.g foo.bar ==> .bar
* @return file extension with .
* @param filename
*/
getExtension(filename: string): string {
const re = /(?:\.([^.]+))?$/
return re.exec(filename)![1];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment