Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

change-file-extension

sindresorhus338.2kMIT1.0.0TypeScript support: included

Change the file extension of a path

change, file, filepath, extension, ext, path, replace, modify, rename, extname, basename, file-extension, file-path

readme

change-file-extension

Change the file extension of a path

Install

npm install change-file-extension

Usage

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.