Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

file-extension

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

file-extension

Get the extension of a given filename or path

  • 4.0.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
93K
increased by0.45%
Maintainers
1
Weekly downloads
 
Created
Source

file-extension

Get the extension of a given filename or path

Differences to path.extname:

  • Treats dotfiles as extension (.eslintrc => eslintrc)
  • Treats extensionless files as extension (Makefile => makefile)
  • Doesn't include the dot in the extension (package.json => json)
  • Returns lowercase by default (LICENCE => licence)

Works in Node.js and the browser. The module's size is currently 267 bytes gzipped.

Installation

Node.js
$ npm install --save file-extension
Browser
<script src="file-extension.js"></script>
<!-- Available as global `fileExtension` -->

Example

var fileExtension = require('file-extension'); // Skip this in the browser

// Case insensitive
fileExtension('file.zip');          //=> 'zip'
fileExtension('.Dockerfile');       //=> 'dockerfile'
fileExtension('file');              //=> 'file'
fileExtension('.file.tar');         //=> 'tar'

// Or with case preserved
fileExtension('.Vagrantfile', {preserveCase: true}); //=> 'Vagrantfile'
fileExtension('INDEX.HTML', {preserveCase: true});   //=> 'HTML'

API

fileExtension(filename, [options])

  • filename {String} The file name. Required.
  • options {Object} Options object.
Options
  • preserveCase {Boolean} Whether case should be preserved. Default: false.

© silverwind, distributed under BSD licence

Keywords

FAQs

Package last updated on 31 May 2018

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc