Bool Node
Overview
The Bool Node is used to output a boolean constant or convert an input value into a boolean. This node can be useful when you need to create a boolean value for use in other nodes, such as the If Node or If/Else Node.
The Bool Node can either output a constant boolean value that you set in the node's settings, or it can take an input and convert it into a boolean. The conversion follows JavaScript's rules for truthy and falsy values, with two exception:
- Empty arrays are considered falsey
- The string "false" is considered falsey.
If you need to treat empty arrays as truthy, or the string "false" as truthy, you can use the Code Node
- Inputs
- Outputs
- Editor Settings
Inputs
Title | Data Type | Description | Default Value | Notes |
---|---|---|---|---|
Input | any | The value to be converted to a boolean. This input is only available if Use Input is enabled. | N/A |
Outputs
Title | Data Type | Description | Notes |
---|---|---|---|
Value | boolean | The boolean value. If Use Input is enabled, this will be the input value converted to a boolean. |
Editor Settings
Setting | Description | Default Value | Use Input Toggle | Input Data Type |
---|---|---|---|---|
Value | The constant boolean value to output. This setting is only available if Use Input is disabled. | false | Yes | boolean |
Use Input | If enabled, the node will convert an input value to a boolean. If disabled, the node will output a constant boolean value. | false | No | N/A |
Example 1: Using a Constant Boolean Value
- Add a Bool Node to your graph.
- Set the
Value
setting totrue
. - Run the graph. The
Value
output of the Bool Node will betrue
.
Example 2: Converting an Input to a Boolean
- Add a Bool Node to your graph.
- Enable the
Use Input
setting. - Add a Text Node to your graph and set the text to
"Hello"
. - Connect the output of the Text Node to the
Input
of the Bool Node. - Run the graph. The
Value
output of the Bool Node will betrue
, because the string"Hello"
is a truthy value in JavaScript.
Error Handling
The Bool Node cannot error under normal circumstances. If the Use Input
setting is enabled and no input is connected, the node will output false
.
FAQ
Q: What values are considered truthy and falsy in JavaScript?
A: The following values are considered falsy:
false
0
''
(empty string)null
undefined
NaN
- In Rivet, empty arrays are also considered falsy.
- In Rivet, the string "false" is also considered falsy.
All other values are considered truthy.
Q: Can I use the Bool Node to check if an array is empty?
A: Yes, if you connect an array to the Input
of a Bool Node, the Value
output will be false
if the array is empty. If the array is not empty, the Value
output will be true
.
Q: Can I use the Bool Node to check if a string is empty?
A: Yes, you can connect a Text Node to the Input
of a Bool Node. If the string is empty, the Value
output of the Bool Node will be false
. If the string is not empty, the Value
output will be true
.
Q: Can I use the Bool Node to check if a number is zero?
A: Yes, you can connect a Number Node to the Input
of a Bool Node. If the number is zero, the Value
output of the Bool Node will be false
. If the number is not zero, the Value
output will be true
.