NodeJS Custom Formatters - parameters not as expected

I’ve become more and more reliant on creating custom formatters, especially for Math (damned JS floating point calculations) and custom date calculations, but I have just come across something new that I haven’t noticed before now having never used more than one function parameter.

As you can see below, I have 3 variables (random string was for debugging):

Yet I have had to add the following to my function for the parameters to line up correctly:

It took me until adding a random string variable in to see that I needed val as the first parameter because the rest were misaligned.

Has it always been the case that val is always the element the formatter is attached to, and the rest of the values come afterwards? Unless I’m blind (most likely), then I haven’t found this in any documentation.

If so, does that mean I can drop the variables in my HJSON when I only need one parameter (the element attached to the formatter)?


Can you elaborate on that? What do you mean with misaligned?

The first argument in the formatter function is always the value it is attached to, the remaining parameters are the ones that you will add in the interface. When you only need one parameter then you can indeed drop the variables in the HJSON.

@patrick Perfect, thanks for that. There are a few formatters I can remove the only variable on now. :slight_smile:

@JonL, what I meant was that say I was trying to get the date parameter from the function above, val would output where I thought date would, date would output where I thought timezone would and so on…

1 Like