source: node_modules/ramda/es/defaultTo.js

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 965 bytes
Line 
1import _curry2 from "./internal/_curry2.js";
2/**
3 * Returns the second argument if it is not `null`, `undefined` or `NaN`;
4 * otherwise the first argument is returned.
5 *
6 * @func
7 * @memberOf R
8 * @since v0.10.0
9 * @category Logic
10 * @sig a -> b -> a | b
11 * @param {a} default The default value.
12 * @param {b} val `val` will be returned instead of `default` unless `val` is `null`, `undefined` or `NaN`.
13 * @return {*} The second value if it is not `null`, `undefined` or `NaN`, otherwise the default value
14 * @example
15 *
16 * const defaultTo42 = R.defaultTo(42);
17 *
18 * defaultTo42(null); //=> 42
19 * defaultTo42(undefined); //=> 42
20 * defaultTo42(false); //=> false
21 * defaultTo42('Ramda'); //=> 'Ramda'
22 * // parseInt('string') results in NaN
23 * defaultTo42(parseInt('string')); //=> 42
24 */
25
26var defaultTo =
27/*#__PURE__*/
28_curry2(function defaultTo(d, v) {
29 return v == null || v !== v ? d : v;
30});
31
32export default defaultTo;
Note: See TracBrowser for help on using the repository browser.