Get MIME type based on file name, path, and extension.
This repository doesn't require frequent updates, so even if it hasn't been updated for a long time, as long as it still exists, it means it's available. We'll keep an eye on whether it can function properly in the latest Node and browser environments.
In the Node.js environment, you can install directly using NPM:
$ npm i @litert/mime --save
If you're using it in a browser, you can utilize the CDN mode.
<script src="https://cdn.jsdelivr.net/npm/@litert/[email protected]/dist/loader.min.js?path=index&npm={'@litert/mime':'0.1.3'}"></script>
Demo code is written using TypeScript.
import * as mime from "@litert/mime";
mime.getData("hello.json"); // {"mime": "application/json", "compressible": true, extension: 'json'}
mime.getData(".html"); // {"mime": "text/html", "compressible": true, extension: 'html'}
mime.getData("css"); // {"mime": "text/css", "compressible": true, extension: 'css'}
mime.getData("hi/baby.js"); // {"mime": "application/javascript", "compressible": true, extension: 'js'}
mime.getData("/root/down/pk.zip"); // {"mime": "application/zip", "compressible": false, extension: 'zip'}
mime.getData("ext.dodooh"); // {"mime": "application/octet-stream", "compressible": false, extension: 'dodooh'}
mime.getMime("root/index.css"); // text/css
Once it's compiled correctly, you can run the sample code in the terminal by using node ./dist/test-node
.
To view the examples, simply access the test/
directory in your browser.
Click here to view the examples online
This library is published under Apache-2.0 license.