mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-29 06:27:49 +00:00
Make _.where return all elements when the props object is empty.
This commit is contained in:
2
dist/lodash.compat.js
vendored
2
dist/lodash.compat.js
vendored
@@ -7769,7 +7769,7 @@
|
||||
}
|
||||
return function(object) {
|
||||
var length = propsLength,
|
||||
result = false;
|
||||
result = true;
|
||||
|
||||
while (length--) {
|
||||
var key = props[length];
|
||||
|
||||
2
dist/lodash.compat.min.js
vendored
2
dist/lodash.compat.min.js
vendored
@@ -32,7 +32,7 @@ for(u&&a&&(e=n[++i]);++i<a;)e=t(e,n[i],i,n)}else gt(n,function(n,r,o){e=u?(u=fal
|
||||
else 2<o&&"function"==typeof r[o-1]&&(a=r[--o]);for(;++u<o;){t=r[u];for(var i=-1,l=Fr(t),f=l.length;++i<f;){var c=l[i];n[c]=a?a(n[c],t[c]):t[c]}}return n}function se(t){if(!t||2>arguments.length)return t;var e=Ut(arguments);return e.push(n),ce.apply(null,e)}function pe(n){var t=[];return wt(n,function(n,e){ve(n)&&t.push(e)}),t.sort()}function ge(n){return n&&typeof n=="object"&&typeof n.length=="number"&&Ye.call(n)==Q||false}function he(n){return n&&typeof n=="object"&&1===n.nodeType&&(Or.nodeClass?-1<Ye.call(n).indexOf("Element"):g(n))||false
|
||||
}function ve(n){return typeof n=="function"}function ye(n){var t=typeof n;return n&&("function"==t||"object"==t)||false}function me(n){var t=typeof n;return"number"==t||n&&"object"==t&&Ye.call(n)==ot||false}function de(n){var t=typeof n;return n&&("function"==t||"object"==t)&&Ye.call(n)==at||false}function be(n){return typeof n=="string"||n&&typeof n=="object"&&Ye.call(n)==lt||false}function _e(n){if(!ye(n))return[];for(var t,e=n.length,e=(typeof e=="number"&&0<e&&(Lr(n)||Or.nonEnumStrings&&be(n)||Or.nonEnumArgs&&ge(n))&&e)>>>0,r=-1,u=e-1,o=Re(e),i=0<e,a=Or.enumErrorProps&&(n===Ue||n instanceof Le),l=Or.enumPrototypes&&typeof n=="function";++r<e;)o[r]=De(r);
|
||||
for(var f in n)l&&"prototype"==f||a&&("message"==f||"name"==f)||i&&(t=+f,-1<t&&t<=u&&0==t%1)||o.push(f);if(Or.nonEnumShadows&&n!==Ze){if(t=n.constructor,r=-1,e=J.length,n===(t&&t.prototype))var c=n===Ke?lt:n===Ue?rt:Ye.call(n),c=kr[c];for(;++r<e;)f=J[r],c&&c[f]||!er.call(n,f)||o.push(f)}return o}function we(n,t,e){var r={};if(typeof t!="function")for(var u=-1,i=yt(arguments,true,false,1),a=ye(n)?i.length:0;++u<a;){var l=i[u];l in n&&(r[l]=n[l])}else t=o.createCallback(t,e,3),wt(n,function(n,e,u){t(n,e,u)&&(r[e]=n)
|
||||
});return r}function xe(n){return At(n,Fr)}function Ce(n){return null==n?"":De(n).replace(M,"\\$&")}function je(n,t){var e="";if(t=+t,1>t||null==n||!gr(t))return e;n=De(n);do t%2&&(e+=n),t=Qe(t/2),n+=n;while(t);return e}function ke(n,t,e){var r=typeof n;return"function"==r||null==n?(typeof t=="undefined"||!("prototype"in n))&&n||Z(n,t,e):"object"!=r?Ie(n):Ee(n)}function Oe(n){return n}function Ee(n){n||(n={});var t=Fr(n),e=t.length,r=t[0],u=n[r];return 1!=e||u!==u||ye(u)?function(r){for(var u=e,o=false;u--&&(o=t[u],o=er.call(r,o)&&jt(r[o],n[o],null,true)););return o
|
||||
});return r}function xe(n){return At(n,Fr)}function Ce(n){return null==n?"":De(n).replace(M,"\\$&")}function je(n,t){var e="";if(t=+t,1>t||null==n||!gr(t))return e;n=De(n);do t%2&&(e+=n),t=Qe(t/2),n+=n;while(t);return e}function ke(n,t,e){var r=typeof n;return"function"==r||null==n?(typeof t=="undefined"||!("prototype"in n))&&n||Z(n,t,e):"object"!=r?Ie(n):Ee(n)}function Oe(n){return n}function Ee(n){n||(n={});var t=Fr(n),e=t.length,r=t[0],u=n[r];return 1!=e||u!==u||ye(u)?function(r){for(var u=e,o=true;u--&&(o=t[u],o=er.call(r,o)&&jt(r[o],n[o],null,true)););return o
|
||||
}:function(n){return er.call(n,r)?(n=n[r],u===n&&(0!==u||1/u==1/n)):false}}function Ae(n,t,e){var r=true,u=t&&pe(t);t&&(e||u.length)||(null==e&&(e=t),t=n,n=o,u=pe(t)),false===e?r=false:ye(e)&&"chain"in e&&(r=e.chain),e=-1;for(var i=ve(n),a=u?u.length:0;++e<a;){var l=u[e],f=n[l]=t[l];i&&(n.prototype[l]=function(t){return function(){var e=this.__chain__,u=this.__wrapped__,o=[u];if(rr.apply(o,arguments),o=t.apply(n,o),r||e){if(u===o&&ye(o))return this;o=new n(o),o.__chain__=e}return o}}(f))}}function Se(){}function Ie(n){return function(t){return null==t?w:t[n]
|
||||
}}t=t?_t.defaults(mt.Object(),t,_t.pick(mt,H)):mt;var Re=t.Array,Ne=t.Boolean,Te=t.Date,Le=t.Error,We=t.Function,Fe=t.Math,$e=t.Number,Pe=t.Object,ze=t.RegExp,De=t.String,Be=t.TypeError,qe=Re.prototype,Ue=Le.prototype,Ze=Pe.prototype,Ke=De.prototype,Me=(Me=t.window)&&Me.document,Ve=t._,Xe=Fe.pow(2,53)-1,Ye=Ze.toString,Ge=ze("^"+Ce(Ye).replace(/toString|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),He=Fe.ceil,Je=t.clearTimeout,Qe=Fe.floor,nr=We.prototype.toString,tr=Lt(tr=Pe.getPrototypeOf)&&tr,er=Ze.hasOwnProperty,rr=qe.push,ur=Ze.propertyIsEnumerable,or=Lt(or=t.Set)&&or,ir=t.setTimeout,ar=qe.splice,lr=qe.unshift,fr=function(){try{var n={},t=Lt(t=Pe.defineProperty)&&t,e=t(n,n,n)&&t
|
||||
}catch(r){}return e}(),cr=Lt(cr=Ke.contains)&&cr,sr=Lt(sr=Pe.create)&&sr,pr=Lt(pr=Re.isArray)&&pr,gr=t.isFinite,hr=t.isNaN,vr=Lt(vr=Pe.keys)&&vr,yr=Fe.max,mr=Fe.min,dr=Lt(dr=Te.now)&&dr,br=t.parseInt,_r=Fe.random,wr=Lt(wr=Ke.trim)&&!wr.call(G)&&wr,xr=Lt(xr=Ke.trimLeft)&&!xr.call(G)&&xr,Cr=Lt(Cr=Ke.trimRight)&&!Cr.call(G)&&Cr,jr={};jr[nt]=Re,jr[tt]=Ne,jr[et]=Te,jr[ut]=We,jr[it]=Pe,jr[ot]=$e,jr[at]=ze,jr[lt]=De;var kr={};kr[nt]=kr[et]=kr[ot]={constructor:true,toLocaleString:true,toString:true,valueOf:true},kr[tt]=kr[lt]={constructor:true,toString:true,valueOf:true},kr[rt]=kr[ut]=kr[at]={constructor:true,toString:true},kr[it]={constructor:true},function(){for(var n=J.length;n--;){var t,e=J[n];
|
||||
|
||||
2
dist/lodash.js
vendored
2
dist/lodash.js
vendored
@@ -7545,7 +7545,7 @@
|
||||
}
|
||||
return function(object) {
|
||||
var length = propsLength,
|
||||
result = false;
|
||||
result = true;
|
||||
|
||||
while (length--) {
|
||||
var key = props[length];
|
||||
|
||||
2
dist/lodash.min.js
vendored
2
dist/lodash.min.js
vendored
@@ -32,7 +32,7 @@ else{u||h||(c=i);var y=p-(i-c),m=0>=y||y>p;m?(u&&(u=Ve(u)),c=i,o=n.apply(a,r)):u
|
||||
for(;++u<o;){t=r[u];for(var i=-1,l=Rr(t),f=l.length;++i<f;){var c=l[i];n[c]=a?a(n[c],t[c]):t[c]}}return n}function le(t){if(!t||2>arguments.length)return t;var e=Bt(arguments);return e.push(n),ae.apply(null,e)}function fe(n){var t=[];return dt(n,function(n,e){se(n)&&t.push(e)}),t.sort()}function ce(n){return n&&typeof n=="object"&&typeof n.length=="number"&&Pe.call(n)==H||false}function pe(n){return n&&typeof n=="object"&&1===n.nodeType&&-1<Pe.call(n).indexOf("Element")||false}function se(n){return typeof n=="function"
|
||||
}function he(n){var t=typeof n;return n&&("function"==t||"object"==t)||false}function ge(n){var t=typeof n;return"number"==t||n&&"object"==t&&Pe.call(n)==et||false}function ve(n){return n&&typeof n=="object"&&Pe.call(n)==ut||false}function ye(n){return typeof n=="string"||n&&typeof n=="object"&&Pe.call(n)==ot||false}function me(n){if(!he(n))return[];for(var t,e=n.length,e=(typeof e=="number"&&0<e&&(Er(n)||_r.nonEnumArgs&&ce(n))&&e)>>>0,r=-1,u=e-1,o=Ee(e),i=0<e;++r<e;)o[r]=$e(r);for(var a in n)i&&(t=+a,-1<t&&t<=u&&0==t%1)||o.push(a);
|
||||
return o}function de(n,t,e){var r={};if(typeof t!="function")for(var u=-1,i=ht(arguments,true,false,1),a=he(n)?i.length:0;++u<a;){var l=i[u];l in n&&(r[l]=n[l])}else t=o.createCallback(t,e,3),dt(n,function(n,e,u){t(n,e,u)&&(r[e]=n)});return r}function be(n){return Ct(n,Rr)}function _e(n){return null==n?"":$e(n).replace(K,"\\$&")}function we(n,t){var e="";if(t=+t,1>t||null==n||!lr(t))return e;n=$e(n);do t%2&&(e+=n),t=Xe(t/2),n+=n;while(t);return e}function xe(n,t,e){var r=typeof n;return"function"==r||null==n?(typeof t=="undefined"||!("prototype"in n))&&n||Z(n,t,e):"object"!=r?Oe(n):je(n)
|
||||
}function ke(n){return n}function je(n){n||(n={});var t=Rr(n),e=t.length,r=t[0],u=n[r];return 1!=e||u!==u||he(u)?function(r){for(var u=e,o=false;u--&&(o=t[u],o=He.call(r,o)&&wt(r[o],n[o],null,true)););return o}:function(n){return He.call(n,r)?(n=n[r],u===n&&(0!==u||1/u==1/n)):false}}function Ce(n,t,e){var r=true,u=t&&fe(t);t&&(e||u.length)||(null==e&&(e=t),t=n,n=o,u=fe(t)),false===e?r=false:he(e)&&"chain"in e&&(r=e.chain),e=-1;for(var i=se(n),a=u?u.length:0;++e<a;){var l=u[e],f=n[l]=t[l];i&&(n.prototype[l]=function(t){return function(){var e=this.__chain__,u=this.__wrapped__,o=[u];
|
||||
}function ke(n){return n}function je(n){n||(n={});var t=Rr(n),e=t.length,r=t[0],u=n[r];return 1!=e||u!==u||he(u)?function(r){for(var u=e,o=true;u--&&(o=t[u],o=He.call(r,o)&&wt(r[o],n[o],null,true)););return o}:function(n){return He.call(n,r)?(n=n[r],u===n&&(0!==u||1/u==1/n)):false}}function Ce(n,t,e){var r=true,u=t&&fe(t);t&&(e||u.length)||(null==e&&(e=t),t=n,n=o,u=fe(t)),false===e?r=false:he(e)&&"chain"in e&&(r=e.chain),e=-1;for(var i=se(n),a=u?u.length:0;++e<a;){var l=u[e],f=n[l]=t[l];i&&(n.prototype[l]=function(t){return function(){var e=this.__chain__,u=this.__wrapped__,o=[u];
|
||||
if(Je.apply(o,arguments),o=t.apply(n,o),r||e){if(u===o&&he(o))return this;o=new n(o),o.__chain__=e}return o}}(f))}}function Ae(){}function Oe(n){return function(t){return null==t?_:t[n]}}t=t?mt.defaults(gt.Object(),t,mt.pick(gt,G)):gt;var Ee=t.Array,Ie=t.Boolean,Re=t.Date,Ne=t.Function,Se=t.Math,Te=t.Number,We=t.Object,Fe=t.RegExp,$e=t.String,Le=t.TypeError,ze=Ee.prototype,De=We.prototype,Be=$e.prototype,qe=(qe=t.window)&&qe.document,Ue=t._,Ze=Se.pow(2,53)-1,Pe=De.toString,Ke=Fe("^"+_e(Pe).replace(/toString|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Me=Se.ceil,Ve=t.clearTimeout,Xe=Se.floor,Ye=Ne.prototype.toString,Ge=Nt(Ge=We.getPrototypeOf)&&Ge,He=De.hasOwnProperty,Je=ze.push,Qe=De.propertyIsEnumerable,nr=Nt(nr=t.Set)&&nr,tr=t.setTimeout,er=ze.splice,rr=ze.unshift,ur=function(){try{var n={},t=Nt(t=We.defineProperty)&&t,e=t(n,n,n)&&t
|
||||
}catch(r){}return e}(),or=Nt(or=Be.contains)&&or,ir=Nt(ir=We.create)&&ir,ar=Nt(ar=Ee.isArray)&&ar,lr=t.isFinite,fr=t.isNaN,cr=Nt(cr=We.keys)&&cr,pr=Se.max,sr=Se.min,hr=Nt(hr=Re.now)&&hr,gr=t.parseInt,vr=Se.random,yr=Nt(yr=Be.trim)&&!yr.call(Y)&&yr,mr=Nt(mr=Be.trimLeft)&&!mr.call(Y)&&mr,dr=Nt(dr=Be.trimRight)&&!dr.call(Y)&&dr,br={};br[J]=Ee,br[Q]=Ie,br[nt]=Re,br[tt]=Ne,br[rt]=We,br[et]=Te,br[ut]=Fe,br[ot]=$e,i.prototype=o.prototype;var _r=o.support={};!function(x){for(var n in arguments);_r.funcDecomp=!Nt(t.WinRTError)&&M.test(b),_r.funcNames=typeof Ne.name=="string";
|
||||
try{_r.dom=11===qe.createDocumentFragment().nodeType}catch(e){_r.dom=false}try{_r.nonEnumArgs=!("1"==n&&He.call(arguments,n)&&Qe.call(arguments,n))}catch(r){_r.nonEnumArgs=true}}(0,0),o.templateSettings={escape:$,evaluate:L,interpolate:z,variable:"",imports:{_:o}},ir||(m=function(){function n(){}return function(e){if(he(e)){n.prototype=e;var r=new n;n.prototype=null}return r||t.Object()}}());var wr=nr&&function(n){var t=new nr,e=n?n.length:0;for(t.push=t.add;e--;)t.push(n[e]);return t},xr=ur?function(n,t){lt.value=t,ur(n,E,lt)
|
||||
|
||||
@@ -7788,7 +7788,7 @@
|
||||
}
|
||||
return function(object) {
|
||||
var length = propsLength,
|
||||
result = false;
|
||||
result = true;
|
||||
|
||||
while (length--) {
|
||||
var key = props[length];
|
||||
|
||||
10
test/test.js
10
test/test.js
@@ -5650,9 +5650,9 @@
|
||||
strictEqual(matches(object), false);
|
||||
});
|
||||
|
||||
test('should return `false` when comparing an empty `source`', 1, function() {
|
||||
test('should return `true` when comparing an empty `source`', 1, function() {
|
||||
var matches = _.matches({});
|
||||
strictEqual(matches(object), false);
|
||||
strictEqual(matches(object), true);
|
||||
});
|
||||
}());
|
||||
|
||||
@@ -9261,8 +9261,10 @@
|
||||
deepEqual(_.where(collection, { 'a': 1 }), [{ 'a': 1 }, { 'a': 1, 'b': 2 }]);
|
||||
});
|
||||
|
||||
test('should return an empty array when provided an empty `properties` object', 1, function() {
|
||||
deepEqual(_.where(array, {}), []);
|
||||
test('should match all elements when provided an empty `properties` object', 2, function() {
|
||||
var actual = _.where(array, {});
|
||||
ok(actual !== array);
|
||||
deepEqual(actual, array);
|
||||
});
|
||||
|
||||
test('should deep compare `properties` values', 1, function() {
|
||||
|
||||
Reference in New Issue
Block a user