Helper for mime type detection by filename or mime type. Has build in types to support typescript. Works in node and in the web.
MimeTypes are included from the official IANA: IANA
Tested with node >=12.0 and all actual browsers.
yarn add mimecraft
npm install mimecraft
const MimeType: IMimeTypesUtils = new MimeTypesUtils();
MimeType.getMimeTypeForFileExtension("pdf");
@injectMimeType
class Test {
public mimetype!: IMimeTypesUtils;
}
const test = new Test();
test.mimetype.getMimeTypeForFileExtension("pdf");
MimeType.getMimeTypeForFileExtension("pdf");
Output:
{ extension: 'pdf', type: 'application/pdf' }
MimeType.getFileExtensionForMimeType("application/pdf");
Output:
{ extension: 'pdf', type: 'application/pdf' }
Ask for mime type or extension that is not included in this lib you will receive:
{ extension: '', type: '' }
const MimeType = new MimeTypesUtils();
MimeType.getMimeTypeForFileExtension("pdf");
@injectMimeType
class Test {
public mimetype;
}
const test = new Test();
test.mimetype.getMimeTypeForFileExtension("pdf");
MimeType.getMimeTypeForFileExtension("pdf");
Output:
{ extension: 'pdf', type: 'application/pdf' }
MimeType.getFileExtensionForMimeType("application/pdf");
Output:
{ extension: 'pdf', type: 'application/pdf' }
Ask for mime type or extension that is not included in this lib you will receive:
{ extension: '', type: '' }
After your first checkout or clone please run "yarn install" to install all required dependencies containing in package.json file.
You will find the following folder structure:
- ./lib (build target folder)
- ./src (source code base on typescript)
We have the following preconfigured commands that can easily run with yarn [command]:
- yarn clean (clean the lib folder)
- yarn build (start build job)
You can always ask with "pdf" or ".pdf" for example.
Happy using =)