A simple CLI/Module for regex replacing strings in files & renaming files recursively
MIT License
A simple CLI/Module for regex replacing strings in files & renaming files recursively
This library can be used both locally as a module or globally as a CLI. Simply choose which you'd like via the install command below.
local: npm install regex-replace
global: npm install -g regex-replace
Replace filenames and file contents
regex-replace 'search string' 'replace string' './path/to/recursively/replace'
Replace file content only
regex-replace 'search string' 'replace string' './path/to/recursively/replace' --filecontents
Replace filenames only
regex-replace 'search string' 'replace string' './path/to/recursively/replace' --filenames
Version
regex-replace -v
import regexReplace from 'regex-replace';
const searchString = 'string to search for';
const replaceString = 'string to replace with';
const path = './some/path/to/recursively/replace';
const options = {
filenamesOnly: false, //default
fileContentsOnly: false //default
};
//promise
regexReplace(searchString, replaceString, path, options)
.then(() => {
//do something after successful regex replace
})
.catch((err) => {
//handle errors
});
//async/await
const doRegexReplace = async function() {
try {
await regexReplace(searchString, replaceString, path, options);
} catch (err) {
console.error('err > regexReplace > testing', err);
}
}
//callback (no support for callbacks currently)
regex-replace searchString replaceString path
--filename
or --filenames
For filenames only--filecontent
or --filecontents
For file contents onlyregexReplace(searchString, replaceString, path, options)
false
defaultfalse
defaultregex-replace
yarn
or npm install
npm test
Please read CONTRIBUTING.md for details on code of conduct, and the process for submitting pull requests.
SemVer is used for versioning. For the versions available, see the releases on this repository.
See also the list of contributors who participated in this project.
This project is licensed under the MIT license.