Methods
orDefault(expression, defaultValue, casteropt, nullable, additionalEmptyValuesopt, nullable) → {*}
If an expression returns a non-value (undefined or null), use the default value instead. Define a caster name, to force expression result/value into certain data type.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
expression |
* | the expression to evaluate |
||
defaultValue |
* | the default value to use if the expression is considered empty |
||
caster |
String | function |
<optional> <nullable> |
null | either a default caster by name ('str', 'string', 'int', 'integer', 'bool', 'boolean', 'float', 'arr', 'array') or a function getting the value and returning the transformed value |
additionalEmptyValues |
Array |
<optional> <nullable> |
null | if set, provides a list of additional values to be considered empty, apart from undefined and null |
Returns:
expression of defaultValue
- Type
- *
Example
function set(name, value){
name = orDefault(name, 'kittens!', 'string', ['', 'none']);
value = orDefault(value, 42, 'int');
}