# file-extension

> Get the extension of a given filename or path

Latest version **4.0.5** (published 2018-05-31) · BSD-2-Clause license · 0 weekly downloads

## Install

```sh
npm install file-extension
pnpm add file-extension
yarn add file-extension
bun add file-extension
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.0.5 |
| Published | 2018-05-31 |
| First published | 2015-05-03 |
| Weekly downloads | 0 |
| License | BSD-2-Clause |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=4 |
| Dependencies | 0 |
| Unpacked size | 4.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 31 |
| Author | silverwind |
| Maintainers | silverwind |
| Keywords | file, extension, extname, ext, file extension, file-extension |

## Links

- npm: https://www.npmjs.com/package/file-extension
- Repository: https://github.com/silverwind/file-extension
- Homepage: https://github.com/silverwind/file-extension#readme
- Issues: https://github.com/silverwind/file-extension/issues
- npm.io page: https://npm.io/package/file-extension

## Alternatives

- [unionfs](https://npm.io/package/unionfs.md) — 2.2M weekly downloads
- [path-starts-with](https://npm.io/package/path-starts-with.md) — 35.9K weekly downloads
- [redzip](https://npm.io/package/redzip.md) — 1.2K weekly downloads
- [vscode-anymatch](https://npm.io/package/vscode-anymatch.md) — 848 weekly downloads
- [@ledgerhq/coin-filecoin](https://npm.io/package/@ledgerhq/coin-filecoin.md) — 793 weekly downloads

## Recent versions

- 4.0.5 (latest) — 2018-05-31
- 4.0.4 — 2018-05-31
- 4.0.2 — 2018-01-23
- 4.0.1 — 2017-12-10
- 4.0.0 — 2017-12-03
- 3.1.2 — 2017-02-07
- 3.1.1 — 2017-02-07
- 3.1.0 — 2016-11-09
- 3.0.2 — 2016-09-26
- 3.0.1 — 2016-09-26
- 3.0.0 — 2016-09-26
- 2.0.1 — 2015-09-28
- 2.0.0 — 2015-09-28
- 1.1.4 — 2015-08-07
- 1.1.3 — 2015-05-24
- … 6 more at https://npm.io/package/file-extension/versions

## README

# file-extension
[![](https://img.shields.io/npm/v/file-extension.svg?style=flat)](https://www.npmjs.org/package/file-extension) [![](https://img.shields.io/npm/dm/file-extension.svg)](https://www.npmjs.org/package/file-extension) [![](https://api.travis-ci.org/silverwind/file-extension.svg?style=flat)](https://travis-ci.org/silverwind/file-extension)
> Get the extension of a given filename or path

Differences to [`path.extname`](https://nodejs.org/api/path.html#path_path_extname_path):

* 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
```html
<script src="file-extension.js"></script>
<!-- Available as global `fileExtension` -->
```
## Example
```js
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](https://github.com/silverwind), distributed under BSD licence

---
_Source: https://npm.io/package/file-extension · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
