Created
March 29, 2017 20:26
-
-
Save alkavan/44a83ca5fdad84186e037bcd8c32fb7a to your computer and use it in GitHub Desktop.
MIME Type extraction and validation by RFC 2045, RFC 833
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
// Pattern (RFC 833, RFC 2045, https://www.ietf.org/rfc/rfc2045.txt) | |
// Tested against 1200~ types @ http://www.iana.org/assignments/media-types/media-types.xhtml | |
const pattern = /^(text|image|audio|video|application+)\/([a-zA-Z\d\+\-\.\:\_]+)$/; | |
// Tests | |
pattern.test("application/x-bzip2"); | |
pattern.test("application/vnd.amazon34.ebook"); | |
pattern.test("application/octet-stream"); | |
// Match | |
"application/x-bzip2".match(pattern); | |
// Output | |
{ | |
0:"application/x-bzip2" | |
1:"application" | |
2:"x-bzip2" | |
index:0 | |
input:"application/x-bzip2" | |
length:3 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment