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 --saveIf you're using it in a modern browser, you can import the package as a native ES module from a CDN.
<script type="module">
import * as mime from "https://cdn.jsdelivr.net/npm/@litert/mime@2.0.0/dist/index.js";
console.log(mime.getMime("index.css"));
</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": "text/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/cssOnce 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.