mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-11 11:27:50 +00:00
Added _.defaultTo. (#2381)
This commit is contained in:
committed by
John-David Dalton
parent
e582ad226a
commit
5fbc5303ff
29
lodash.js
29
lodash.js
@@ -14705,6 +14705,34 @@
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a default value if the input is `undefined`.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @since 4.13.2
|
||||
* @category Util
|
||||
* @param {*} input The value to be checked if it is `undefined`.
|
||||
* @param {*} defaultValue The default value that gets returned if the input is `undefined`.
|
||||
* @returns {*} Returns the input or if it's `undefined`, the default value.
|
||||
* @example
|
||||
*
|
||||
* console.log(_.defaultTo(undefined, 10));
|
||||
* // => 10
|
||||
*
|
||||
* // Inside flow (FP only)
|
||||
* var findOrDefault = _.flow([
|
||||
* _.find(function(number) { number > 5; }),
|
||||
* _.defaultTo(0)
|
||||
* ]);
|
||||
*
|
||||
* findOrDefault([1,2,3]);
|
||||
* // => 0
|
||||
*/
|
||||
function defaultTo(value, defaultValue) {
|
||||
return value === undefined ? defaultValue : value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a function that returns the result of invoking the given functions
|
||||
* with the `this` binding of the created function, where each successive
|
||||
@@ -15979,6 +16007,7 @@
|
||||
lodash.cloneDeepWith = cloneDeepWith;
|
||||
lodash.cloneWith = cloneWith;
|
||||
lodash.deburr = deburr;
|
||||
lodash.defaultTo = defaultTo;
|
||||
lodash.divide = divide;
|
||||
lodash.endsWith = endsWith;
|
||||
lodash.eq = eq;
|
||||
|
||||
Reference in New Issue
Block a user