default-to

v0.9.6arrow_drop_down
v0.9.6
STATUS
Passing
DOWNLOADS
4
VISIBILITY
Public
PUBLISHED
5 years ago
SIZE
806 B
Returns the second argument if it is not `null`, `undefined` or `NaN`; otherwise the first argument is returned.
1 contributor
Install default-to as a package?
Copied
npm i @bit/justin-capalbo.ramda.default-to
Set Bit as a scoped registryLearn more
npm config set '@bit:registry' https://node.bit.cloud
Component Example
React
React
Vue
Angular
React Native
Add dependency... help_outline
Just
import
any of the 1 million components
and packages in Bit or NPM to the example.
import Button from '@bit/grommet.grommet.button';
import Lodash from 'lodash';
toggle layout
No preview available
modifieddraft
chevron_left
chevron_right
defaultTo (
default:a,
val:b
) : *

Returns the second argument if it is not null, undefined or NaN; otherwise the first argument is returned.

Example
const defaultTo42 = R.defaultTo(42);

     defaultTo42(null);  //=> 42
     defaultTo42(undefined);  //=> 42
     defaultTo42(false);  //=> false
     defaultTo42('Ramda');  //=> 'Ramda'
     // parseInt('string') results in NaN
     defaultTo42(parseInt('string')); //=> 42
Arguments
default: a

The default value.

val: b

val will be returned instead of default unless val is null, undefined or NaN.

Returns
*

The second value if it is not `null`, `undefined` or `NaN`, otherwise the default value

Help and resources