https://github.com/khalyomede/mime
Mime type enum and function in V.
https://github.com/khalyomede/mime
content-type enum function mime vlang
Last synced: 4 months ago
JSON representation
Mime type enum and function in V.
- Host: GitHub
- URL: https://github.com/khalyomede/mime
- Owner: khalyomede
- License: mit
- Created: 2021-05-22T18:07:14.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-05-25T19:47:35.000Z (about 5 years ago)
- Last Synced: 2025-07-15T00:18:27.482Z (11 months ago)
- Topics: content-type, enum, function, mime, vlang
- Language: V
- Homepage:
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# MIME
List of mime and their file extensions.
```v
module main
import khalyomede.mime { Mime }
fn main() {
text_html := Mime.text_html
println(text_html) // "text/html"
}
```
## Summary
- [About](#about)
- [Features](#features)
- [Installation](#installation)
- [Examples](#examples)
## About
I create this package to have a type safe list of allowed mime, to be used to return "Content-Type" header for my router.
This library can be used for other use cases as well.
[back to summary](#summary)
## Features
- List of common MIME types
- Ability to get allowed file extensions from a MIME type
- Ability to get the MIME text representation
- Ability to get a MIME Type from a file extension
- Ability to get a MIME Type from a MIME text representation
[back to summary](#summary)
## Installation
- [Using V installer](#using-v-installer)
### Using V installer
On your terminal, run this command:
```bash
v install khalyomede.mime
```
[back to summary](#summary)
## Examples
- [Get the text representation](#get-the-text-representation)
- [Get the list of allowed file extensions](#get-the-list-of-allowed-file-extensions)
- [Create from a MIME text representation](#create-from-a-mime-text-representation)
- [Create from a file extension](#create-from-a-file-extension)
### Get the text representation
Use `.str()` or pass it on a parameter accepting a `string` which will convert the MIME type to its text representation.
```v
module main
import khalyomede.mime { Mime }
fn main() {
text_html := Mime.text_html
assert text_html.str() == "text/html"
}
```
### Get the list of allowed file extensions
```v
module main
import khalyomede.mime { Mime }
fn main() {
text_html := Mime.text_html
assert text_html.extensions() == ["html"]
}
```
### Create from a MIME text representation
```v
module main
import khalyomede.mime { Mime }
fn main() {
text_html := Mime.from_text("text/html") or { Mime.text_html }
}
```
### Create from a file extension
```v
module main
import khalyomede.mime { Mime }
fn main() {
text_html := Mime.from_file_extension("html") or { Mime.text_html }
}
```