replace-in-file
Advanced tools
Comparing version 2.3.2 to 2.4.0
@@ -18,3 +18,3 @@ #!/usr/bin/env node | ||
//Collect main arguments | ||
const from = argv._.shift(); | ||
let from = argv._.shift(); | ||
const to = argv._.shift(); | ||
@@ -27,2 +27,17 @@ | ||
//If the --isRegex flag is passed, send the 'from' parameter | ||
//to the lib as a RegExp object | ||
if (argv.isRegex) { | ||
const flags = from.replace(/.*\/([gimy]*)$/, '$1'); | ||
const pattern = from.replace(new RegExp(`^/(.*?)/${flags}$`), '$1'); | ||
try { | ||
from = new RegExp(pattern, flags); | ||
} | ||
catch (error) { | ||
console.error('Could not create RegExp from \'from\' parameter:'); | ||
console.error(error); | ||
process.exit(1); | ||
} | ||
} | ||
//Log | ||
@@ -29,0 +44,0 @@ console.log(`Replacing '${from}' with '${to}'`); |
{ | ||
"name": "replace-in-file", | ||
"version": "2.3.2", | ||
"version": "2.4.0", | ||
"description": "A simple utility to quickly replace text in one or more files.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/adamreisnz/replace-in-file#readme", |
@@ -98,10 +98,12 @@ # Replace in file | ||
```sh | ||
replace-in-file from to some/file.js,some/**/glob.js | ||
replace-in-file from to some/file.js,some/**/glob.js [--isRegex] | ||
``` | ||
The options `allowEmptyPaths` and `encoding` are supported in the CLI. | ||
In addition, the CLI supports the `verbose` option to list the changed files. | ||
The flags `allowEmptyPaths` and `encoding` are supported in the CLI. | ||
In addition, the CLI supports the `verbose` flag to list the changed files. | ||
Multiple files or globs can be replaced by providing a comma separated list. | ||
A regular expression may be used for the `from` parameter by specifying the `--isRegex` flag. | ||
## License | ||
@@ -108,0 +110,0 @@ (MIT License) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
127090
914
112