Prefix and postfix - redundant dashes
justanotheranonymoususer opened this issue · comments
Tmp Version
0.2.1
Expected Behavior
When I use the following example code from the readme:
tmp.file({ mode: 0o644, prefix: 'prefix-', postfix: '.txt' }, /*...*/);
I expect to get a filename like this:
prefix-blabla-blabla.txt
That was the behavior in old versions.
Experienced Behavior
I get a filename like this:
prefix--blabla-blabla-.txt
While the first redundant dash can be fixed by removing -
from prefix
, the dash before the extension stays there.
i.e. If I have postfix: '.txt'
, I get [...]bla[...]-.tmp
.
@justanotheranonymoususer nice find. Never thought of the suffix actually being meant for an file name extension. But since it is documented that way, we need to fix that.
My proposal would be to test for a leading dot .
. If it is there, the hyphen -
will be omitted. If it is not, then a hyphen will be included in the so generated file name.
What do you think?
@justanotheranonymoususer would you care to provide us with a PR?
@justanotheranonymoususer I did not forget your issue. However, I am having a hard time with this, as the suffix is always meant to be a part of the filename and not representing its extension, e.g. .txt
.
Apart from that, tmp is not meant to write out the terminal file. As of its nature, tmp will just write out temporary files. And if you need them to have a specific extension, feel free to use the available fs methods to move/rename an existing tmp file to a location where it gets persisted, once that it was finalized and closed.
Closing as invalid.
TODO fix the documentation.
@justanotheranonymoususer and since you are the only person who reported this, I think that we are safe with limiting the prefix use.