CLI appends '.svg' to input filename instead of replacing
captain-geek opened this issue · comments
This code will replace the extension instead of just appending it.
nodecli.js:12
outfilename = infilename.replace(/.[a-zA-Z0-9]*$/, '.svg')
Yes, this ignores the edge case where a file doesn't have a '.*' suffix which can either be handled by a test on the next line or not worried about ...
Hi,
Thanks for your feedback!
You're right, it's rather primitive to only append ".svg" to the filename, but it has some advantages as well:
-
The output filename clearly identifies the input file. E.g. if you have
image.gif
,image.jpg
andimage.png
in the same directory, thenimage.jpg.svg
is more informative thanimage.svg
. -
Protects against some kinds of accidental overwrites. Continuing the example above: if you would automatically convert with replacing, then the result from
image.png
would overwrite the results fromimage.gif
andimage.jpg
. -
It's simpler and probably more robust: filename extensions can have special characters also.
https://en.wikipedia.org/wiki/List_of_filename_extensions_%28alphabetical%29
There might be other edge cases for replace / regex, and it is not in the scope of this project to handle these.
nodecli.js
is meant to be an example rather than a real tool, so you're free to change and develop it further. ☺