jankovicsandras / imagetracerjs

Simple raster image tracer and vectorizer written in JavaScript.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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:

  1. The output filename clearly identifies the input file. E.g. if you have image.gif , image.jpg and image.png in the same directory, then image.jpg.svg is more informative than image.svg.

  2. 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 from image.gif and image.jpg.

  3. 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. ☺