silverwind/file-extension


Get the extension of a given filename or path

License: BSD-2-Clause

Language: Makefile


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

Project Statistics

Sourcerank 11
Repository Size 128 KB
Stars 19
Forks 1
Watchers 1
Open issues 1
Dependencies 7
Contributors 2
Tags 21
Created
Last updated
Last pushed

Top Contributors See all

silverwind Dominic Barnes

Packages Referencing this Repo

file-extension
Get the extension of a given filename or path
Latest release 4.0.5 - Updated - 19 stars

Recent Tags See all

v4.0.5 May 31, 2018
v4.0.4 May 31, 2018
v4.0.3 May 31, 2018
v4.0.2 January 23, 2018
v4.0.1 December 10, 2017
v4.0.0 December 03, 2017
v3.1.2 February 07, 2017
v3.1.1 February 07, 2017
v3.1.0 November 09, 2016
v3.0.2 September 26, 2016
v3.0.1 September 26, 2016
v3.0.0 September 26, 2016
v2.0.1 September 28, 2015
v2.0.0 September 28, 2015
1.1.4 August 07, 2015

Something wrong with this page? Make a suggestion

Last synced: 2018-06-03 17:06:23 UTC

Login to resync this repository