mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 18:37:50 +00:00
Make _.defaultTo return the defaultValue for NaN and nullish values.
This commit is contained in:
@@ -14706,8 +14706,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks `value` to determine if a default value should be returned.
|
* Checks `value` to determine whether a default value should be returned in
|
||||||
* If `value` is `undefined`, the `defaultValue` is returned in its place.
|
* its place. The `defaultValue` is returned if `value` is `NaN`, `null`,
|
||||||
|
* or `undefined`.
|
||||||
*
|
*
|
||||||
* @static
|
* @static
|
||||||
* @memberOf _
|
* @memberOf _
|
||||||
@@ -14725,7 +14726,7 @@
|
|||||||
* // => 10
|
* // => 10
|
||||||
*/
|
*/
|
||||||
function defaultTo(value, defaultValue) {
|
function defaultTo(value, defaultValue) {
|
||||||
return value === undefined ? defaultValue : value;
|
return (value == null || value !== value) ? defaultValue : value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -4604,11 +4604,11 @@
|
|||||||
QUnit.module('lodash.defaultTo');
|
QUnit.module('lodash.defaultTo');
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
QUnit.test('should return a default value if `value` is `undefined`', function(assert) {
|
QUnit.test('should return a default value if `value` is `NaN` or nullish', function(assert) {
|
||||||
assert.expect(1);
|
assert.expect(1);
|
||||||
|
|
||||||
var expected = lodashStable.map(falsey, function(value) {
|
var expected = lodashStable.map(falsey, function(value) {
|
||||||
return value === undefined ? 1 : value;
|
return (value == null || value !== value) ? 1 : value;
|
||||||
});
|
});
|
||||||
|
|
||||||
var actual = lodashStable.map(falsey, function(value) {
|
var actual = lodashStable.map(falsey, function(value) {
|
||||||
|
|||||||
Reference in New Issue
Block a user