sprintf.js icon indicating copy to clipboard operation
sprintf.js copied to clipboard

print nothing on %n

Open ctr49 opened this issue 2 years ago • 4 comments

POSIX C/C++ sprintf have a specifier "n" that prints nothing. This can be useful in some cases to suppress content.

Would you mind implementing %n to print nothing in sprint.js?

Thanks!

ctr49 avatar Jun 12 '23 16:06 ctr49

What are the use cases?

alexei avatar Jun 13 '23 09:06 alexei

In my case I use CometVisu as home automation visualization. It uses sprint.js and allows formatting with it. For my custom visualization I sometimes want to suppress output and there is currently no way to do so.

In general I suppose the use case is exactly the same as %n in C

ctr49 avatar Jul 05 '23 17:07 ctr49

@ctr49 I kind of like this idea, see https://github.com/alexei/sprintf.js/pull/228

There's one thing I'm undecided about. %n in C doesn't accept any options, however I think it would be cool if it did e.g. %+'#10n would result in ########## (i.e. as opposed to an empty string). What do you think about this?

alexei avatar Sep 11 '23 13:09 alexei

#228 looks great, thanks!

Regarding the option I can see the point where such a syntax may make sense, but I'm not sure if overloading "n" (having a specific meaning in original sprintf) is self-explanatory or if it deserves a dedicated (conflict-free) option.

ctr49 avatar Sep 13 '23 16:09 ctr49