DEV Community


Posted on • Updated on

What do you guys use for formatting strings in javascript?

Hi there boys and girls!

How do you approach string formatting in javascript? Do you use any library or implement the formating yourselves?

I'm developing a loggin' library which relies quite a bit on formatting so i'm really interested in looking for alternatives and what solutions people have come with.

I've been using this library strif I made for my logging library, and it really does the job.

Top comments (2)

alangdm profile image
Alan Dávalos

Why not just use string template literals?

nombrekeff profile image

Yes, It could be accomplished using template literals, although for the use case I needed it for, it was not enough, I needed to process each string segment separately and process it in some way, also needed something where I could easily enable and disable some part of the formatting (which we call transformers within strif)

For example:

  • To color specific segments of the log.
  • Enabling/disabling color.
  • Having multiple transformers per segment.
  • But most importantly to not add complexity for the user that is not needed.

But yes, for most cases I think template literals are good enough.