Skip to content

Instantly share code, notes, and snippets.

@andredublin
Created August 8, 2016 20:48
Show Gist options
  • Save andredublin/70e52258cc5ee85ed0870eb284abec10 to your computer and use it in GitHub Desktop.
Save andredublin/70e52258cc5ee85ed0870eb284abec10 to your computer and use it in GitHub Desktop.
checks the extension of a file name
type FileExtension =
|PNG
|JPG
|GIF
|RAW
|BMP
|SVG
|PSD
type IsImageType =
| IsAnImage
| IsNotAnImage
let (|PNG|JPG|GIF|RAW|BMP|SVG|PSD|) (input : string) =
let fileType = input.Split '.' |> Array.last
match fileType.ToLower() with
| "psd" -> PSD
| "svg" -> SVG
| "bmp" -> BMP
| "raw" -> RAW
| "gif" -> GIF
| "jpg" -> JPG
| "png" -> PNG
| _ -> failwith "Unknown file type"
let IsImageUrl str =
match str with
|PNG |JPG |GIF|RAW|BMP|SVG|PSD -> IsAnImage
| _ -> IsNotAnImage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment