Created
March 28, 2021 18:29
-
-
Save stoyan-scava/154fbcdbbda656931b3fbd18d7082c3e to your computer and use it in GitHub Desktop.
Detector for file extensions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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