I was chatting with @markus (surpise you?) and we were discussing boolean and strings. Generally, in Node-RED things tend to flow better as boolean as you’re only dealing with true and false. But, in order to do that, you have to figure out how to convert these. This will convert a true or false string and make it a boolean. 3 different use cases.
only convert if it is a string and that string content is either true or false only. Otherwise do nothing.
Using dicts this way is so neat I like this approach and use it in other languages as well, like python where it can be used like a make-shift switch statement.
Here is my take on the same principle (cats and different ways etc…):
A thing to note about dicts and booleans in js, when you set a dict key to a boolean it will actually use the string representation of the boolean. If you use both ‘true’ and the boolean true they are the same value and would be duplicate keys. The beauty is that it also works when referencing it, so if you try to access with the boolean true or the string ‘true’ you’ll get the same item. With that said, the above dict works also for boolean input for the previously described reason, not just the strings.
You can test the above statement with the following in a function node:
That is … true (or ‘true’ if you prefer )
My bias. In python (since v3.x version) It works correctly. I rely a lot on dicts.
This Is one more reason to suspect any J* language