Skip to content

Instantly share code, notes, and snippets.

@TheJarX
Created March 25, 2021 20:19
Show Gist options
  • Save TheJarX/02a9a565e9cb633b75ee1a5ca7e1445f to your computer and use it in GitHub Desktop.
Save TheJarX/02a9a565e9cb633b75ee1a5ca7e1445f to your computer and use it in GitHub Desktop.
Simple but can help
// 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