UNPKG

982 BJavaScriptView Raw
1var _curry2 =
2/*#__PURE__*/
3require("./internal/_curry2");
4/**
5 * Returns the second argument if it is not `null`, `undefined` or `NaN`;
6 * otherwise the first argument is returned.
7 *
8 * @func
9 * @memberOf R
10 * @since v0.10.0
11 * @category Logic
12 * @sig a -> b -> a | b
13 * @param {a} default The default value.
14 * @param {b} val `val` will be returned instead of `default` unless `val` is `null`, `undefined` or `NaN`.
15 * @return {*} The second value if it is not `null`, `undefined` or `NaN`, otherwise the default value
16 * @example
17 *
18 * const defaultTo42 = R.defaultTo(42);
19 *
20 * defaultTo42(null); //=> 42
21 * defaultTo42(undefined); //=> 42
22 * defaultTo42(false); //=> false
23 * defaultTo42('Ramda'); //=> 'Ramda'
24 * // parseInt('string') results in NaN
25 * defaultTo42(parseInt('string')); //=> 42
26 */
27
28
29var defaultTo =
30/*#__PURE__*/
31_curry2(function defaultTo(d, v) {
32 return v == null || v !== v ? d : v;
33});
34
35module.exports = defaultTo;
\No newline at end of file