Skip to content

Commit 4aaac56

Browse files
author
Jordan Hotmann
committed
Trim output file name (unless --notrim)
1 parent 72df4ae commit 4aaac56

File tree

4 files changed

+10
-1
lines changed

4 files changed

+10
-1
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ The new file name does not need to contain a file extension. If you do not speci
2626
```-s```, ```--sim```: Simulate rename and just print new file names
2727
```-n```, ```--noindex```: Do not append an index when renaming multiple files. Use with caution.
2828
```-v```, ```--verbose```: Print all rename operations completed. Prints the same information as the -s option but goes through with the renames.
29+
```--notrim```: Do not trim whitespace at beginning or end of ouput file name
2930
```-h```, ```--help```: Show help
3031

3132
### Variables

bin.js

+3
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ const argv = yargs
5151
alias: 'verbose',
5252
boolean: true,
5353
describe: 'Print all rename operations completed'
54+
}, 'notrim': {
55+
boolean: true,
56+
describe: 'Do not trim whitespace at beginning or end of ouput file name'
5457
}
5558
})
5659
.help('help')

index.js

+5
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ module.exports = {
8787
fileObj.newName = fileObj.newName + replacements.i.function(fileObj, '1');
8888
}
8989

90+
// TRIM output file name unless --notrim option used
91+
if (!args.notrim) {
92+
fileObj.newName = fileObj.newName.trim();
93+
}
94+
9095
let operationText = fileObj.base + ' → ' + fileObj.newName + fileObj.newNameExt;
9196

9297
if (args.s) { // SIMULATED if argument --s just print what the output would be

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rename-cli",
3-
"version": "2.3.0",
3+
"version": "2.4.0",
44
"description": "A command line utility for renaming files",
55
"main": "index.js",
66
"preferGlobal": true,

0 commit comments

Comments
 (0)