What is replace-ext?
The replace-ext npm package is a utility for replacing the extension of a file path string. It is particularly useful in build processes and file manipulation tasks where you need to change file extensions programmatically.
What are replace-ext's main functionalities?
Replace File Extension
This feature allows you to replace the extension of a given file path. In the code sample, the extension of 'file.txt' is changed to '.md', resulting in 'file.md'.
const replaceExt = require('replace-ext');
const filePath = 'example/file.txt';
const newFilePath = replaceExt(filePath, '.md');
console.log(newFilePath); // Outputs: 'example/file.md'
Other packages similar to replace-ext
path
The 'path' module is a built-in Node.js module that provides utilities for working with file and directory paths. It includes the 'path.format' and 'path.parse' methods, which can be used to achieve similar functionality to replace-ext by manually changing the file extension.
upath
The 'upath' package is a utility for working with file paths across different operating systems. It provides methods like 'upath.changeExt' which can be used to change the file extension, similar to replace-ext. However, upath offers additional cross-platform path handling features.
replace-ext
Replaces a file extension with another one.
Usage
var replaceExt = require('replace-ext');
var path = '/some/dir/file.js';
var newPath = replaceExt(path, '.coffee');
console.log(newPath);
API
replaceExt(path, extension)
Replaces the extension from path
with extension
and returns the updated path string.
Does not replace the extension if path
is not a string or is empty.
replace-ext
for enterprise
Available as part of the Tidelift Subscription.
The maintainers of replace-ext
and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. Learn more.
License
MIT