
Product
Introducing Tier 1 Reachability: Precision CVE Triage for Enterprise Teams
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
react-native-mimetype
Advanced tools
I find keep making these file extension lookup tables for mime types. It's about time I put it in a module to save me the trouble.
This version differs from rsdoiel's version because we are not looking for the path module at all. This means that we can use this for React Native (which has Node, but doesn't have Path).
var mimetype = require('mimetype');
console.log(mimetype.lookup("myfile.txt")); // Should display text/plain
mimetype.set('.exotic', 'x-application/experimental'); // Add/update a mime type in the catalog
console.log(mimetype.lookup("myfile.exotic")); // Should display x-application/experimental
mimetype.del('.exotic'); // Removes the mime type from the catalog
console.log(mimetype.lookup("myfile.exitoc")); // Should display false
mimetype.forEach(function (ext, mime_type_string) {
console.log(ext, mime_type_string); // Display the extension and matching mimetype in catalog
});
Sometimes detecting by filename extensions isn't work and you want to default to a general purposes mime-type (e.g. text/plain, application/octet-stream).
var mimetype = require('mimetype');
// This should display 0 (false)
console.log(mimetype.lookup("filename.unknownMimeType");
// This should display the string text/plain
console.log(mimetype.lookup("filename.unknownMimeType", false, "text/plain");
// This should display the string text/plain; charset=UTF-8
console.log(mimetype.lookup("filename.unknownMimeType", "UTF-8", "text/plain");
While this was implemented as a NodeJS module it also works under MongoDB's shell. Instead of including with a "require" you would load the JavaScript file load-mimetype.js.
load("./extras/load-mimetype.js");
print("Check the mime type of test.txt:" + MimeType.lookup("test.txt"));
This would display something like-
MongoDB shell version: 2.2.0
connecting to: test
> load("./extras/load-mimetype.js");
> print("Check the mime type of test.txt: " + MimeType.lookup("test.txt"));
Check the mime type of test.txt: text/plain
>
FAQs
A mime type catalog driven by filename extensions.
We found that react-native-mimetype demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
Research
/Security News
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.
Security News
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.