Created
March 25, 2021 20:19
-
-
Save TheJarX/02a9a565e9cb633b75ee1a5ca7e1445f to your computer and use it in GitHub Desktop.
Simple but can help
This file contains 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
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types | |
// you can return an array instead of an object | |
function getDataFromMIME(mime) { | |
const [type, subtype, parameter] = mime.split(/[\/\;]/); | |
const [paramName, paramValue] = parameter.split('='); | |
return { | |
type, | |
subtype, | |
[paramName]: paramValue, | |
parameter: [paramName, paramValue] | |
}; | |
} | |
const { type, subtype } = getDataFromMIME('video/mp4;ts=192378933'); | |
console.log(`This file is a/an ${type} with the subtype ${subtype}`) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment