What is ext-name?
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.
What are ext-name's main functionalities?
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' }
Other packages similar to ext-name
mime-types
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.
path
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.
mime
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.
ext-name
Get the file extension and MIME type from a file
Install
$ npm install --save ext-name
Usage
const extName = require('ext-name');
console.log(extName('foobar.tar'));
console.log(extName.mime('application/x-tar'));
API
extName(filename)
Returns an Array
with objects with the file extension and MIME type.
filename
Type: string
Get the extension and MIME type from a filename.
extName.mime(mimetype)
Returns an Array
with objects with the file extension and MIME type.
mimetype
Type: string
Get the extension and MIME type from a MIME type.
Related
License
MIT © Kevin Mårtensson