# change-file-extension

> Change the file extension of a path

Latest version **1.0.0** (published 2024-08-18) · MIT license · 0 weekly downloads

## Install

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

## Health

**Score 40/100 (D)** — status: maintenance-mode.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2024-08-18 |
| First published | 2023-11-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=18 |
| Dependencies | 0 |
| Unpacked size | 3.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 41 |
| Author | Sindre Sorhus |
| Maintainers | sindresorhus |
| Keywords | change, file, filepath, extension, ext, path, replace, modify, rename, extname, basename, file-extension, file-path |

## Links

- npm: https://www.npmjs.com/package/change-file-extension
- Repository: https://github.com/sindresorhus/change-file-extension
- Homepage: https://github.com/sindresorhus/change-file-extension#readme
- Issues: https://github.com/sindresorhus/change-file-extension/issues
- Funding: https://github.com/sponsors/sindresorhus
- npm.io page: https://npm.io/package/change-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

- 1.0.0 (latest) — 2024-08-18
- 0.1.1 — 2023-12-25
- 0.1.0 — 2023-11-03

## README

# change-file-extension

> Change the file extension of a path

## Install

```sh
npm install change-file-extension
```

## Usage

```js
import changeFileExtension from 'change-file-extension';

changeFileExtension('foo/bar.txt', 'md');
//=> 'foo/bar.md'

changeFileExtension('foo/bar.txt', '.md');
//=> 'foo/bar.md'

changeFileExtension('bar.txt', '');
//=> 'bar'
```

## API

### changeFileExtension(filePath, extension)

#### filePath

Type: `string`

The file path whose extension needs to be changed.

#### extension

Type: `string`

The new extension to replace the old one.

To remove the extension, pass an empty string.

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