mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-01 23:57:49 +00:00
Make _.merge assign null values. [closes #151]
Former-commit-id: 5a839996db9475182d5957d2f8cb4b3c265b0d9f
This commit is contained in:
@@ -41,8 +41,8 @@
|
||||
// flip `typeof` expressions to help optimize Safari and
|
||||
// correct the AMD module definition for AMD build optimizers
|
||||
// (e.g. from `"number" == typeof x` to `typeof x == "number")
|
||||
source = source.replace(/(return)?("[^"]+")\s*([!=]=)\s*(typeof(?:\s*\([^)]+\)|\s+[\w.]+))/g, function(match, ret, type, equality, expression) {
|
||||
return (ret ? ret + ' ' : '') + expression + equality + type;
|
||||
source = source.replace(/(\w)?("[^"]+")\s*([!=]=)\s*(typeof(?:\s*\([^)]+\)|\s+[.\w[\]]+))/g, function(match, other, type, equality, expression) {
|
||||
return (other ? other + ' ' : '') + expression + equality + type;
|
||||
});
|
||||
|
||||
// add trailing semicolon
|
||||
|
||||
@@ -1738,7 +1738,7 @@ Creates a function that is restricted to execute `func` once. Repeat calls to th
|
||||
var initialize = _.once(createApplication);
|
||||
initialize();
|
||||
initialize();
|
||||
// Application is only created once.
|
||||
// `initialize` executes `createApplication` once
|
||||
```
|
||||
|
||||
* * *
|
||||
@@ -2598,7 +2598,7 @@ _.keys({ 'one': 1, 'two': 2, 'three': 3 });
|
||||
### <a id="_mergeobject--source1-source2-"></a>`_.merge(object [, source1, source2, ...])`
|
||||
<a href="#_mergeobject--source1-source2-">#</a> [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1758 "View in source") [Ⓣ][1]
|
||||
|
||||
Recursively merges own enumerable properties of the source object(s), that don't resolve to `null`/`undefined`, into the `destination` object. Subsequent sources will overwrite propery assignments of previous sources.
|
||||
Recursively merges own enumerable properties of the source object(s), that don't resolve to `undefined`, into the `destination` object. Subsequent sources will overwrite propery assignments of previous sources.
|
||||
|
||||
#### Arguments
|
||||
1. `object` *(Object)*: The destination object.
|
||||
@@ -3184,4 +3184,4 @@ A reference to the `lodash` function.
|
||||
<!-- /div -->
|
||||
|
||||
|
||||
[1]: #Arrays "Jump back to the TOC."
|
||||
[1]: #Arrays "Jump back to the TOC."
|
||||
@@ -1726,7 +1726,7 @@
|
||||
|
||||
/**
|
||||
* Recursively merges own enumerable properties of the source object(s), that
|
||||
* don't resolve to `null`/`undefined`, into the `destination` object. Subsequent
|
||||
* don't resolve to `undefined`, into the `destination` object. Subsequent
|
||||
* sources will overwrite propery assignments of previous sources.
|
||||
*
|
||||
* @static
|
||||
@@ -1796,7 +1796,7 @@
|
||||
// recursively merge objects and arrays (susceptible to call stack limits)
|
||||
object[key] = merge(value, source, indicatorObject, stackA, stackB);
|
||||
}
|
||||
} else if (source != null) {
|
||||
} else if (typeof source != 'undefined') {
|
||||
object[key] = source;
|
||||
}
|
||||
});
|
||||
@@ -3682,7 +3682,7 @@
|
||||
* var initialize = _.once(createApplication);
|
||||
* initialize();
|
||||
* initialize();
|
||||
* // Application is only created once.
|
||||
* // `initialize` executes `createApplication` once
|
||||
*/
|
||||
function once(func) {
|
||||
var ran,
|
||||
|
||||
2
lodash.min.js
vendored
2
lodash.min.js
vendored
@@ -11,7 +11,7 @@ var r=n.constructor;return!j(r)&&(!tr||!p(n))||r instanceof r?tt?(sr(n,function(
|
||||
}for(e||(e=[]),u||(u=[]),o=e.length;o--;)if(e[o]==n)return u[o];var a=i?r(n.length):{};return e.push(n),u.push(a),(i?R:vr)(n,function(n,r){a[r]=_(n,t,W,e,u)}),i&&(Et.call(n,"index")&&(a.index=n.index),Et.call(n,"input")&&(a.input=n.input)),a}function d(n){var t=[];return sr(n,function(n,r){j(n)&&t.push(r)}),t.sort()}function b(n){for(var t=-1,r=gr(n),e=r.length,u={};++t<e;){var o=r[t];u[n[o]]=o}return u}function w(n,t,r,e){if(n===t)return 0!==n||1/n==1/t;if(n==W||t==W)return n===t;var u=$t.call(n),o=$t.call(t);
|
||||
if(u==Mt&&(u=Lt),o==Mt&&(o=Lt),u!=o)return X;switch(u){case zt:case Ct:return+n==+t;case Kt:return n!=+n?t!=+t:0==n?1/n==1/t:n==+t;case Ut:case Vt:return n==t+""}if(o=u==Pt,!o){if(n.__wrapped__||t.__wrapped__)return w(n.__wrapped__||n,t.__wrapped__||t);if(u!=Lt||tr&&(p(n)||p(t)))return X;var u=!Yt&&h(n)?Object:n.constructor,i=!Yt&&h(t)?Object:t.constructor;if(u!=i&&(!j(u)||!(u instanceof u&&j(i)&&i instanceof i)))return X}for(r||(r=[]),e||(e=[]),u=r.length;u--;)if(r[u]==n)return e[u]==t;var a=Q,f=0;
|
||||
if(r.push(n),e.push(t),o){if(f=n.length,a=f==t.length)for(;f--&&(a=w(n[f],t[f],r,e)););return a}return sr(n,function(n,u,o){return Et.call(o,u)?(f++,a=Et.call(t,u)&&w(n,t[u],r,e)):void 0}),a&&sr(t,function(n,t,r){return Et.call(r,t)?a=-1<--f:void 0}),a}function j(n){return typeof n=="function"}function x(n){return n?or[typeof n]:X}function O(n){return typeof n=="number"||$t.call(n)==Kt}function A(n){return typeof n=="string"||$t.call(n)==Vt}function E(n,t,r){var e=arguments,u=0,o=2,i=e[3],a=e[4];for(r!==ot&&(i=[],a=[],typeof r!="number"&&(o=e.length));++u<o;)vr(e[u],function(t,r){var e,u,o;
|
||||
if(t&&((u=_r(t))||dr(t))){for(var f=i.length;f--&&!(e=i[f]==t););e?n[r]=a[f]:(i.push(t),a.push((o=n[r],o=u?_r(o)?o:[]:dr(o)?o:{})),n[r]=E(o,t,ot,i,a))}else t!=W&&(n[r]=t)});return n}function S(n){for(var t=-1,r=gr(n),e=r.length,u=Array(e);++t<e;)u[t]=n[r[t]];return u}function k(n,t,r){var e=-1,u=n?n.length:0,o=X,r=(0>r?It(0,u+r):r)||0;return typeof u=="number"?o=-1<(A(n)?n.indexOf(t,r):C(n,t,r)):lr(n,function(n){return++e<r?void 0:!(o=n===t)}),o}function $(n,t,r){var e=Q,t=a(t,r);if(_r(n))for(var r=-1,u=n.length;++r<u&&(e=!!t(n[r],r,n)););else lr(n,function(n,r,u){return e=!!t(n,r,u)
|
||||
if(t&&((u=_r(t))||dr(t))){for(var f=i.length;f--&&!(e=i[f]==t););e?n[r]=a[f]:(i.push(t),a.push((o=n[r],o=u?_r(o)?o:[]:dr(o)?o:{})),n[r]=E(o,t,ot,i,a))}else typeof t!="undefined"&&(n[r]=t)});return n}function S(n){for(var t=-1,r=gr(n),e=r.length,u=Array(e);++t<e;)u[t]=n[r[t]];return u}function k(n,t,r){var e=-1,u=n?n.length:0,o=X,r=(0>r?It(0,u+r):r)||0;return typeof u=="number"?o=-1<(A(n)?n.indexOf(t,r):C(n,t,r)):lr(n,function(n){return++e<r?void 0:!(o=n===t)}),o}function $(n,t,r){var e=Q,t=a(t,r);if(_r(n))for(var r=-1,u=n.length;++r<u&&(e=!!t(n[r],r,n)););else lr(n,function(n,r,u){return e=!!t(n,r,u)
|
||||
});return e}function q(n,t,r){var e=[],t=a(t,r);if(_r(n))for(var r=-1,u=n.length;++r<u;){var o=n[r];t(o,r,n)&&e.push(o)}else lr(n,function(n,r,u){t(n,r,u)&&e.push(n)});return e}function N(n,t,r){var e,t=a(t,r);return R(n,function(n,r,u){return t(n,r,u)?(e=n,X):void 0}),e}function R(n,t,r){if(t&&typeof r=="undefined"&&_r(n))for(var r=-1,e=n.length;++r<e&&t(n[r],r,n)!==X;);else lr(n,t,r);return n}function F(n,t,r){var e=-1,u=n?n.length:0,o=Array(typeof u=="number"?u:0),t=a(t,r);if(_r(n))for(;++e<u;)o[e]=t(n[e],e,n);
|
||||
else lr(n,function(n,r,u){o[++e]=t(n,r,u)});return o}function D(n,t,r){var e=-1/0,o=e;if(!t&&_r(n))for(var r=-1,i=n.length;++r<i;){var f=n[r];f>o&&(o=f)}else t=!t&&A(n)?u:a(t,r),lr(n,function(n,r,u){r=t(n,r,u),r>e&&(e=r,o=n)});return o}function I(n,t){return F(n,t+"")}function T(n,t,r,e){var u=3>arguments.length,t=a(t,e,ot);if(_r(n)){var o=-1,i=n.length;for(u&&(r=n[++o]);++o<i;)r=t(r,n[o],o,n)}else lr(n,function(n,e,o){r=u?(u=X,n):t(r,n,e,o)});return r}function B(n,t,r,e){var u=n,o=n?n.length:0,i=3>arguments.length;
|
||||
if(typeof o!="number")var f=gr(n),o=f.length;else nr&&A(n)&&(u=n.split(""));return t=a(t,e,ot),R(n,function(n,e,a){e=f?f[--o]:--o,r=i?(i=X,u[e]):t(r,u[e],e,a)}),r}function M(n,t,r){var e,t=a(t,r);if(_r(n))for(var r=-1,u=n.length;++r<u&&!(e=t(n[r],r,n)););else lr(n,function(n,r,u){return!(e=t(n,r,u))});return!!e}function P(n,t,r){if(n){var e=n.length;return t==W||r?n[0]:v(n,0,Tt(It(0,t),e))}}function z(n,t){for(var r=-1,e=n?n.length:0,u=[];++r<e;){var o=n[r];_r(o)?St.apply(u,t?o:z(o)):u.push(o)}return u
|
||||
|
||||
@@ -2609,7 +2609,7 @@
|
||||
|
||||
/**
|
||||
* Creates an array of numbers (positive and/or negative) progressing from
|
||||
* `start` up to but not including `stop`. This method is a port of Python's
|
||||
* `start` up to but not including `end`. This method is a port of Python's
|
||||
* `range()` function. See http://docs.python.org/library/functions.html#range.
|
||||
*
|
||||
* @static
|
||||
@@ -3135,7 +3135,7 @@
|
||||
* var initialize = _.once(createApplication);
|
||||
* initialize();
|
||||
* initialize();
|
||||
* // Application is only created once.
|
||||
* // `initialize` executes `createApplication` once
|
||||
*/
|
||||
function once(func) {
|
||||
var ran,
|
||||
|
||||
@@ -622,7 +622,7 @@
|
||||
(function() {
|
||||
var object = Object.freeze({
|
||||
'a': _.identity,
|
||||
'b': null
|
||||
'b': undefined
|
||||
});
|
||||
|
||||
['non-strict', 'strict'].forEach(function(strictMode, index) {
|
||||
@@ -736,7 +736,7 @@
|
||||
deepEqual(lodash.defaults({}, new Foo), Foo.prototype, '_.defaults should assign inherited `source` properties: ' + basename);
|
||||
deepEqual(lodash.extend({}, new Foo), Foo.prototype, '_.extend should assign inherited `source` properties: ' + basename);
|
||||
|
||||
actual = lodash.find(array, function(value) {
|
||||
var actual = lodash.find(array, function(value) {
|
||||
return 'a' in value;
|
||||
});
|
||||
|
||||
@@ -761,7 +761,7 @@
|
||||
|
||||
// avoid issues comparing objects with `deepEqual`
|
||||
object = { 'a': 1, 'b': 2, 'c': 3 };
|
||||
var actual = lodash.omit(object, function(value) { return value == 3; });
|
||||
actual = lodash.omit(object, function(value) { return value == 3; });
|
||||
deepEqual(_.keys(actual).sort(), ['a', 'b', 'c'], '_.omit should not accept a `callback`: ' + basename);
|
||||
|
||||
actual = lodash.pick(object, function(value) { return value != 3; });
|
||||
|
||||
10
test/test.js
10
test/test.js
@@ -1217,6 +1217,16 @@
|
||||
_.reduce(array, _.merge, actual);
|
||||
deepEqual(actual, { 'a': 1, 'b': 2, 'c': 3});
|
||||
});
|
||||
|
||||
test('should assign `null` values', function() {
|
||||
var actual = _.merge({ 'a': 1 }, { 'a': null });
|
||||
strictEqual(actual.a, null);
|
||||
});
|
||||
|
||||
test('should not assign `undefined` values', function() {
|
||||
var actual = _.merge({ 'a': 1 }, { 'a': undefined });
|
||||
equal(actual.a, 1);
|
||||
});
|
||||
}(1, 2, 3));
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
Reference in New Issue
Block a user