
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.
The ext-name npm package is used to get the file extension name from a given file path or URL. It is a simple utility that helps in extracting the extension part of a file name.
Get file extension from a file path
This feature allows you to extract the file extension and its corresponding MIME type from a given file path.
const extName = require('ext-name');
const filePath = 'example/file.txt';
const extension = extName(filePath);
console.log(extension); // { ext: 'txt', mime: 'text/plain' }
Get file extension from a URL
This feature allows you to extract the file extension and its corresponding MIME type from a given URL.
const extName = require('ext-name');
const url = 'http://example.com/file.txt';
const extension = extName(url);
console.log(extension); // { ext: 'txt', mime: 'text/plain' }
The mime-types package provides a comprehensive list of MIME types and their associated file extensions. It is more extensive than ext-name and can be used to look up MIME types based on file extensions and vice versa.
The path module is a built-in Node.js module that provides utilities for working with file and directory paths. It includes a method called extname which can be used to extract the file extension from a file path. However, it does not provide MIME type information.
The mime package is used to look up the MIME type of a file based on its extension. It is similar to ext-name but focuses more on MIME type lookups and conversions.
Get the file extension and MIME type from a file
$ npm install --save ext-name
const extName = require('ext-name');
console.log(extName('foobar.tar'));
//=> [{ext: 'tar', mime: 'application/x-tar'}]
console.log(extName.mime('application/x-tar'));
//=> [{ext: 'tar', mime: 'application/x-tar'}]
Returns an Array
with objects with the file extension and MIME type.
Type: string
Get the extension and MIME type from a filename.
Returns an Array
with objects with the file extension and MIME type.
Type: string
Get the extension and MIME type from a MIME type.
MIT © Kevin Mårtensson
FAQs
Get the file extension and MIME type from a file
The npm package ext-name receives a total of 4,035,665 weekly downloads. As such, ext-name popularity was classified as popular.
We found that ext-name demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.