-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add known_types/0 function that lists all known types #79
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Can we add a test for this? It's enough to test that the returned term is a list of strings, has some known types in it, and has some user-defined known types in it.
lib/mime.ex
Outdated
Returns a list of all known types, including custom types compiled into the MIME module. | ||
""" | ||
def known_types do | ||
Map.keys(unquote(Macro.escape(all_types))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be better to compile them with their extensions, so all information becomes available?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made it return just the types because that's what I would expect a known_types
function to do but it's also better to have more information. I changed it to return the mapping of types to extensions. :)
Added a test and changed the return type to include extensions: iex(1)> MIME.known_types
%{
"image/bmp" => ["bmp"],
"application/json-patch+json" => ["json-patch"],
"application/vnd.oasis.opendocument.spreadsheet" => ["ods"],
"application/zip" => ["zip"],
"application/vnd.openxmlformats-officedocument.wordprocessingml.document" => ["docx"],
"application/xhtml+xml" => ["xhtml"],
"application/x-bzip2" => ["bz2"],
"application/manifest+json" => ["webmanifest"],
"application/vnd.ms-powerpoint" => ["ppt"],
"application/json" => ["json"],
"video/mpeg" => ["mpeg", "mpg"],
"application/x-7z-compressed" => ["7z"],
"video/mp4" => ["mp4"],
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" => ["xlsx"],
"text/css" => ["css"],
"application/vnd.etsi.asic-e+zip" => ["asice", "sce"],
"text/xml" => ["xml"],
"text/plain" => ["txt", "text"],
"audio/aac" => ["aac"],
...
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome!
💚 💙 💜 💛 ❤️ |
Adds a
known_types/0
function that returns a list of all known types. Fixes #75.