addDefault
The addDefault function returns a custom default value when the input is null or undefined.
Syntax
Section titled “Syntax”{input | addDefault:customDefault}Parameters
Section titled “Parameters”input(any): The value to checkcustomDefault(any): The value to return if input is null or undefined
Returns
Section titled “Returns”- The original
inputif it’s not null or undefined - The
customDefaultvalue if input is null or undefined
Examples
Section titled “Examples”Basic default
Section titled “Basic default”{null | addDefault:"N/A"}// Returns: "N/A"Value exists
Section titled “Value exists”{"Active" | addDefault:"Unknown"}// Returns: "Active"With undefined
Section titled “With undefined”{undefined | addDefault:"No data"}// Returns: "No data"Empty string handling
Section titled “Empty string handling”{"" | addDefault:"Empty"}// Returns: "" (empty string is not null/undefined)With vulnerability data
Section titled “With vulnerability data”{vulnerability.cvss_score | addDefault:"Not scored"}// Returns CVSS score or "Not scored" if nullNumeric defaults
Section titled “Numeric defaults”{user.loginCount | addDefault:0}// Returns login count or 0 if nullUse Cases
Section titled “Use Cases”- Handling missing data in reports
- Providing fallback values for optional fields
- Ensuring consistent display of empty values
- Default values for configuration settings
- Placeholder text for undefined properties
This function only checks for null and undefined. Empty strings, zero, and false are considered valid values and will not trigger the default.