From ca7adb59db16851de8b224ea0e3227818476f096 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Thu, 13 Mar 2014 00:18:13 -0700 Subject: [PATCH] Rebuild dist. --- dist/lodash.compat.js | 288 ++++++++++++++-------------- dist/lodash.compat.min.js | 127 ++++++------- dist/lodash.js | 304 ++++++++++++++--------------- dist/lodash.min.js | 118 ++++++------ dist/lodash.underscore.js | 347 +++++++++++++++++++++++----------- dist/lodash.underscore.min.js | 65 +++---- 6 files changed, 691 insertions(+), 558 deletions(-) diff --git a/dist/lodash.compat.js b/dist/lodash.compat.js index 7474e70f2..222581c7d 100644 --- a/dist/lodash.compat.js +++ b/dist/lodash.compat.js @@ -231,6 +231,18 @@ /*--------------------------------------------------------------------------*/ + /** + * Used by `_.defaults` to customize its `_.assign` use. + * + * @private + * @param {*} objectValue The destination object property value. + * @param {*} sourceValue The source object property value. + * @returns {*} Returns the value to assign to the destination object. + */ + function assignDefaults(objectValue, sourceValue) { + return typeof objectValue == 'undefined' ? sourceValue : objectValue; + } + /** * The base implementation of `compareAscending` used to compare values and * sort them in ascending order without guaranteeing a stable sort. @@ -1328,7 +1340,7 @@ iterable = collection, length = collection ? collection.length : 0; - if (typeof length == 'number') { + if (typeof length == 'number' && length > -1) { length |= 0; if (support.unindexedChars && isString(iterable)) { iterable = iterable.split(''); @@ -1357,7 +1369,7 @@ var iterable = collection, length = collection ? collection.length : 0; - if (typeof length == 'number') { + if (typeof length == 'number' && length > -1) { length = (length |= 0) < 0 ? 0 : length; if (support.unindexedChars && isString(iterable)) { iterable = iterable.split(''); @@ -2802,59 +2814,6 @@ return array; } - /** - * Creates an array of numbers (positive and/or negative) progressing from - * `start` up to but not including `end`. If `start` is less than `stop` a - * zero-length range is created unless a negative `step` is specified. - * - * @static - * @memberOf _ - * @category Arrays - * @param {number} [start=0] The start of the range. - * @param {number} end The end of the range. - * @param {number} [step=1] The value to increment or decrement by. - * @returns {Array} Returns the new array of numbers. - * @example - * - * _.range(4); - * // => [0, 1, 2, 3] - * - * _.range(1, 5); - * // => [1, 2, 3, 4] - * - * _.range(0, 20, 5); - * // => [0, 5, 10, 15] - * - * _.range(0, -4, -1); - * // => [0, -1, -2, -3] - * - * _.range(1, 4, 0); - * // => [1, 1, 1] - * - * _.range(0); - * // => [] - */ - function range(start, end, step) { - start = +start || 0; - step = typeof step == 'number' ? step : (+step || 1); - - if (end == null) { - end = start; - start = 0; - } - // use `Array(length)` so engines like Chakra and V8 avoid slower modes - // http://youtu.be/XAqIpGU8ZZk#t=17m25s - var index = -1, - length = nativeMax(0, ceil((end - start) / (step || 1))), - result = Array(length); - - while (++index < length) { - result[index] = start; - start += step; - } - return result; - } - /** * Removes all elements from an array that the predicate returns truthy for * and returns an array of removed elements. The predicate is bound to `thisArg` @@ -2954,21 +2913,19 @@ var index = -1, length = array ? array.length : 0; - if (typeof start == 'undefined') { - start = 0; - } else if (start < 0) { + start |= 0; + if (start < 0) { start = nativeMax(length + start, 0); } else if (start > length) { start = length; } - if (typeof end == 'undefined') { - end = length; - } else if (end < 0) { + end = typeof end == 'undefined' ? length : (end | 0); + if (end < 0) { end = nativeMax(length + end, 0); } else if (end > length) { end = length; } - length = (length = (end - start) | 0) < 0 ? 0 : length; + length = start > end ? 0 : (end - start); var result = Array(length); while (++index < length) { @@ -3583,20 +3540,19 @@ */ function contains(collection, target, fromIndex) { var length = collection ? collection.length : 0; - fromIndex = typeof fromIndex == 'number' ? fromIndex | 0 : 0; + fromIndex = (typeof fromIndex == 'number' && fromIndex) | 0; - if (typeof length == 'number') { - length = (length |= 0) < 0 ? 0 : length; - if (fromIndex >= length) { - return false; - } + if (typeof length == 'number' && length > -1) { if (typeof collection == 'string' || !isArray(collection) && isString(collection)) { + if (fromIndex >= length) { + return false; + } return nativeContains ? nativeContains.call(collection, target, fromIndex) : collection.indexOf(target, fromIndex) > -1; } var indexOf = getIndexOf(); - fromIndex = fromIndex < 0 ? nativeMax(0, length + fromIndex) : fromIndex; + fromIndex = fromIndex < 0 ? nativeMax(0, (length | 0) + fromIndex) : fromIndex; return indexOf(collection, target, fromIndex) > -1; } var index = -1, @@ -3819,27 +3775,12 @@ * // => { 'name': 'fred', 'age': 40, 'blocked': true } */ function find(collection, predicate, thisArg) { - predicate = lodash.createCallback(predicate, thisArg, 3); if (isArray(collection)) { - var index = -1, - length = collection.length; - - while (++index < length) { - var value = collection[index]; - if (predicate(value, index, collection)) { - return value; - } - } - } else { - var result; - baseEach(collection, function(value, index, collection) { - if (predicate(value, index, collection)) { - result = value; - return false; - } - }); - return result; + var index = findIndex(collection, predicate, thisArg); + return index > -1 ? collection[index] : undefined; } + var key = findKey(collection, predicate, thisArg); + return typeof key == 'string' ? collection[key] : undefined; } /** @@ -3863,16 +3804,12 @@ * // => 3 */ function findLast(collection, predicate, thisArg) { - var result; - - predicate = lodash.createCallback(predicate, thisArg, 3); - baseEachRight(collection, function(value, index, collection) { - if (predicate(value, index, collection)) { - result = value; - return false; - } - }); - return result; + if (isArray(collection)) { + var index = findLastIndex(collection, predicate, thisArg); + return index > -1 ? collection[index] : undefined; + } + var key = findLastKey(collection, predicate, thisArg); + return typeof key == 'string' ? collection[key] : undefined; } /** @@ -4060,7 +3997,7 @@ var args = slice(arguments, 2), index = -1, isFunc = typeof methodName == 'function', - length = collection ? collection.length | 0 : 0, + length = (collection && collection.length) | 0, result = Array(length < 0 ? 0 : length); baseEach(collection, function(value) { @@ -4110,7 +4047,7 @@ */ function map(collection, callback, thisArg) { var index = -1, - length = collection ? collection.length | 0 : 0, + length = (collection && collection.length) | 0, result = Array(length < 0 ? 0 : length); callback = lodash.createCallback(callback, thisArg, 3); @@ -4499,7 +4436,7 @@ collection = collection.split(''); } if (n == null || guard) { - var length = collection ? collection.length | 0 : 0; + var length = (collection && collection.length) | 0; return length > 0 ? collection[baseRandom(0, length - 1)] : undefined; } var result = shuffle(collection); @@ -4524,7 +4461,7 @@ */ function shuffle(collection) { var index = -1, - length = collection ? collection.length | 0 : 0, + length = (collection && collection.length) | 0, result = Array(length < 0 ? 0 : length); baseEach(collection, function(value) { @@ -4675,8 +4612,8 @@ */ function sortBy(collection, callback, thisArg) { var index = -1, + length = (collection && collection.length) | 0, multi = callback && isArray(callback), - length = collection ? collection.length | 0 : 0, result = Array(length < 0 ? 0 : length); if (!multi) { @@ -5674,33 +5611,10 @@ * _.defaults({ 'name': 'barney' }, { 'name': 'fred', 'employer': 'slate' }); * // => { 'name': 'barney', 'employer': 'slate' } */ - function defaults(object, source, guard) { - if (!object) { - return object; - } - var args = arguments, - argsIndex = 0, - argsLength = args.length, - type = typeof guard; - - // enables use as a callback for functions like `_.reduce` - if ((type == 'number' || type == 'string') && args[3] && args[3][guard] === source) { - argsLength = 2; - } - while (++argsIndex < argsLength) { - source = args[argsIndex]; - var index = -1, - props = keys(source), - length = props.length; - - while (++index < length) { - var key = props[index]; - if (typeof object[key] == 'undefined') { - object[key] = source[key]; - } - } - } - return object; + function defaults() { + var args = slice(arguments); + args.push(assignDefaults); + return assign.apply(null, args); } /** @@ -6026,7 +5940,7 @@ * @returns {boolean} Returns `true` if the `value` is an `arguments` object, else `false`. * @example * - * (function() { return _.isArguments(arguments); })(1, 2, 3); + * (function() { return _.isArguments(arguments); })(); * // => true * * _.isArguments([1, 2, 3]); @@ -6055,11 +5969,11 @@ * @returns {boolean} Returns `true` if the `value` is an array, else `false`. * @example * - * (function() { return _.isArray(arguments); })(); - * // => false - * * _.isArray([1, 2, 3]); * // => true + * + * (function() { return _.isArray(arguments); })(); + * // => false */ var isArray = nativeIsArray || function(value) { return value && typeof value == 'object' && typeof value.length == 'number' && @@ -6076,6 +5990,9 @@ * @returns {boolean} Returns `true` if the `value` is a boolean value, else `false`. * @example * + * _.isBoolean(false); + * // => true + * * _.isBoolean(null); * // => false */ @@ -6096,6 +6013,9 @@ * * _.isDate(new Date); * // => true + * + * _.isDate('Wed May 23 2012'); + * // => false */ function isDate(value) { return value && typeof value == 'object' && toString.call(value) == dateClass || false; @@ -6113,6 +6033,9 @@ * * _.isElement(document.body); * // => true + * + * _.isElement(''); + * // => false */ function isElement(value) { return value && typeof value == 'object' && value.nodeType === 1 && @@ -6138,14 +6061,20 @@ * @returns {boolean} Returns `true` if the `value` is empty, else `false`. * @example * + * _.isEmpty(null); + * // => true + * + * _.isEmpty(true); + * // => true + * + * _.isEmpty(1); + * // => true + * * _.isEmpty([1, 2, 3]); * // => false * - * _.isEmpty({}); - * // => true - * - * _.isEmpty(''); - * // => true + * _.isEmpty({ 'a': 1 }); + * // => false */ function isEmpty(value) { var result = true; @@ -6270,6 +6199,9 @@ * * _.isFunction(_); * // => true + * + * _.isFunction(/abc/); + * // => false */ function isFunction(value) { return typeof value == 'function'; @@ -6355,7 +6287,7 @@ * _.isNull(null); * // => true * - * _.isNull(undefined); + * _.isNull(void 0); * // => false */ function isNull(value) { @@ -6375,8 +6307,14 @@ * @returns {boolean} Returns `true` if the `value` is a number, else `false`. * @example * - * _.isNumber(8.4 * 5); + * _.isNumber(8.4); * // => true + * + * _.isNumber(NaN); + * // => true + * + * _.isNumber('8.4'); + * // => false */ function isNumber(value) { var type = typeof value; @@ -6430,8 +6368,11 @@ * @returns {boolean} Returns `true` if the `value` is a regular expression, else `false`. * @example * - * _.isRegExp(/fred/); + * _.isRegExp(/abc/); * // => true + * + * _.isRegExp('/abc/'); + * // => false */ function isRegExp(value) { var type = typeof value; @@ -6449,8 +6390,11 @@ * @returns {boolean} Returns `true` if the `value` is a string, else `false`. * @example * - * _.isString('fred'); + * _.isString('abc'); * // => true + * + * _.isString(1); + * // => false */ function isString(value) { return typeof value == 'string' || @@ -6469,6 +6413,9 @@ * * _.isUndefined(void 0); * // => true + * + * _.isUndefined(null); + * // => false */ function isUndefined(value) { return typeof value == 'undefined'; @@ -7998,6 +7945,61 @@ return baseRandom(min, max); } + /** + * Creates an array of numbers (positive and/or negative) progressing from + * `start` up to but not including `end`. If `start` is less than `stop` a + * zero-length range is created unless a negative `step` is specified. + * + * @static + * @memberOf _ + * @category Utilities + * @param {number} [start=0] The start of the range. + * @param {number} end The end of the range. + * @param {number} [step=1] The value to increment or decrement by. + * @returns {Array} Returns the new array of numbers. + * @example + * + * _.range(4); + * // => [0, 1, 2, 3] + * + * _.range(1, 5); + * // => [1, 2, 3, 4] + * + * _.range(0, 20, 5); + * // => [0, 5, 10, 15] + * + * _.range(0, -4, -1); + * // => [0, -1, -2, -3] + * + * _.range(1, 4, 0); + * // => [1, 1, 1] + * + * _.range(0); + * // => [] + */ + function range(start, end, step) { + start = +start || 0; + step = step == null ? 1 : (+step || 0); + + if (end == null) { + end = start; + start = 0; + } else { + end = +end || 0; + } + // use `Array(length)` so engines like Chakra and V8 avoid slower modes + // http://youtu.be/XAqIpGU8ZZk#t=17m25s + var index = -1, + length = nativeMax(0, ceil((end - start) / (step || 1))), + result = Array(length); + + while (++index < length) { + result[index] = start; + start += step; + } + return result; + } + /** * Resolves the value of property `key` on `object`. If `key` is a function * it will be invoked with the `this` binding of `object` and its result diff --git a/dist/lodash.compat.min.js b/dist/lodash.compat.min.js index 961dd5c52..9c5085cb4 100644 --- a/dist/lodash.compat.min.js +++ b/dist/lodash.compat.min.js @@ -3,67 +3,66 @@ * Lo-Dash 2.4.1 (Custom Build) lodash.com/license | Underscore.js 1.6.0 underscorejs.org/LICENSE * Build: `lodash -o ./dist/lodash.compat.js` */ -;(function(){function n(n,t){if(n!==t){if(n>t||typeof n=="undefined")return 1;if(ne||13e||8202r||13r||8202a(e,l)&&f.push(l);return f}function st(n,t){var r=-1,e=n,u=n?n.length:0;if(typeof u=="number")for(u|=0,be.unindexedChars&&hr(e)&&(e=e.split(""));++r(e|=0)?0:e,be.unindexedChars&&hr(r)&&(r=r.split(""));e--&&false!==t(r[e],e,n););else yt(n,t,Se);return n}function ht(n,t,r,e){e=(0|e)-1;for(var u=n?n.length:0,o=[];++ei(s,h)&&((u||f)&&s.push(h),c.push(p))}return c}function Ct(n,t){for(var r=-1,e=t(n),u=e.length,o=kr(u);++rr&&(r=0),s&&(a=[]),p&&(i=[]),h=[n,t,r,e,u,o,a,i],t==w||t==(w|k)?f(h):Z(h)) -}function At(){var n=(n=u.indexOf)===Tt?t:n;return n}function St(n){return typeof n=="function"&&Ur.test(Zr.call(n))}function It(n){var t,r;return!n||qr.call(n)!=ut||!Yr.call(n,"constructor")&&(t=n.constructor,fr(t)&&!(t instanceof t))||!be.argsClass&&ir(n)||!be.nodeClass&&p(n)?false:be.ownLast?(gt(n,function(n,t,e){return r=Yr.call(e,t),false},gr),false!==r):(gt(n,function(n,t){r=t},gr),typeof r=="undefined"||Yr.call(n,r))}function Rt(n){for(var t=-1,r=gr(n),e=r.length,u=[];++ta?0:a)}function Tt(n,r,e){var u=n?n.length:0;if(typeof e=="number")e=0|(0>e?fe(0,u+e):e);else if(e)return e=$t(n,r),u&&n[e]===r?e:-1;return t(n,r,e)}function Lt(n,t,r){var e=n?n.length:0;if(typeof t!="number"&&null!=t){var o=e,a=0;for(t=u.createCallback(t,r,3);o--&&t(n[o],o,n);)a++}else a=null==t||r?1:t; -return a=e-a,Pt(n,0,0>a?0:a)}function Wt(n,t,r){var e=n?n.length:0;if(typeof t!="number"&&null!=t){var o=e,a=0;for(t=u.createCallback(t,r,3);o--&&t(n[o],o,n);)a++}else if(a=t,null==a||r)return n?n[e-1]:_;return a=e-a,Pt(n,0>a?0:a)}function Ft(n,t,r){if(typeof t!="number"&&null!=t){var e=-1,o=n?n.length:0,a=0;for(t=u.createCallback(t,r,3);++et?0:t;return Pt(n,a)}function Pt(n,t,r){var e=-1,u=n?n.length:0;for(typeof t=="undefined"?t=0:0>t?t=fe(u+t,0):t>u&&(t=u),typeof r=="undefined"?r=u:0>r?r=fe(u+r,0):r>u&&(r=u),u=0>(u=r-t|0)?0:u,r=kr(u);++e>>1,r(n[e])r?0:r);++t(e|=0)?0:e,r>=e)return false;if(typeof n=="string"||!Ee(n)&&hr(n))return ee?ee.call(n,t,r):-1r?fe(0,e+r):r,-1o?0:o);if(t=u.createCallback(t,r,3),Ee(n))for(;++ea&&(a=l)}else t=null==t&&hr(n)?e:u.createCallback(t,r,3),st(n,function(n,r,e){r=t(n,r,e),r>o&&(o=r,a=n)});return a}function Ht(n,t,r,e){var o=3>arguments.length;if(t=u.createCallback(t,e,4),Ee(n)){var a=-1,i=n.length;for(o&&i&&(r=n[++a]);++aarguments.length;return t=u.createCallback(t,e,4),pt(n,function(n,e,u){r=o?(o=false,n):t(r,n,e,u)}),r}function Qt(n){var t=-1,r=n?0|n.length:0,e=kr(0>r?0:r); -return st(n,function(n){var r=wt(0,++t);e[t]=e[r],e[r]=n}),e}function nr(n,t,r){var e;if(t=u.createCallback(t,r,3),Ee(n)){r=-1;for(var o=n.length;++rarguments.length)return Et(n,w,null,t);if(n)var r=n[A]?n[A][2]:n.length,e=Pt(arguments,2),r=r-e.length;return Et(n,w|k,r,t,e)}function rr(n,t,r){var e,u,o,a,i,l,f,c=0,s=false,p=true;if(!fr(n))throw new Wr;if(t=0>t?0:t,true===r)var h=true,p=false;else cr(r)&&(h=r.leading,s="maxWait"in r&&(fe(t,r.maxWait)||0),p="trailing"in r?r.trailing:p); -var g=function(){var r=t-(Fe()-a);0>=r||r>t?(u&&Mr(u),r=f,u=l=f=_,r&&(c=Fe(),o=n.apply(i,e),l||u||(e=i=null))):l=Qr(g,r)},v=function(){l&&Mr(l),u=l=f=_,(p||s!==t)&&(c=Fe(),o=n.apply(i,e),l||u||(e=i=null))};return function(){if(e=arguments,a=Fe(),i=this,f=p&&(l||!h),false===s)var r=h&&!l;else{u||h||(c=a);var y=s-(a-c),m=0>=y||y>s;m?(u&&(u=Mr(u)),c=a,o=n.apply(i,e)):u||(u=Qr(v,y))}return m&&l?l=Mr(l):l||t===s||(l=Qr(g,t)),r&&(m=true,o=n.apply(i,e)),!m||l||u||(e=i=null),o}}function er(n){if(!fr(n))throw new Wr; -return function(){return!n.apply(this,arguments)}}function ur(n,t,r){if(!n)return n;var e=arguments,u=0,o=e.length,a=typeof r;if("number"!=a&&"string"!=a||!e[3]||e[3][r]!==t||(o=2),3t||null==n)return r;n=Lr(n);do t%2&&(r+=n),t=Vr(t/2),n+=n;while(t);return r}function br(n,t,r){var e=typeof n;return"function"==e||null==n?(typeof t=="undefined"||!("prototype"in n))&&n||q(n,t,r):"object"!=e?jr(n):wr(n)}function _r(n){return n}function wr(n){n||(n={});var t=Se(n),r=t.length,e=t[0],u=n[e];return 1!=r||u!==u||cr(u)?function(e){for(var u=r,o=false;u--&&(o=t[u],o=Yr.call(e,o)&&bt(e[o],n[o],null,true)););return o}:function(n){return Yr.call(n,e)?(n=n[e],u===n&&(0!==u||1/u==1/n)):false -}}function xr(n,t,r){var e=true,o=t&&ar(t);t&&(r||o.length)||(null==r&&(r=t),t=n,n=u,o=ar(t)),false===r?e=false:cr(r)&&"chain"in r&&(e=r.chain),r=-1;for(var a=fr(n),i=o?o.length:0;++r--n?t.apply(this,arguments):void 0}},u.assign=ur,u.at=function(n,t){var r=arguments,e=-1,u=ht(r,true,false,1),o=u.length,a=typeof t;for("number"!=a&&"string"!=a||!r[2]||r[2][t]!==n||(o=1),be.unindexedChars&&hr(n)&&(n=n.split("")),r=kr(o);++earguments.length?Et(t,w|x,null,n):Et(t,w|x|k,null,n,Pt(arguments,2))},u.chain=function(n){return n=new o(n),n.__chain__=true,n},u.compact=function(n){for(var t=-1,r=n?n.length:0,e=0,u=[];++t(h?r(h,c):i(f,c))){for(u=o,(h||f).push(c);--u;)if(h=a[u],0>(h?r(h,c):i(e[u],c)))continue n; -p.push(c)}}return p},u.invert=function(n,t){for(var r=-1,e=Se(n),u=e.length,o={};++ro?0:o);return st(n,function(n){a[++e]=(u?t:n[t]).apply(n,r)}),a},u.keys=Se,u.keysIn=gr,u.map=Yt,u.mapValues=function(n,t,r){var e={};return t=u.createCallback(t,r,3),mt(n,function(n,r,u){e[r]=t(n,r,u)}),e},u.matches=wr,u.max=Gt,u.memoize=function(n,t){if(!fr(n))throw new Wr; -var r=function(){var e=r.cache,u=t?t.apply(this,arguments):"_"+arguments[0];return Yr.call(e,u)?e[u]:e[u]=n.apply(this,arguments)};return r.cache={},r},u.merge=function(n,t,r){if(!n)return n;var e=arguments,u=e.length,o=typeof r;if("number"!=o&&"string"!=o||!e[3]||e[3][r]!==t||(u=2),3l?0:l); -for(o||(t=u.createCallback(t,r,3)),st(n,function(n,r,u){if(o)for(r=t.length,u=kr(r);r--;)u[r]=n[t[r]];else u=t(n,r,u);f[++e]={a:u,b:e,c:n}}),l=f.length,f.sort(o?i:a);l--;)f[l]=f[l].c;return f},u.tap=function(n,t,r){return t.call(r,n),n},u.throttle=function(n,t,r){var e=true,u=true;if(!fr(n))throw new Wr;return false===r?e=false:cr(r)&&(e="leading"in r?!!r.leading:e,u="trailing"in r?!!r.trailing:u),lt.leading=e,lt.maxWait=+t,lt.trailing=u,rr(n,t,lt)},u.times=function(n,t,r){n=-1<(n=+n)?n:0;var e=-1,u=kr(n);for(t=q(t,r,1);++er?fe(0,e+r):ce(r,e-1))+1);e--;)if(n[e]===t)return e; -return-1},u.mixin=xr,u.noConflict=function(){return n._=Br,this},u.noop=Cr,u.now=Fe,u.pad=function(n,t,r){n=null==n?"":Lr(n),t|=0;var e=n.length;return e=n.length)return n;var o=r-e.length;if(1>o)return e;if(r=n.slice(0,o),null==u)return r+e;if(pr(u)){if(n.slice(o).search(u)){var a,i,l=n.slice(0,o);for(u.global||(u=Tr(u.source,(D.exec(u)||"")+"g")),u.lastIndex=0;a=u.exec(l);)i=a.index; -r=r.slice(0,null==i?o:i)}}else n.indexOf(u,o)!=o&&(u=r.lastIndexOf(u),-1n.indexOf(";")?n:n.replace(T,d))},u.uniqueId=function(n){var t=++S;return Lr(null==n?"":n)+t},u.all=Kt,u.any=nr,u.detect=Vt,u.findWhere=Vt,u.foldl=Ht,u.foldr=Jt,u.include=Ut,u.inject=Ht,xr(function(){var n={};return mt(u,function(t,r){u.prototype[r]||(n[r]=t)}),n}(),false),u.first=Nt,u.last=Wt,u.sample=function(n,t,r){return n&&typeof n.length!="number"?n=yr(n):be.unindexedChars&&hr(n)&&(n=n.split("")),null==t||r?(t=n?0|n.length:0,0"']/g,W=/<%-([\s\S]+?)%>/g,F=/<%([\s\S]+?)%>/g,P=/<%=([\s\S]+?)%>/g,$=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,D=/\w*$/,z=/^\s*function[ \n\r\t]+\w/,B=/^0[xX]/,q=/[\xC0-\xFF]/g,U=/($^)/,K=/[.*+?^${}()|[\]\\]/g,M=/\bthis\b/,V=/['\n\r\t\u2028\u2029\\]/g,Z=/[A-Z]{2,}|[a-zA-Z0-9][a-z0-9]*/g,X=" \t\x0B\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000",Y="Array Boolean Date Error Function Math Number Object RegExp Set String _ clearTimeout document isFinite isNaN parseInt setTimeout TypeError window WinRTError".split(" "),G="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" "),H="[object Arguments]",J="[object Array]",Q="[object Boolean]",nt="[object Date]",tt="[object Error]",rt="[object Function]",et="[object Number]",ut="[object Object]",ot="[object RegExp]",at="[object String]",it={}; -it[rt]=false,it[H]=it[J]=it[Q]=it[nt]=it[et]=it[ut]=it[ot]=it[at]=true;var lt={leading:false,maxWait:0,trailing:false},ft={configurable:false,enumerable:false,value:null,writable:false},ct={"&":"&","<":"<",">":">",'"':""","'":"'"},st={"&":"&","<":"<",">":">",""":'"',"'":"'"},pt={\u00c0:"A",\u00c1:"A",\u00c2:"A",\u00c3:"A",\u00c4:"A",\u00c5:"A",\u00e0:"a",\u00e1:"a",\u00e2:"a",\u00e3:"a",\u00e4:"a",\u00e5:"a",\u00c7:"C",\u00e7:"c",\u00d0:"D",\u00f0:"d",\u00c8:"E",\u00c9:"E",\u00ca:"E",\u00cb:"E",\u00e8:"e",\u00e9:"e",\u00ea:"e",\u00eb:"e",\u00cc:"I",\u00cd:"I",\u00ce:"I",\u00cf:"I",\u00ec:"i",\u00ed:"i",\u00ee:"i",\u00ef:"i",\u00d1:"N",\u00f1:"n",\u00d2:"O",\u00d3:"O",\u00d4:"O",\u00d5:"O",\u00d6:"O",\u00d8:"O",\u00f2:"o",\u00f3:"o",\u00f4:"o",\u00f5:"o",\u00f6:"o",\u00f8:"o",\u00d9:"U",\u00da:"U",\u00db:"U",\u00dc:"U",\u00f9:"u",\u00fa:"u",\u00fb:"u",\u00fc:"u",\u00dd:"Y",\u00fd:"y",\u00ff:"y",\u00c6:"AE",\u00e6:"ae",\u00de:"Th",\u00fe:"th",\u00df:"ss","\xd7":" ","\xf7":" "},ht={"function":true,object:true},gt={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"},vt=ht[typeof window]&&window||this,yt=ht[typeof exports]&&exports&&!exports.nodeType&&exports,ht=ht[typeof module]&&module&&!module.nodeType&&module,mt=yt&&ht&&typeof global=="object"&&global; -!mt||mt.global!==mt&&mt.window!==mt&&mt.self!==mt||(vt=mt);var mt=ht&&ht.exports===yt&&yt,dt=b();typeof define=="function"&&typeof define.amd=="object"&&define.amd?(vt._=dt, define(function(){return dt})):yt&&ht?mt?(ht.exports=dt)._=dt:yt._=dt:vt._=dt}).call(this); \ No newline at end of file +;(function(){function n(n,t){return typeof n=="undefined"?t:n}function t(n,t){if(n!==t){if(n>t||typeof n=="undefined")return 1;if(ne||13e||8202r||13r||8202a(t,l)&&f.push(l);return f}function pt(n,t){var r=-1,e=n,u=n?n.length:0;if(typeof u=="number"&&-1(e|=0)?0:e,je.unindexedChars&&dr(r)&&(r=r.split(""));e--&&false!==t(r[e],e,n););else mt(n,t,Le);return n}function gt(n,t,r,e){e=(0|e)-1;for(var u=n?n.length:0,o=[];++ei(s,h)&&((u||f)&&s.push(h),c.push(p))}return c}function jt(n,t){for(var r=-1,e=t(n),u=e.length,o=Ir(u);++rr&&(r=0),s&&(a=[]),p&&(i=[]),h=[n,t,r,e,u,o,a,i],t==x||t==(x|O)?c(h):X(h)) +}function St(){var n=(n=o.indexOf)===Ft?r:n;return n}function It(n){return typeof n=="function"&&Xr.test(Jr.call(n))}function Rt(n){var t,r;return!n||Zr.call(n)!=ot||!ne.call(n,"constructor")&&(t=n.constructor,gr(t)&&!(t instanceof t))||!je.argsClass&&pr(n)||!je.nodeClass&&h(n)?false:je.ownLast?(vt(n,function(n,t,e){return r=ne.call(e,t),false},br),false!==r):(vt(n,function(n,t){r=t},br),typeof r=="undefined"||ne.call(n,r))}function Nt(n){for(var t=-1,r=br(n),e=r.length,u=[];++ta?0:a)}function Ft(n,t,e){var u=n?n.length:0;if(typeof e=="number")e=0|(0>e?ge(0,u+e):e); +else if(e)return e=Bt(n,t),u&&n[e]===t?e:-1;return r(n,t,e)}function Pt(n,t,r){var e=n?n.length:0;if(typeof t!="number"&&null!=t){var u=e,a=0;for(t=o.createCallback(t,r,3);u--&&t(n[u],u,n);)a++}else a=null==t||r?1:t;return a=e-a,zt(n,0,0>a?0:a)}function $t(n,t,r){var e=n?n.length:0;if(typeof t!="number"&&null!=t){var u=e,a=0;for(t=o.createCallback(t,r,3);u--&&t(n[u],u,n);)a++}else if(a=t,null==a||r)return n?n[e-1]:w;return a=e-a,zt(n,0>a?0:a)}function Dt(n,t,r){if(typeof t!="number"&&null!=t){var e=-1,u=n?n.length:0,a=0; +for(t=o.createCallback(t,r,3);++et?0:t;return zt(n,a)}function zt(n,t,r){var e=-1,u=n?n.length:0;for(t|=0,0>t?t=ge(u+t,0):t>u&&(t=u),r=typeof r=="undefined"?u:0|r,0>r?r=ge(u+r,0):r>u&&(r=u),u=t>r?0:r-t,r=Ir(u);++e>>1,r(n[e])r?0:r);++tr?ge(0,(0|e)+r):r,-1u?0:u);if(t=o.createCallback(t,r,3),Ne(n))for(;++ea&&(a=l)}else t=null==t&&dr(n)?u:o.createCallback(t,r,3),pt(n,function(n,r,u){r=t(n,r,u),r>e&&(e=r,a=n)});return a}function nr(n,t,r,e){var u=3>arguments.length;if(t=o.createCallback(t,e,4),Ne(n)){var a=-1,i=n.length;for(u&&i&&(r=n[++a]);++aarguments.length;return t=o.createCallback(t,e,4),ht(n,function(n,e,o){r=u?(u=false,n):t(r,n,e,o)}),r}function rr(n){var t=-1,r=0|(n&&n.length),e=Ir(0>r?0:r); +return pt(n,function(n){var r=xt(0,++t);e[t]=e[r],e[r]=n}),e}function er(n,t,r){var e;if(t=o.createCallback(t,r,3),Ne(n)){r=-1;for(var u=n.length;++rarguments.length)return At(n,x,null,t);if(n)var r=n[S]?n[S][2]:n.length,e=zt(arguments,2),r=r-e.length;return At(n,x|O,r,t,e)}function or(n,t,r){var e,u,o,a,i,l,f,c=0,s=false,p=true;if(!gr(n))throw new zr;if(t=0>t?0:t,true===r)var h=true,p=false;else vr(r)&&(h=r.leading,s="maxWait"in r&&(ge(t,r.maxWait)||0),p="trailing"in r?r.trailing:p); +var g=function(){var r=t-(Be()-a);0>=r||r>t?(u&&Gr(u),r=f,u=l=f=w,r&&(c=Be(),o=n.apply(i,e),l||u||(e=i=null))):l=ue(g,r)},v=function(){l&&Gr(l),u=l=f=w,(p||s!==t)&&(c=Be(),o=n.apply(i,e),l||u||(e=i=null))};return function(){if(e=arguments,a=Be(),i=this,f=p&&(l||!h),false===s)var r=h&&!l;else{u||h||(c=a);var y=s-(a-c),m=0>=y||y>s;m?(u&&(u=Gr(u)),c=a,o=n.apply(i,e)):u||(u=ue(v,y))}return m&&l?l=Gr(l):l||t===s||(l=ue(g,t)),r&&(m=true,o=n.apply(i,e)),!m||l||u||(e=i=null),o}}function ar(n){if(!gr(n))throw new zr; +return function(){return!n.apply(this,arguments)}}function ir(n,t,r){if(!n)return n;var e=arguments,u=0,o=e.length,a=typeof r;if("number"!=a&&"string"!=a||!e[3]||e[3][r]!==t||(o=2),3t||null==n)return r;n=Dr(n);do t%2&&(r+=n),t=Hr(t/2),n+=n;while(t);return r}function jr(n,t,r){var e=typeof n;return"function"==e||null==n?(typeof t=="undefined"||!("prototype"in n))&&n||U(n,t,r):"object"!=e?Sr(n):Or(n)}function kr(n){return n}function Or(n){n||(n={});var t=Le(n),r=t.length,e=t[0],u=n[e];return 1!=r||u!==u||vr(u)?function(e){for(var u=r,o=false;u--&&(o=t[u],o=ne.call(e,o)&&_t(e[o],n[o],null,true)););return o}:function(n){return ne.call(n,e)?(n=n[e],u===n&&(0!==u||1/u==1/n)):false +}}function Er(n,t,r){var e=true,u=t&&sr(t);t&&(r||u.length)||(null==r&&(r=t),t=n,n=o,u=sr(t)),false===r?e=false:vr(r)&&"chain"in r&&(e=r.chain),r=-1;for(var a=gr(n),i=u?u.length:0;++r--n?t.apply(this,arguments):void 0}},o.assign=ir,o.at=function(n,t){var r=arguments,e=-1,u=gt(r,true,false,1),o=u.length,a=typeof t;for("number"!=a&&"string"!=a||!r[2]||r[2][t]!==n||(o=1),je.unindexedChars&&dr(n)&&(n=n.split("")),r=Ir(o);++earguments.length?At(t,x|C,null,n):At(t,x|C|O,null,n,zt(arguments,2))},o.chain=function(n){return n=new a(n),n.__chain__=true,n},o.compact=function(n){for(var t=-1,r=n?n.length:0,e=0,u=[];++t(h?e(h,c):i(f,c))){for(u=o,(h||f).push(c);--u;)if(h=a[u],0>(h?e(h,c):i(t[u],c)))continue n; +p.push(c)}}return p},o.invert=function(n,t){for(var r=-1,e=Le(n),u=e.length,o={};++ro?0:o);return pt(n,function(n){a[++e]=(u?t:n[t]).apply(n,r)}),a},o.keys=Le,o.keysIn=br,o.map=Jt,o.mapValues=function(n,t,r){var e={};return t=o.createCallback(t,r,3),dt(n,function(n,r,u){e[r]=t(n,r,u)}),e},o.matches=Or,o.max=Qt,o.memoize=function(n,t){if(!gr(n))throw new zr; +var r=function(){var e=r.cache,u=t?t.apply(this,arguments):"_"+arguments[0];return ne.call(e,u)?e[u]:e[u]=n.apply(this,arguments)};return r.cache={},r},o.merge=function(n,t,r){if(!n)return n;var e=arguments,u=e.length,o=typeof r;if("number"!=o&&"string"!=o||!e[3]||e[3][r]!==t||(u=2),3u?0:u);for(a||(t=o.createCallback(t,r,3)),pt(n,function(n,r,u){if(a)for(r=t.length,u=Ir(r);r--;)u[r]=n[t[r]]; +else u=t(n,r,u);f[++e]={a:u,b:e,c:n}}),u=f.length,f.sort(a?l:i);u--;)f[u]=f[u].c;return f},o.tap=function(n,t,r){return t.call(r,n),n},o.throttle=function(n,t,r){var e=true,u=true;if(!gr(n))throw new zr;return false===r?e=false:vr(r)&&(e="leading"in r?!!r.leading:e,u="trailing"in r?!!r.trailing:u),ft.leading=e,ft.maxWait=+t,ft.trailing=u,or(n,t,ft)},o.times=function(n,t,r){n=-1<(n=+n)?n:0;var e=-1,u=Ir(n);for(t=U(t,r,1);++er?ge(0,e+r):ve(r,e-1))+1);e--;)if(n[e]===t)return e; +return-1},o.mixin=Er,o.noConflict=function(){return t._=Vr,this},o.noop=Ar,o.now=Be,o.pad=function(n,t,r){n=null==n?"":Dr(n),t|=0;var e=n.length;return e=n.length)return n;var o=r-e.length;if(1>o)return e;if(r=n.slice(0,o),null==u)return r+e;if(mr(u)){if(n.slice(o).search(u)){var a,i,l=n.slice(0,o);for(u.global||(u=$r(u.source,(z.exec(u)||"")+"g")),u.lastIndex=0;a=u.exec(l);)i=a.index; +r=r.slice(0,null==i?o:i)}}else n.indexOf(u,o)!=o&&(u=r.lastIndexOf(u),-1n.indexOf(";")?n:n.replace(L,b))},o.uniqueId=function(n){var t=++I;return Dr(null==n?"":n)+t},o.all=Zt,o.any=er,o.detect=Yt,o.findWhere=Yt,o.foldl=nr,o.foldr=tr,o.include=Vt,o.inject=nr,Er(function(){var n={};return dt(o,function(t,r){o.prototype[r]||(n[r]=t)}),n}(),false),o.first=Wt,o.last=$t,o.sample=function(n,t,r){return n&&typeof n.length!="number"?n=wr(n):je.unindexedChars&&dr(n)&&(n=n.split("")),null==t||r?(t=0|(n&&n.length),0"']/g,F=/<%-([\s\S]+?)%>/g,P=/<%([\s\S]+?)%>/g,$=/<%=([\s\S]+?)%>/g,D=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,z=/\w*$/,B=/^\s*function[ \n\r\t]+\w/,q=/^0[xX]/,U=/[\xC0-\xFF]/g,K=/($^)/,M=/[.*+?^${}()|[\]\\]/g,V=/\bthis\b/,Z=/['\n\r\t\u2028\u2029\\]/g,X=/[A-Z]{2,}|[a-zA-Z0-9][a-z0-9]*/g,Y=" \t\x0B\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000",G="Array Boolean Date Error Function Math Number Object RegExp Set String _ clearTimeout document isFinite isNaN parseInt setTimeout TypeError window WinRTError".split(" "),H="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" "),J="[object Arguments]",Q="[object Array]",nt="[object Boolean]",tt="[object Date]",rt="[object Error]",et="[object Function]",ut="[object Number]",ot="[object Object]",at="[object RegExp]",it="[object String]",lt={}; +lt[et]=false,lt[J]=lt[Q]=lt[nt]=lt[tt]=lt[ut]=lt[ot]=lt[at]=lt[it]=true;var ft={leading:false,maxWait:0,trailing:false},ct={configurable:false,enumerable:false,value:null,writable:false},st={"&":"&","<":"<",">":">",'"':""","'":"'"},pt={"&":"&","<":"<",">":">",""":'"',"'":"'"},ht={\u00c0:"A",\u00c1:"A",\u00c2:"A",\u00c3:"A",\u00c4:"A",\u00c5:"A",\u00e0:"a",\u00e1:"a",\u00e2:"a",\u00e3:"a",\u00e4:"a",\u00e5:"a",\u00c7:"C",\u00e7:"c",\u00d0:"D",\u00f0:"d",\u00c8:"E",\u00c9:"E",\u00ca:"E",\u00cb:"E",\u00e8:"e",\u00e9:"e",\u00ea:"e",\u00eb:"e",\u00cc:"I",\u00cd:"I",\u00ce:"I",\u00cf:"I",\u00ec:"i",\u00ed:"i",\u00ee:"i",\u00ef:"i",\u00d1:"N",\u00f1:"n",\u00d2:"O",\u00d3:"O",\u00d4:"O",\u00d5:"O",\u00d6:"O",\u00d8:"O",\u00f2:"o",\u00f3:"o",\u00f4:"o",\u00f5:"o",\u00f6:"o",\u00f8:"o",\u00d9:"U",\u00da:"U",\u00db:"U",\u00dc:"U",\u00f9:"u",\u00fa:"u",\u00fb:"u",\u00fc:"u",\u00dd:"Y",\u00fd:"y",\u00ff:"y",\u00c6:"AE",\u00e6:"ae",\u00de:"Th",\u00fe:"th",\u00df:"ss","\xd7":" ","\xf7":" "},gt={"function":true,object:true},vt={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"},yt=gt[typeof window]&&window||this,mt=gt[typeof exports]&&exports&&!exports.nodeType&&exports,gt=gt[typeof module]&&module&&!module.nodeType&&module,dt=mt&>&&typeof global=="object"&&global; +!dt||dt.global!==dt&&dt.window!==dt&&dt.self!==dt||(yt=dt);var dt=gt&>.exports===mt&&mt,bt=_();typeof define=="function"&&typeof define.amd=="object"&&define.amd?(yt._=bt, define(function(){return bt})):mt&>?dt?(gt.exports=bt)._=bt:mt._=bt:yt._=bt}).call(this); \ No newline at end of file diff --git a/dist/lodash.js b/dist/lodash.js index 34ccba2e1..675e5bcde 100644 --- a/dist/lodash.js +++ b/dist/lodash.js @@ -224,6 +224,18 @@ /*--------------------------------------------------------------------------*/ + /** + * Used by `_.defaults` to customize its `_.assign` use. + * + * @private + * @param {*} objectValue The destination object property value. + * @param {*} sourceValue The source object property value. + * @returns {*} Returns the value to assign to the destination object. + */ + function assignDefaults(objectValue, sourceValue) { + return typeof objectValue == 'undefined' ? sourceValue : objectValue; + } + /** * The base implementation of `compareAscending` used to compare values and * sort them in ascending order without guaranteeing a stable sort. @@ -1171,7 +1183,7 @@ iterable = collection, length = collection ? collection.length : 0; - if (typeof length == 'number') { + if (typeof length == 'number' && length > -1) { length |= 0; while (++index < length) { if (callback(iterable[index], index, collection) === false) { @@ -1197,7 +1209,7 @@ var iterable = collection, length = collection ? collection.length : 0; - if (typeof length == 'number') { + if (typeof length == 'number' && length > -1) { length = (length |= 0) < 0 ? 0 : length; while (length--) { if (callback(iterable[length], length, collection) === false) { @@ -1745,7 +1757,7 @@ callback = lodash.createCallback(callback, thisArg, 3); var index = -1, - length = collection ? collection.length | 0 : 0; + length = (collection && collection.length) | 0; if (length > 0) { while (++index < length) { @@ -2627,59 +2639,6 @@ return array; } - /** - * Creates an array of numbers (positive and/or negative) progressing from - * `start` up to but not including `end`. If `start` is less than `stop` a - * zero-length range is created unless a negative `step` is specified. - * - * @static - * @memberOf _ - * @category Arrays - * @param {number} [start=0] The start of the range. - * @param {number} end The end of the range. - * @param {number} [step=1] The value to increment or decrement by. - * @returns {Array} Returns the new array of numbers. - * @example - * - * _.range(4); - * // => [0, 1, 2, 3] - * - * _.range(1, 5); - * // => [1, 2, 3, 4] - * - * _.range(0, 20, 5); - * // => [0, 5, 10, 15] - * - * _.range(0, -4, -1); - * // => [0, -1, -2, -3] - * - * _.range(1, 4, 0); - * // => [1, 1, 1] - * - * _.range(0); - * // => [] - */ - function range(start, end, step) { - start = +start || 0; - step = typeof step == 'number' ? step : (+step || 1); - - if (end == null) { - end = start; - start = 0; - } - // use `Array(length)` so engines like Chakra and V8 avoid slower modes - // http://youtu.be/XAqIpGU8ZZk#t=17m25s - var index = -1, - length = nativeMax(0, ceil((end - start) / (step || 1))), - result = Array(length); - - while (++index < length) { - result[index] = start; - start += step; - } - return result; - } - /** * Removes all elements from an array that the predicate returns truthy for * and returns an array of removed elements. The predicate is bound to `thisArg` @@ -2779,21 +2738,19 @@ var index = -1, length = array ? array.length : 0; - if (typeof start == 'undefined') { - start = 0; - } else if (start < 0) { + start |= 0; + if (start < 0) { start = nativeMax(length + start, 0); } else if (start > length) { start = length; } - if (typeof end == 'undefined') { - end = length; - } else if (end < 0) { + end = typeof end == 'undefined' ? length : (end | 0); + if (end < 0) { end = nativeMax(length + end, 0); } else if (end > length) { end = length; } - length = (length = (end - start) | 0) < 0 ? 0 : length; + length = start > end ? 0 : (end - start); var result = Array(length); while (++index < length) { @@ -3405,20 +3362,19 @@ */ function contains(collection, target, fromIndex) { var length = collection ? collection.length : 0; - fromIndex = typeof fromIndex == 'number' ? fromIndex | 0 : 0; + fromIndex = (typeof fromIndex == 'number' && fromIndex) | 0; - if (typeof length == 'number') { - length = (length |= 0) < 0 ? 0 : length; - if (fromIndex >= length) { - return false; - } + if (typeof length == 'number' && length > -1) { if (typeof collection == 'string' || !isArray(collection) && isString(collection)) { + if (fromIndex >= length) { + return false; + } return nativeContains ? nativeContains.call(collection, target, fromIndex) : collection.indexOf(target, fromIndex) > -1; } var indexOf = getIndexOf(); - fromIndex = fromIndex < 0 ? nativeMax(0, length + fromIndex) : fromIndex; + fromIndex = fromIndex < 0 ? nativeMax(0, (length | 0) + fromIndex) : fromIndex; return indexOf(collection, target, fromIndex) > -1; } var index = -1, @@ -3517,7 +3473,7 @@ predicate = lodash.createCallback(predicate, thisArg, 3); var index = -1, - length = collection ? collection.length | 0 : 0; + length = (collection && collection.length) | 0; if (length > 0) { while (++index < length) { @@ -3578,7 +3534,7 @@ predicate = lodash.createCallback(predicate, thisArg, 3); var index = -1, - length = collection ? collection.length | 0 : 0; + length = (collection && collection.length) | 0; if (length > 0) { while (++index < length) { @@ -3641,27 +3597,13 @@ * // => { 'name': 'fred', 'age': 40, 'blocked': true } */ function find(collection, predicate, thisArg) { - predicate = lodash.createCallback(predicate, thisArg, 3); - var index = -1, - length = collection ? collection.length | 0 : 0; - + var length = (collection && collection.length) | 0; if (length > 0) { - while (++index < length) { - var value = collection[index]; - if (predicate(value, index, collection)) { - return value; - } - } - } else { - var result; - baseEach(collection, function(value, index, collection) { - if (predicate(value, index, collection)) { - result = value; - return false; - } - }); - return result; + var index = findIndex(collection, predicate, thisArg); + return index > -1 ? collection[index] : undefined; } + var key = findKey(collection, predicate, thisArg); + return typeof key == 'string' ? collection[key] : undefined; } /** @@ -3685,16 +3627,13 @@ * // => 3 */ function findLast(collection, predicate, thisArg) { - var result; - - predicate = lodash.createCallback(predicate, thisArg, 3); - baseEachRight(collection, function(value, index, collection) { - if (predicate(value, index, collection)) { - result = value; - return false; - } - }); - return result; + var length = (collection && collection.length) | 0; + if (length > 0) { + var index = findLastIndex(collection, predicate, thisArg); + return index > -1 ? collection[index] : undefined; + } + var key = findLastKey(collection, predicate, thisArg); + return typeof key == 'string' ? collection[key] : undefined; } /** @@ -3725,7 +3664,7 @@ */ function forEach(collection, callback, thisArg) { var index = -1, - length = collection ? collection.length | 0 : 0; + length = (collection && collection.length) | 0; callback = callback && typeof thisArg == 'undefined' ? callback : baseCreateCallback(callback, thisArg, 3); if (length > 0) { @@ -3758,7 +3697,7 @@ * // => logs each number from right to left and returns '3,2,1' */ function forEachRight(collection, callback, thisArg) { - var length = collection ? collection.length | 0 : 0; + var length = (collection && collection.length) | 0; callback = callback && typeof thisArg == 'undefined' ? callback : baseCreateCallback(callback, thisArg, 3); if (length > 0) { @@ -3885,7 +3824,7 @@ var args = slice(arguments, 2), index = -1, isFunc = typeof methodName == 'function', - length = collection ? collection.length | 0 : 0, + length = (collection && collection.length) | 0, result = Array(length < 0 ? 0 : length); baseEach(collection, function(value) { @@ -3935,7 +3874,7 @@ */ function map(collection, callback, thisArg) { var index = -1, - length = collection ? collection.length | 0 : 0; + length = (collection && collection.length) | 0; callback = lodash.createCallback(callback, thisArg, 3); if (length > 0) { @@ -4207,7 +4146,7 @@ callback = lodash.createCallback(callback, thisArg, 4); var index = -1, - length = collection ? collection.length | 0 : 0; + length = (collection && collection.length) | 0; if (length > 0) { if (noaccum && length) { @@ -4323,7 +4262,7 @@ collection = values(collection); } if (n == null || guard) { - var length = collection ? collection.length | 0 : 0; + var length = (collection && collection.length) | 0; return length > 0 ? collection[baseRandom(0, length - 1)] : undefined; } var result = shuffle(collection); @@ -4348,7 +4287,7 @@ */ function shuffle(collection) { var index = -1, - length = collection ? collection.length | 0 : 0, + length = (collection && collection.length) | 0, result = Array(length < 0 ? 0 : length); baseEach(collection, function(value) { @@ -4432,7 +4371,7 @@ predicate = lodash.createCallback(predicate, thisArg, 3); var index = -1, - length = collection ? collection.length | 0 : 0; + length = (collection && collection.length) | 0; if (length > 0) { while (++index < length) { @@ -4499,8 +4438,8 @@ */ function sortBy(collection, callback, thisArg) { var index = -1, + length = (collection && collection.length) | 0, multi = callback && isArray(callback), - length = collection ? collection.length | 0 : 0, result = Array(length < 0 ? 0 : length); if (!multi) { @@ -5496,33 +5435,10 @@ * _.defaults({ 'name': 'barney' }, { 'name': 'fred', 'employer': 'slate' }); * // => { 'name': 'barney', 'employer': 'slate' } */ - function defaults(object, source, guard) { - if (!object) { - return object; - } - var args = arguments, - argsIndex = 0, - argsLength = args.length, - type = typeof guard; - - // enables use as a callback for functions like `_.reduce` - if ((type == 'number' || type == 'string') && args[3] && args[3][guard] === source) { - argsLength = 2; - } - while (++argsIndex < argsLength) { - source = args[argsIndex]; - var index = -1, - props = keys(source), - length = props.length; - - while (++index < length) { - var key = props[index]; - if (typeof object[key] == 'undefined') { - object[key] = source[key]; - } - } - } - return object; + function defaults() { + var args = slice(arguments); + args.push(assignDefaults); + return assign.apply(null, args); } /** @@ -5848,7 +5764,7 @@ * @returns {boolean} Returns `true` if the `value` is an `arguments` object, else `false`. * @example * - * (function() { return _.isArguments(arguments); })(1, 2, 3); + * (function() { return _.isArguments(arguments); })(); * // => true * * _.isArguments([1, 2, 3]); @@ -5870,11 +5786,11 @@ * @returns {boolean} Returns `true` if the `value` is an array, else `false`. * @example * - * (function() { return _.isArray(arguments); })(); - * // => false - * * _.isArray([1, 2, 3]); * // => true + * + * (function() { return _.isArray(arguments); })(); + * // => false */ var isArray = nativeIsArray || function(value) { return value && typeof value == 'object' && typeof value.length == 'number' && @@ -5891,6 +5807,9 @@ * @returns {boolean} Returns `true` if the `value` is a boolean value, else `false`. * @example * + * _.isBoolean(false); + * // => true + * * _.isBoolean(null); * // => false */ @@ -5911,6 +5830,9 @@ * * _.isDate(new Date); * // => true + * + * _.isDate('Wed May 23 2012'); + * // => false */ function isDate(value) { return value && typeof value == 'object' && toString.call(value) == dateClass || false; @@ -5928,6 +5850,9 @@ * * _.isElement(document.body); * // => true + * + * _.isElement(''); + * // => false */ function isElement(value) { return value && typeof value == 'object' && value.nodeType === 1 && @@ -5953,14 +5878,20 @@ * @returns {boolean} Returns `true` if the `value` is empty, else `false`. * @example * + * _.isEmpty(null); + * // => true + * + * _.isEmpty(true); + * // => true + * + * _.isEmpty(1); + * // => true + * * _.isEmpty([1, 2, 3]); * // => false * - * _.isEmpty({}); - * // => true - * - * _.isEmpty(''); - * // => true + * _.isEmpty({ 'a': 1 }); + * // => false */ function isEmpty(value) { var result = true; @@ -6084,6 +6015,9 @@ * * _.isFunction(_); * // => true + * + * _.isFunction(/abc/); + * // => false */ function isFunction(value) { return typeof value == 'function'; @@ -6163,7 +6097,7 @@ * _.isNull(null); * // => true * - * _.isNull(undefined); + * _.isNull(void 0); * // => false */ function isNull(value) { @@ -6183,8 +6117,14 @@ * @returns {boolean} Returns `true` if the `value` is a number, else `false`. * @example * - * _.isNumber(8.4 * 5); + * _.isNumber(8.4); * // => true + * + * _.isNumber(NaN); + * // => true + * + * _.isNumber('8.4'); + * // => false */ function isNumber(value) { var type = typeof value; @@ -6238,8 +6178,11 @@ * @returns {boolean} Returns `true` if the `value` is a regular expression, else `false`. * @example * - * _.isRegExp(/fred/); + * _.isRegExp(/abc/); * // => true + * + * _.isRegExp('/abc/'); + * // => false */ function isRegExp(value) { return value && typeof value == 'object' && toString.call(value) == regexpClass || false; @@ -6255,8 +6198,11 @@ * @returns {boolean} Returns `true` if the `value` is a string, else `false`. * @example * - * _.isString('fred'); + * _.isString('abc'); * // => true + * + * _.isString(1); + * // => false */ function isString(value) { return typeof value == 'string' || @@ -6275,6 +6221,9 @@ * * _.isUndefined(void 0); * // => true + * + * _.isUndefined(null); + * // => false */ function isUndefined(value) { return typeof value == 'undefined'; @@ -7771,6 +7720,61 @@ return baseRandom(min, max); } + /** + * Creates an array of numbers (positive and/or negative) progressing from + * `start` up to but not including `end`. If `start` is less than `stop` a + * zero-length range is created unless a negative `step` is specified. + * + * @static + * @memberOf _ + * @category Utilities + * @param {number} [start=0] The start of the range. + * @param {number} end The end of the range. + * @param {number} [step=1] The value to increment or decrement by. + * @returns {Array} Returns the new array of numbers. + * @example + * + * _.range(4); + * // => [0, 1, 2, 3] + * + * _.range(1, 5); + * // => [1, 2, 3, 4] + * + * _.range(0, 20, 5); + * // => [0, 5, 10, 15] + * + * _.range(0, -4, -1); + * // => [0, -1, -2, -3] + * + * _.range(1, 4, 0); + * // => [1, 1, 1] + * + * _.range(0); + * // => [] + */ + function range(start, end, step) { + start = +start || 0; + step = step == null ? 1 : (+step || 0); + + if (end == null) { + end = start; + start = 0; + } else { + end = +end || 0; + } + // use `Array(length)` so engines like Chakra and V8 avoid slower modes + // http://youtu.be/XAqIpGU8ZZk#t=17m25s + var index = -1, + length = nativeMax(0, ceil((end - start) / (step || 1))), + result = Array(length); + + while (++index < length) { + result[index] = start; + start += step; + } + return result; + } + /** * Resolves the value of property `key` on `object`. If `key` is a function * it will be invoked with the `this` binding of `object` and its result diff --git a/dist/lodash.min.js b/dist/lodash.min.js index 6b73200de..eb5128a93 100644 --- a/dist/lodash.min.js +++ b/dist/lodash.min.js @@ -3,62 +3,62 @@ * Lo-Dash 2.4.1 (Custom Build) lodash.com/license | Underscore.js 1.6.0 underscorejs.org/LICENSE * Build: `lodash modern -o ./dist/lodash.js` */ -;(function(){function n(n,t){if(n!==t){if(n>t||typeof n=="undefined")return 1;if(ne||13e||8202r||13r||8202i(e,f)&&l.push(f);return l}function ft(n,t){var r=-1,e=n?n.length:0;if(typeof e=="number")for(e|=0;++r(r|=0)?0:r;r--&&false!==t(n[r],r,n););else ht(n,t,ke);return n}function ct(n,t,r,e){e=(0|e)-1;for(var u=n?n.length:0,o=[];++ea(p,h)&&((u||l)&&p.push(h),c.push(s))}return c}function _t(n,t){for(var r=-1,e=t(n),u=e.length,o=xr(u);++rr&&(r=0),p&&(i=[]),s&&(a=[]),h=[n,t,r,e,u,o,i,a],t==_||t==(_|j)?l(h):V(h)) -}function Ct(){var n=(n=u.indexOf)===Rt?t:n;return n}function Ot(n){return typeof n=="function"&&Lr.test(Ur.call(n))}function At(n){var t,r;return n&&Dr.call(n)==tt&&(Kr.call(n,"constructor")||(t=n.constructor,!ir(t)||t instanceof t))?(pt(n,function(n,t){r=t},pr),typeof r=="undefined"||Kr.call(n,r)):false}function It(n){for(var t=-1,r=pr(n),e=r.length,u=[];++ti?0:i)}function Rt(n,r,e){var u=n?n.length:0;if(typeof e=="number")e=0|(0>e?ee(0,u+e):e);else if(e)return e=Ft(n,r),u&&n[e]===r?e:-1;return t(n,r,e)}function Nt(n,t,r){var e=n?n.length:0;if(typeof t!="number"&&null!=t){var o=e,i=0;for(t=u.createCallback(t,r,3);o--&&t(n[o],o,n);)i++}else i=null==t||r?1:t;return i=e-i,Wt(n,0,0>i?0:i)}function St(n,t,r){var e=n?n.length:0;if(typeof t!="number"&&null!=t){var o=e,i=0;for(t=u.createCallback(t,r,3);o--&&t(n[o],o,n);)i++ -}else if(i=t,null==i||r)return n?n[e-1]:b;return i=e-i,Wt(n,0>i?0:i)}function Tt(n,t,r){if(typeof t!="number"&&null!=t){var e=-1,o=n?n.length:0,i=0;for(t=u.createCallback(t,r,3);++et?0:t;return Wt(n,i)}function Wt(n,t,r){var e=-1,u=n?n.length:0;for(typeof t=="undefined"?t=0:0>t?t=ee(u+t,0):t>u&&(t=u),typeof r=="undefined"?r=u:0>r?r=ee(u+r,0):r>u&&(r=u),u=0>(u=r-t|0)?0:u,r=xr(u);++e>>1,r(n[e])r?0:r);++t(e|=0)?0:e,r>=e)return false;if(typeof n=="string"||!we(n)&&cr(n))return Hr?Hr.call(n,t,r):-1r?ee(0,e+r):r,-1=e){var o;return ft(n,function(n,r,e){return t(n,r,e)?(o=n,false):void 0}),o}for(;++ri&&(i=f)}else t=null==t&&cr(n)?e:u.createCallback(t,r,3),ft(n,function(n,r,e){r=t(n,r,e),r>o&&(o=r,i=n) -});return i}function Xt(n,t,r,e){var o=3>arguments.length;t=u.createCallback(t,e,4);var i=-1,a=n?0|n.length:0;if(0arguments.length;return t=u.createCallback(t,e,4),lt(n,function(n,e,u){r=o?(o=false,n):t(r,n,e,u)}),r}function Gt(n){var t=-1,r=n?0|n.length:0,e=xr(0>r?0:r);return ft(n,function(n){var r=dt(0,++t);e[t]=e[r],e[r]=n}),e}function Ht(n,t,r){var e;t=u.createCallback(t,r,3),r=-1; -var o=n?0|n.length:0;if(0arguments.length)return jt(n,_,null,t);if(n)var r=n[A]?n[A][2]:n.length,e=Wt(arguments,2),r=r-e.length;return jt(n,_|j,r,t,e)}function Qt(n,t,r){var e,u,o,i,a,f,l,c=0,p=false,s=true;if(!ir(n))throw new Nr;if(t=0>t?0:t,true===r)var h=true,s=false;else ar(r)&&(h=r.leading,p="maxWait"in r&&(ee(t,r.maxWait)||0),s="trailing"in r?r.trailing:s);var g=function(){var r=t-(Re()-i); -0>=r||r>t?(u&&Br(u),r=l,u=f=l=b,r&&(c=Re(),o=n.apply(a,e),f||u||(e=a=null))):f=Zr(g,r)},v=function(){f&&Br(f),u=f=l=b,(s||p!==t)&&(c=Re(),o=n.apply(a,e),f||u||(e=a=null))};return function(){if(e=arguments,i=Re(),a=this,l=s&&(f||!h),false===p)var r=h&&!f;else{u||h||(c=i);var y=p-(i-c),m=0>=y||y>p;m?(u&&(u=Br(u)),c=i,o=n.apply(a,e)):u||(u=Zr(v,y))}return m&&f?f=Br(f):f||t===p||(f=Zr(g,t)),r&&(m=true,o=n.apply(a,e)),!m||f||u||(e=a=null),o}}function nr(n){if(!ir(n))throw new Nr;return function(){return!n.apply(this,arguments) -}}function tr(n,t,r){if(!n)return n;var e=arguments,u=0,o=e.length,i=typeof r;if("number"!=i&&"string"!=i||!e[3]||e[3][r]!==t||(o=2),3t||null==n)return r;n=Rr(n);do t%2&&(r+=n),t=qr(t/2),n+=n;while(t);return r}function yr(n,t,r){var e=typeof n;return"function"==e||null==n?(typeof t=="undefined"||!("prototype"in n))&&n||q(n,t,r):"object"!=e?wr(n):dr(n)}function mr(n){return n}function dr(n){n||(n={});var t=ke(n),r=t.length,e=t[0],u=n[e];return 1!=r||u!==u||ar(u)?function(e){for(var u=r,o=false;u--&&(o=t[u],o=Kr.call(e,o)&&yt(e[o],n[o],null,true)););return o}:function(n){return Kr.call(n,e)?(n=n[e],u===n&&(0!==u||1/u==1/n)):false -}}function br(n,t,r){var e=true,o=t&&er(t);t&&(r||o.length)||(null==r&&(r=t),t=n,n=u,o=er(t)),false===r?e=false:ar(r)&&"chain"in r&&(e=r.chain),r=-1;for(var i=ir(n),a=o?o.length:0;++r--n?t.apply(this,arguments):void 0 -}},u.assign=tr,u.at=function(n,t){var r=arguments,e=-1,u=ct(r,true,false,1),o=u.length,i=typeof t;for("number"!=i&&"string"!=i||!r[2]||r[2][t]!==n||(o=1),r=xr(o);++earguments.length?jt(t,_|w,null,n):jt(t,_|w|j,null,n,Wt(arguments,2))},u.chain=function(n){return n=new o(n),n.__chain__=true,n -},u.compact=function(n){for(var t=-1,r=n?n.length:0,e=0,u=[];++t(h?r(h,c):a(l,c))){for(u=o,(h||l).push(c);--u;)if(h=i[u],0>(h?r(h,c):a(e[u],c)))continue n;s.push(c)}}return s},u.invert=function(n,t){for(var r=-1,e=ke(n),u=e.length,o={};++ro?0:o); -return ft(n,function(n){i[++e]=(u?t:n[t]).apply(n,r)}),i},u.keys=ke,u.keysIn=pr,u.map=Vt,u.mapValues=function(n,t,r){var e={};return t=u.createCallback(t,r,3),gt(n,function(n,r,u){e[r]=t(n,r,u)}),e},u.matches=dr,u.max=Zt,u.memoize=function(n,t){if(!ir(n))throw new Nr;var r=function(){var e=r.cache,u=t?t.apply(this,arguments):"_"+arguments[0];return Kr.call(e,u)?e[u]:e[u]=n.apply(this,arguments)};return r.cache={},r},u.merge=function(n,t,r){if(!n)return n;var e=arguments,u=e.length,o=typeof r;if("number"!=o&&"string"!=o||!e[3]||e[3][r]!==t||(u=2),3f?0:f); -for(o||(t=u.createCallback(t,r,3)),ft(n,function(n,r,u){if(o)for(r=t.length,u=xr(r);r--;)u[r]=n[t[r]];else u=t(n,r,u);l[++e]={a:u,b:e,c:n}}),f=l.length,l.sort(o?a:i);f--;)l[f]=l[f].c;return l},u.tap=function(n,t,r){return t.call(r,n),n},u.throttle=function(n,t,r){var e=true,u=true;if(!ir(n))throw new Nr;return false===r?e=false:ar(r)&&(e="leading"in r?!!r.leading:e,u="trailing"in r?!!r.trailing:u),ot.leading=e,ot.maxWait=+t,ot.trailing=u,Qt(n,t,ot)},u.times=function(n,t,r){n=-1<(n=+n)?n:0;var e=-1,u=xr(n);for(t=q(t,r,1);++er?ee(0,e+r):ue(r,e-1))+1);e--;)if(n[e]===t)return e;return-1},u.mixin=br,u.noConflict=function(){return n._=$r,this},u.noop=_r,u.now=Re,u.pad=function(n,t,r){n=null==n?"":Rr(n),t|=0; -var e=n.length;return e=n.length)return n;var o=r-e.length;if(1>o)return e;if(r=n.slice(0,o),null==u)return r+e;if(lr(u)){if(n.slice(o).search(u)){var i,a,f=n.slice(0,o);for(u.global||(u=Er(u.source,(L.exec(u)||"")+"g")),u.lastIndex=0;i=u.exec(f);)a=i.index; -r=r.slice(0,null==a?o:a)}}else n.indexOf(u,o)!=o&&(u=r.lastIndexOf(u),-1n.indexOf(";")?n:n.replace(S,m))},u.uniqueId=function(n){var t=++I;return Rr(null==n?"":n)+t},u.all=qt,u.any=Ht,u.detect=Pt,u.findWhere=Pt,u.foldl=Xt,u.foldr=Yt,u.include=Bt,u.inject=Xt,br(function(){var n={};return gt(u,function(t,r){u.prototype[r]||(n[r]=t)}),n}(),false),u.first=Et,u.last=St,u.sample=function(n,t,r){return n&&typeof n.length!="number"&&(n=hr(n)),null==t||r?(t=n?0|n.length:0,0"']/g,W=/<%-([\s\S]+?)%>/g,F=/<%([\s\S]+?)%>/g,$=/<%=([\s\S]+?)%>/g,D=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,L=/\w*$/,z=/^\s*function[ \n\r\t]+\w/,B=/^0[xX]/,q=/[\xC0-\xFF]/g,U=/($^)/,P=/[.*+?^${}()|[\]\\]/g,K=/\bthis\b/,M=/['\n\r\t\u2028\u2029\\]/g,V=/[A-Z]{2,}|[a-zA-Z0-9][a-z0-9]*/g,Z=" \t\x0B\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000",X="Array Boolean Date Function Math Number Object RegExp Set String _ clearTimeout document isFinite isNaN parseInt setTimeout TypeError window WinRTError".split(" "),Y="[object Arguments]",G="[object Array]",H="[object Boolean]",J="[object Date]",Q="[object Function]",nt="[object Number]",tt="[object Object]",rt="[object RegExp]",et="[object String]",ut={}; -ut[Q]=false,ut[Y]=ut[G]=ut[H]=ut[J]=ut[nt]=ut[tt]=ut[rt]=ut[et]=true;var ot={leading:false,maxWait:0,trailing:false},it={configurable:false,enumerable:false,value:null,writable:false},at={"&":"&","<":"<",">":">",'"':""","'":"'"},ft={"&":"&","<":"<",">":">",""":'"',"'":"'"},lt={\u00c0:"A",\u00c1:"A",\u00c2:"A",\u00c3:"A",\u00c4:"A",\u00c5:"A",\u00e0:"a",\u00e1:"a",\u00e2:"a",\u00e3:"a",\u00e4:"a",\u00e5:"a",\u00c7:"C",\u00e7:"c",\u00d0:"D",\u00f0:"d",\u00c8:"E",\u00c9:"E",\u00ca:"E",\u00cb:"E",\u00e8:"e",\u00e9:"e",\u00ea:"e",\u00eb:"e",\u00cc:"I",\u00cd:"I",\u00ce:"I",\u00cf:"I",\u00ec:"i",\u00ed:"i",\u00ee:"i",\u00ef:"i",\u00d1:"N",\u00f1:"n",\u00d2:"O",\u00d3:"O",\u00d4:"O",\u00d5:"O",\u00d6:"O",\u00d8:"O",\u00f2:"o",\u00f3:"o",\u00f4:"o",\u00f5:"o",\u00f6:"o",\u00f8:"o",\u00d9:"U",\u00da:"U",\u00db:"U",\u00dc:"U",\u00f9:"u",\u00fa:"u",\u00fb:"u",\u00fc:"u",\u00dd:"Y",\u00fd:"y",\u00ff:"y",\u00c6:"AE",\u00e6:"ae",\u00de:"Th",\u00fe:"th",\u00df:"ss","\xd7":" ","\xf7":" "},ct={"function":true,object:true},pt={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"},st=ct[typeof window]&&window||this,ht=ct[typeof exports]&&exports&&!exports.nodeType&&exports,ct=ct[typeof module]&&module&&!module.nodeType&&module,gt=ht&&ct&&typeof global=="object"&&global; -!gt||gt.global!==gt&>.window!==gt&>.self!==gt||(st=gt);var gt=ct&&ct.exports===ht&&ht,vt=d();typeof define=="function"&&typeof define.amd=="object"&&define.amd?(st._=vt, define(function(){return vt})):ht&&ct?gt?(ct.exports=vt)._=vt:ht._=vt:st._=vt}).call(this); \ No newline at end of file +;(function(){function n(n,t){return typeof n=="undefined"?t:n}function t(n,t){if(n!==t){if(n>t||typeof n=="undefined")return 1;if(ne||13e||8202r||13r||8202i(t,l)&&f.push(l);return f}function ft(n,t){var r=-1,e=n?n.length:0;if(typeof e=="number"&&-1(r|=0)?0:r;r--&&false!==t(n[r],r,n););else gt(n,t,Ie); +return n}function pt(n,t,r,e){e=(0|e)-1;for(var u=n?n.length:0,o=[];++ea(p,h)&&((u||f)&&p.push(h),c.push(s))}return c}function wt(n,t){for(var r=-1,e=t(n),u=e.length,o=Ar(u);++rr&&(r=0),p&&(i=[]),s&&(a=[]),h=[n,t,r,e,u,o,i,a],t==w||t==(w|C)?c(h):Z(h))}function Ot(){var n=(n=o.indexOf)===Tt?r:n;return n}function At(n){return typeof n=="function"&&Pr.test(Zr.call(n))}function It(n){var t,r;return n&&Ur.call(n)==rt&&(Yr.call(n,"constructor")||(t=n.constructor,!pr(t)||t instanceof t))?(st(n,function(n,t){r=t +},yr),typeof r=="undefined"||Yr.call(n,r)):false}function Et(n){for(var t=-1,r=yr(n),e=r.length,u=[];++ti?0:i)}function Tt(n,t,e){var u=n?n.length:0;if(typeof e=="number")e=0|(0>e?le(0,u+e):e);else if(e)return e=Lt(n,t),u&&n[e]===t?e:-1;return r(n,t,e)}function Wt(n,t,r){var e=n?n.length:0;if(typeof t!="number"&&null!=t){var u=e,i=0;for(t=o.createCallback(t,r,3);u--&&t(n[u],u,n);)i++}else i=null==t||r?1:t;return i=e-i,Dt(n,0,0>i?0:i)}function Ft(n,t,r){var e=n?n.length:0;if(typeof t!="number"&&null!=t){var u=e,i=0;for(t=o.createCallback(t,r,3);u--&&t(n[u],u,n);)i++ +}else if(i=t,null==i||r)return n?n[e-1]:_;return i=e-i,Dt(n,0>i?0:i)}function $t(n,t,r){if(typeof t!="number"&&null!=t){var e=-1,u=n?n.length:0,i=0;for(t=o.createCallback(t,r,3);++et?0:t;return Dt(n,i)}function Dt(n,t,r){var e=-1,u=n?n.length:0;for(t|=0,0>t?t=le(u+t,0):t>u&&(t=u),r=typeof r=="undefined"?u:0|r,0>r?r=le(u+r,0):r>u&&(r=u),u=t>r?0:r-t,r=Ar(u);++e>>1,r(n[e])r?0:r);++tr?le(0,(0|e)+r):r,-1i&&(i=l)}else t=null==t&&vr(n)?u:o.createCallback(t,r,3),ft(n,function(n,r,u){r=t(n,r,u),r>e&&(e=r,i=n)});return i}function Ht(n,t,r,e){var u=3>arguments.length;t=o.createCallback(t,e,4); +var i=-1,a=0|(n&&n.length);if(0arguments.length;return t=o.createCallback(t,e,4),ct(n,function(n,e,o){r=u?(u=false,n):t(r,n,e,o)}),r}function Qt(n){var t=-1,r=0|(n&&n.length),e=Ar(0>r?0:r);return ft(n,function(n){var r=bt(0,++t);e[t]=e[r],e[r]=n}),e}function nr(n,t,r){var e;t=o.createCallback(t,r,3),r=-1;var u=0|(n&&n.length);if(0arguments.length)return Ct(n,w,null,t);if(n)var r=n[I]?n[I][2]:n.length,e=Dt(arguments,2),r=r-e.length;return Ct(n,w|C,r,t,e)}function rr(n,t,r){var e,u,o,i,a,l,f,c=0,p=false,s=true;if(!pr(n))throw new $r;if(t=0>t?0:t,true===r)var h=true,s=false;else sr(r)&&(h=r.leading,p="maxWait"in r&&(le(t,r.maxWait)||0),s="trailing"in r?r.trailing:s);var g=function(){var r=t-(Fe()-i);0>=r||r>t?(u&&Mr(u),r=f,u=l=f=_,r&&(c=Fe(),o=n.apply(a,e),l||u||(e=a=null))):l=Jr(g,r) +},v=function(){l&&Mr(l),u=l=f=_,(s||p!==t)&&(c=Fe(),o=n.apply(a,e),l||u||(e=a=null))};return function(){if(e=arguments,i=Fe(),a=this,f=s&&(l||!h),false===p)var r=h&&!l;else{u||h||(c=i);var y=p-(i-c),m=0>=y||y>p;m?(u&&(u=Mr(u)),c=i,o=n.apply(a,e)):u||(u=Jr(v,y))}return m&&l?l=Mr(l):l||t===p||(l=Jr(g,t)),r&&(m=true,o=n.apply(a,e)),!m||l||u||(e=a=null),o}}function er(n){if(!pr(n))throw new $r;return function(){return!n.apply(this,arguments)}}function ur(n,t,r){if(!n)return n;var e=arguments,u=0,o=e.length,i=typeof r; +if("number"!=i&&"string"!=i||!e[3]||e[3][r]!==t||(o=2),3t||null==n)return r;n=Fr(n);do t%2&&(r+=n),t=Vr(t/2),n+=n;while(t);return r}function wr(n,t,r){var e=typeof n;return"function"==e||null==n?(typeof t=="undefined"||!("prototype"in n))&&n||U(n,t,r):"object"!=e?Or(n):jr(n)}function xr(n){return n}function jr(n){n||(n={});var t=Ie(n),r=t.length,e=t[0],u=n[e];return 1!=r||u!==u||sr(u)?function(e){for(var u=r,o=false;u--&&(o=t[u],o=Yr.call(e,o)&&mt(e[o],n[o],null,true)););return o}:function(n){return Yr.call(n,e)?(n=n[e],u===n&&(0!==u||1/u==1/n)):false +}}function kr(n,t,r){var e=true,u=t&&lr(t);t&&(r||u.length)||(null==r&&(r=t),t=n,n=o,u=lr(t)),false===r?e=false:sr(r)&&"chain"in r&&(e=r.chain),r=-1;for(var i=pr(n),a=u?u.length:0;++r--n?t.apply(this,arguments):void 0 +}},o.assign=ur,o.at=function(n,t){var r=arguments,e=-1,u=pt(r,true,false,1),o=u.length,i=typeof t;for("number"!=i&&"string"!=i||!r[2]||r[2][t]!==n||(o=1),r=Ar(o);++earguments.length?Ct(t,w|x,null,n):Ct(t,w|x|C,null,n,Dt(arguments,2))},o.chain=function(n){return n=new i(n),n.__chain__=true,n +},o.compact=function(n){for(var t=-1,r=n?n.length:0,e=0,u=[];++t(h?e(h,c):a(f,c))){for(u=o,(h||f).push(c);--u;)if(h=i[u],0>(h?e(h,c):a(t[u],c)))continue n;s.push(c)}}return s},o.invert=function(n,t){for(var r=-1,e=Ie(n),u=e.length,o={};++ro?0:o); +return ft(n,function(n){i[++e]=(u?t:n[t]).apply(n,r)}),i},o.keys=Ie,o.keysIn=yr,o.map=Yt,o.mapValues=function(n,t,r){var e={};return t=o.createCallback(t,r,3),vt(n,function(n,r,u){e[r]=t(n,r,u)}),e},o.matches=jr,o.max=Gt,o.memoize=function(n,t){if(!pr(n))throw new $r;var r=function(){var e=r.cache,u=t?t.apply(this,arguments):"_"+arguments[0];return Yr.call(e,u)?e[u]:e[u]=n.apply(this,arguments)};return r.cache={},r},o.merge=function(n,t,r){if(!n)return n;var e=arguments,u=e.length,o=typeof r;if("number"!=o&&"string"!=o||!e[3]||e[3][r]!==t||(u=2),3u?0:u);for(i||(t=o.createCallback(t,r,3)),ft(n,function(n,r,u){if(i)for(r=t.length,u=Ar(r);r--;)u[r]=n[t[r]]; +else u=t(n,r,u);f[++e]={a:u,b:e,c:n}}),u=f.length,f.sort(i?l:a);u--;)f[u]=f[u].c;return f},o.tap=function(n,t,r){return t.call(r,n),n},o.throttle=function(n,t,r){var e=true,u=true;if(!pr(n))throw new $r;return false===r?e=false:sr(r)&&(e="leading"in r?!!r.leading:e,u="trailing"in r?!!r.trailing:u),it.leading=e,it.maxWait=+t,it.trailing=u,rr(n,t,it)},o.times=function(n,t,r){n=-1<(n=+n)?n:0;var e=-1,u=Ar(n);for(t=U(t,r,1);++er?le(0,e+r):fe(r,e-1))+1);e--;)if(n[e]===t)return e; +return-1},o.mixin=kr,o.noConflict=function(){return t._=qr,this},o.noop=Cr,o.now=Fe,o.pad=function(n,t,r){n=null==n?"":Fr(n),t|=0;var e=n.length;return e=n.length)return n;var o=r-e.length;if(1>o)return e;if(r=n.slice(0,o),null==u)return r+e;if(gr(u)){if(n.slice(o).search(u)){var i,a,l=n.slice(0,o);for(u.global||(u=Wr(u.source,(z.exec(u)||"")+"g")),u.lastIndex=0;i=u.exec(l);)a=i.index; +r=r.slice(0,null==a?o:a)}}else n.indexOf(u,o)!=o&&(u=r.lastIndexOf(u),-1n.indexOf(";")?n:n.replace(T,d))},o.uniqueId=function(n){var t=++E;return Fr(null==n?"":n)+t},o.all=Kt,o.any=nr,o.detect=Vt,o.findWhere=Vt,o.foldl=Ht,o.foldr=Jt,o.include=Pt,o.inject=Ht,kr(function(){var n={};return vt(o,function(t,r){o.prototype[r]||(n[r]=t)}),n}(),false),o.first=St,o.last=Ft,o.sample=function(n,t,r){return n&&typeof n.length!="number"&&(n=dr(n)),null==t||r?(t=0|(n&&n.length),0"']/g,F=/<%-([\s\S]+?)%>/g,$=/<%([\s\S]+?)%>/g,D=/<%=([\s\S]+?)%>/g,L=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,z=/\w*$/,B=/^\s*function[ \n\r\t]+\w/,q=/^0[xX]/,U=/[\xC0-\xFF]/g,P=/($^)/,K=/[.*+?^${}()|[\]\\]/g,M=/\bthis\b/,V=/['\n\r\t\u2028\u2029\\]/g,Z=/[A-Z]{2,}|[a-zA-Z0-9][a-z0-9]*/g,X=" \t\x0B\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000",Y="Array Boolean Date Function Math Number Object RegExp Set String _ clearTimeout document isFinite isNaN parseInt setTimeout TypeError window WinRTError".split(" "),G="[object Arguments]",H="[object Array]",J="[object Boolean]",Q="[object Date]",nt="[object Function]",tt="[object Number]",rt="[object Object]",et="[object RegExp]",ut="[object String]",ot={}; +ot[nt]=false,ot[G]=ot[H]=ot[J]=ot[Q]=ot[tt]=ot[rt]=ot[et]=ot[ut]=true;var it={leading:false,maxWait:0,trailing:false},at={configurable:false,enumerable:false,value:null,writable:false},lt={"&":"&","<":"<",">":">",'"':""","'":"'"},ft={"&":"&","<":"<",">":">",""":'"',"'":"'"},ct={\u00c0:"A",\u00c1:"A",\u00c2:"A",\u00c3:"A",\u00c4:"A",\u00c5:"A",\u00e0:"a",\u00e1:"a",\u00e2:"a",\u00e3:"a",\u00e4:"a",\u00e5:"a",\u00c7:"C",\u00e7:"c",\u00d0:"D",\u00f0:"d",\u00c8:"E",\u00c9:"E",\u00ca:"E",\u00cb:"E",\u00e8:"e",\u00e9:"e",\u00ea:"e",\u00eb:"e",\u00cc:"I",\u00cd:"I",\u00ce:"I",\u00cf:"I",\u00ec:"i",\u00ed:"i",\u00ee:"i",\u00ef:"i",\u00d1:"N",\u00f1:"n",\u00d2:"O",\u00d3:"O",\u00d4:"O",\u00d5:"O",\u00d6:"O",\u00d8:"O",\u00f2:"o",\u00f3:"o",\u00f4:"o",\u00f5:"o",\u00f6:"o",\u00f8:"o",\u00d9:"U",\u00da:"U",\u00db:"U",\u00dc:"U",\u00f9:"u",\u00fa:"u",\u00fb:"u",\u00fc:"u",\u00dd:"Y",\u00fd:"y",\u00ff:"y",\u00c6:"AE",\u00e6:"ae",\u00de:"Th",\u00fe:"th",\u00df:"ss","\xd7":" ","\xf7":" "},pt={"function":true,object:true},st={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"},ht=pt[typeof window]&&window||this,gt=pt[typeof exports]&&exports&&!exports.nodeType&&exports,pt=pt[typeof module]&&module&&!module.nodeType&&module,vt=gt&&pt&&typeof global=="object"&&global; +!vt||vt.global!==vt&&vt.window!==vt&&vt.self!==vt||(ht=vt);var vt=pt&&pt.exports===gt&>,yt=b();typeof define=="function"&&typeof define.amd=="object"&&define.amd?(ht._=yt, define(function(){return yt})):gt&&pt?vt?(pt.exports=yt)._=yt:gt._=yt:ht._=yt}).call(this); \ No newline at end of file diff --git a/dist/lodash.underscore.js b/dist/lodash.underscore.js index edb0830ee..1f787bc98 100644 --- a/dist/lodash.underscore.js +++ b/dist/lodash.underscore.js @@ -566,7 +566,7 @@ iterable = collection, length = collection ? collection.length : 0; - if (typeof length == 'number') { + if (typeof length == 'number' && length > -1) { length |= 0; while (++index < length) { if (callback(iterable[index], index, collection) === breakIndicator) { @@ -592,7 +592,7 @@ var iterable = collection, length = collection ? collection.length : 0; - if (typeof length == 'number') { + if (typeof length == 'number' && length > -1) { length = (length |= 0) < 0 ? 0 : length; while (length--) { if (callback(iterable[length], length, collection) === breakIndicator) { @@ -978,7 +978,7 @@ callback = createCallback(callback, thisArg, 3); var index = -1, - length = collection ? collection.length | 0 : 0; + length = (collection && collection.length) | 0; if (length > 0) { while (++index < length) { @@ -1185,6 +1185,60 @@ */ var drop = rest; + /** + * This method is like `_.find` except that it returns the index of the first + * element the predicate returns truthy for, instead of the element itself. + * + * If a property name is provided for `predicate` the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is provided for `predicate` the created "_.where" style callback + * will return `true` for elements that have the properties of the given object, + * else `false`. + * + * @static + * @memberOf _ + * @category Arrays + * @param {Array} array The array to search. + * @param {Function|Object|string} [predicate=identity] The function called + * per iteration. If a property name or object is provided it will be used + * to create a "_.pluck" or "_.where" style callback, respectively. + * @param {*} [thisArg] The `this` binding of `predicate`. + * @returns {number} Returns the index of the found element, else `-1`. + * @example + * + * var characters = [ + * { 'name': 'barney', 'age': 36 }, + * { 'name': 'fred', 'age': 40, 'blocked': true }, + * { 'name': 'pebbles', 'age': 1 } + * ]; + * + * _.findIndex(characters, function(chr) { + * return chr.age < 20; + * }); + * // => 2 + * + * // using "_.where" callback shorthand + * _.findIndex(characters, { 'age': 36 }); + * // => 0 + * + * // using "_.pluck" callback shorthand + * _.findIndex(characters, 'blocked'); + * // => 1 + */ + function findIndex(array, predicate, thisArg) { + var index = -1, + length = array ? array.length : 0; + + predicate = createCallback(predicate, thisArg, 3); + while (++index < length) { + if (predicate(array[index], index, array)) { + return index; + } + } + return -1; + } + /** * Gets the first element of `array`. * @@ -1424,59 +1478,6 @@ return -1; } - /** - * Creates an array of numbers (positive and/or negative) progressing from - * `start` up to but not including `end`. If `start` is less than `stop` a - * zero-length range is created unless a negative `step` is specified. - * - * @static - * @memberOf _ - * @category Arrays - * @param {number} [start=0] The start of the range. - * @param {number} end The end of the range. - * @param {number} [step=1] The value to increment or decrement by. - * @returns {Array} Returns the new array of numbers. - * @example - * - * _.range(4); - * // => [0, 1, 2, 3] - * - * _.range(1, 5); - * // => [1, 2, 3, 4] - * - * _.range(0, 20, 5); - * // => [0, 5, 10, 15] - * - * _.range(0, -4, -1); - * // => [0, -1, -2, -3] - * - * _.range(1, 4, 0); - * // => [1, 1, 1] - * - * _.range(0); - * // => [] - */ - function range(start, end, step) { - start = +start || 0; - step = (+step || 1); - - if (end == null) { - end = start; - start = 0; - } - // use `Array(length)` so engines like Chakra and V8 avoid slower modes - // http://youtu.be/XAqIpGU8ZZk#t=17m25s - var index = -1, - length = nativeMax(0, ceil((end - start) / step)), - result = Array(length); - - while (++index < length) { - result[index] = start; - start += step; - } - return result; - } - /** * Gets all but the first element of `array`. * @@ -1518,21 +1519,19 @@ var index = -1, length = array ? array.length : 0; - if (typeof start == 'undefined') { - start = 0; - } else if (start < 0) { + start |= 0; + if (start < 0) { start = nativeMax(length + start, 0); } else if (start > length) { start = length; } - if (typeof end == 'undefined') { - end = length; - } else if (end < 0) { + end = typeof end == 'undefined' ? length : (end | 0); + if (end < 0) { end = nativeMax(length + end, 0); } else if (end > length) { end = length; } - length = (length = (end - start) | 0) < 0 ? 0 : length; + length = start > end ? 0 : (end - start); var result = Array(length); while (++index < length) { @@ -1944,7 +1943,7 @@ */ function contains(collection, target) { var indexOf = getIndexOf(), - length = collection ? collection.length | 0 : 0, + length = (collection && collection.length) | 0, result = false; if (length > 0) { @@ -2040,7 +2039,7 @@ predicate = createCallback(predicate, thisArg, 3); var index = -1, - length = collection ? collection.length | 0 : 0; + length = (collection && collection.length) | 0; if (length > 0) { while (++index < length) { @@ -2101,7 +2100,7 @@ predicate = createCallback(predicate, thisArg, 3); var index = -1, - length = collection ? collection.length | 0 : 0; + length = (collection && collection.length) | 0; if (length > 0) { while (++index < length) { @@ -2164,27 +2163,13 @@ * // => { 'name': 'fred', 'age': 40, 'blocked': true } */ function find(collection, predicate, thisArg) { - predicate = createCallback(predicate, thisArg, 3); - var index = -1, - length = collection ? collection.length | 0 : 0; - + var length = (collection && collection.length) | 0; if (length > 0) { - while (++index < length) { - var value = collection[index]; - if (predicate(value, index, collection)) { - return value; - } - } - } else { - var result; - baseEach(collection, function(value, index, collection) { - if (predicate(value, index, collection)) { - result = value; - return breakIndicator; - } - }); - return result; + var index = findIndex(collection, predicate, thisArg); + return index > -1 ? collection[index] : undefined; } + var key = findKey(collection, predicate, thisArg); + return typeof key == 'string' ? collection[key] : undefined; } /** @@ -2215,7 +2200,7 @@ */ function forEach(collection, callback, thisArg) { var index = -1, - length = collection ? collection.length | 0 : 0; + length = (collection && collection.length) | 0; callback = callback && typeof thisArg == 'undefined' ? callback : baseCreateCallback(callback, thisArg, 3); if (length > 0) { @@ -2342,7 +2327,7 @@ var args = slice(arguments, 2), index = -1, isFunc = typeof methodName == 'function', - length = collection ? collection.length | 0 : 0, + length = (collection && collection.length) | 0, result = Array(length < 0 ? 0 : length); baseEach(collection, function(value) { @@ -2392,7 +2377,7 @@ */ function map(collection, callback, thisArg) { var index = -1, - length = collection ? collection.length | 0 : 0; + length = (collection && collection.length) | 0; callback = createCallback(callback, thisArg, 3); if (length > 0) { @@ -2459,7 +2444,7 @@ callback = null; } var index = -1, - length = collection ? collection.length | 0 : 0; + length = (collection && collection.length) | 0; if (callback == null && length > 0) { while (++index < length) { @@ -2532,7 +2517,7 @@ callback = null; } var index = -1, - length = collection ? collection.length | 0 : 0; + length = (collection && collection.length) | 0; if (callback == null && length > 0) { while (++index < length) { @@ -2660,7 +2645,7 @@ callback = createCallback(callback, thisArg, 4); var index = -1, - length = collection ? collection.length | 0 : 0; + length = (collection && collection.length) | 0; if (length > 0) { if (noaccum && length) { @@ -2776,7 +2761,7 @@ collection = values(collection); } if (n == null || guard) { - var length = collection ? collection.length | 0 : 0; + var length = (collection && collection.length) | 0; return length > 0 ? collection[baseRandom(0, length - 1)] : undefined; } var result = shuffle(collection); @@ -2801,7 +2786,7 @@ */ function shuffle(collection) { var index = -1, - length = collection ? collection.length | 0 : 0, + length = (collection && collection.length) | 0, result = Array(length < 0 ? 0 : length); baseEach(collection, function(value) { @@ -2885,7 +2870,7 @@ predicate = createCallback(predicate, thisArg, 3); var index = -1, - length = collection ? collection.length | 0 : 0; + length = (collection && collection.length) | 0; if (length > 0) { while (++index < length) { @@ -2952,7 +2937,7 @@ */ function sortBy(collection, callback, thisArg) { var index = -1, - length = collection ? collection.length | 0 : 0, + length = (collection && collection.length) | 0, result = Array(length < 0 ? 0 : length); callback = createCallback(callback, thisArg, 3); @@ -3721,6 +3706,60 @@ return object; } + /** + * This method is like `_.findIndex` except that it returns the key of the + * first element the predicate returns truthy for, instead of the element itself. + * + * If a property name is provided for `predicate` the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is provided for `predicate` the created "_.where" style callback + * will return `true` for elements that have the properties of the given object, + * else `false`. + * + * @static + * @memberOf _ + * @category Objects + * @param {Object} object The object to search. + * @param {Function|Object|string} [predicate=identity] The function called + * per iteration. If a property name or object is provided it will be used + * to create a "_.pluck" or "_.where" style callback, respectively. + * @param {*} [thisArg] The `this` binding of `predicate`. + * @returns {string|undefined} Returns the key of the found element, else `undefined`. + * @example + * + * var characters = { + * 'barney': { 'age': 36 }, + * 'fred': { 'age': 40, 'blocked': true }, + * 'pebbles': { 'age': 1 } + * }; + * + * _.findKey(characters, function(chr) { + * return chr.age < 40; + * }); + * // => 'barney' (property order is not guaranteed across environments) + * + * // using "_.where" callback shorthand + * _.findKey(characters, { 'age': 1 }); + * // => 'pebbles' + * + * // using "_.pluck" callback shorthand + * _.findKey(characters, 'blocked'); + * // => 'fred' + */ + function findKey(object, predicate, thisArg) { + var result; + + predicate = createCallback(predicate, thisArg, 3); + baseForOwn(object, function(value, key, object) { + if (predicate(value, key, object)) { + result = key; + return breakIndicator; + } + }); + return result; + } + /** * Creates a sorted array of property names of all enumerable properties, * own and inherited, of `object` that have function values. @@ -3814,7 +3853,7 @@ * @returns {boolean} Returns `true` if the `value` is an `arguments` object, else `false`. * @example * - * (function() { return _.isArguments(arguments); })(1, 2, 3); + * (function() { return _.isArguments(arguments); })(); * // => true * * _.isArguments([1, 2, 3]); @@ -3843,11 +3882,11 @@ * @returns {boolean} Returns `true` if the `value` is an array, else `false`. * @example * - * (function() { return _.isArray(arguments); })(); - * // => false - * * _.isArray([1, 2, 3]); * // => true + * + * (function() { return _.isArray(arguments); })(); + * // => false */ var isArray = nativeIsArray || function(value) { return value && typeof value == 'object' && typeof value.length == 'number' && @@ -3864,6 +3903,9 @@ * @returns {boolean} Returns `true` if the `value` is a boolean value, else `false`. * @example * + * _.isBoolean(false); + * // => true + * * _.isBoolean(null); * // => false */ @@ -3884,6 +3926,9 @@ * * _.isDate(new Date); * // => true + * + * _.isDate('Wed May 23 2012'); + * // => false */ function isDate(value) { return value && typeof value == 'object' && toString.call(value) == dateClass || false; @@ -3901,6 +3946,9 @@ * * _.isElement(document.body); * // => true + * + * _.isElement(''); + * // => false */ function isElement(value) { return value && value.nodeType === 1 || false; @@ -3918,14 +3966,20 @@ * @returns {boolean} Returns `true` if the `value` is empty, else `false`. * @example * + * _.isEmpty(null); + * // => true + * + * _.isEmpty(true); + * // => true + * + * _.isEmpty(1); + * // => true + * * _.isEmpty([1, 2, 3]); * // => false * - * _.isEmpty({}); - * // => true - * - * _.isEmpty(''); - * // => true + * _.isEmpty({ 'a': 1 }); + * // => false */ function isEmpty(value) { if (!value) { @@ -4029,6 +4083,9 @@ * * _.isFunction(_); * // => true + * + * _.isFunction(/abc/); + * // => false */ function isFunction(value) { return typeof value == 'function'; @@ -4114,7 +4171,7 @@ * _.isNull(null); * // => true * - * _.isNull(undefined); + * _.isNull(void 0); * // => false */ function isNull(value) { @@ -4134,8 +4191,14 @@ * @returns {boolean} Returns `true` if the `value` is a number, else `false`. * @example * - * _.isNumber(8.4 * 5); + * _.isNumber(8.4); * // => true + * + * _.isNumber(NaN); + * // => true + * + * _.isNumber('8.4'); + * // => false */ function isNumber(value) { var type = typeof value; @@ -4153,8 +4216,11 @@ * @returns {boolean} Returns `true` if the `value` is a regular expression, else `false`. * @example * - * _.isRegExp(/fred/); + * _.isRegExp(/abc/); * // => true + * + * _.isRegExp('/abc/'); + * // => false */ function isRegExp(value) { var type = typeof value; @@ -4172,8 +4238,11 @@ * @returns {boolean} Returns `true` if the `value` is a string, else `false`. * @example * - * _.isString('fred'); + * _.isString('abc'); * // => true + * + * _.isString(1); + * // => false */ function isString(value) { return typeof value == 'string' || @@ -4192,6 +4261,9 @@ * * _.isUndefined(void 0); * // => true + * + * _.isUndefined(null); + * // => false */ function isUndefined(value) { return typeof value == 'undefined'; @@ -4889,16 +4961,71 @@ if (min == null && max == null) { max = 1; } - min = +min || 0; + min |= 0; if (max == null) { max = min; min = 0; } else { - max = +max || 0; + max |= 0; } return min + floor(nativeRandom() * (max - min + 1)); } + /** + * Creates an array of numbers (positive and/or negative) progressing from + * `start` up to but not including `end`. If `start` is less than `stop` a + * zero-length range is created unless a negative `step` is specified. + * + * @static + * @memberOf _ + * @category Utilities + * @param {number} [start=0] The start of the range. + * @param {number} end The end of the range. + * @param {number} [step=1] The value to increment or decrement by. + * @returns {Array} Returns the new array of numbers. + * @example + * + * _.range(4); + * // => [0, 1, 2, 3] + * + * _.range(1, 5); + * // => [1, 2, 3, 4] + * + * _.range(0, 20, 5); + * // => [0, 5, 10, 15] + * + * _.range(0, -4, -1); + * // => [0, -1, -2, -3] + * + * _.range(1, 4, 0); + * // => [1, 1, 1] + * + * _.range(0); + * // => [] + */ + function range(start, end, step) { + start = +start || 0; + step = step == null ? 1 : (+step || 0); + + if (end == null) { + end = start; + start = 0; + } else { + end = +end || 0; + } + // use `Array(length)` so engines like Chakra and V8 avoid slower modes + // http://youtu.be/XAqIpGU8ZZk#t=17m25s + var index = -1, + length = nativeMax(0, ceil((end - start) / step)), + result = Array(length); + + while (++index < length) { + result[index] = start; + start += step; + } + return result; + } + /** * Resolves the value of property `key` on `object`. If `key` is a function * it will be invoked with the `this` binding of `object` and its result diff --git a/dist/lodash.underscore.min.js b/dist/lodash.underscore.min.js index 01b0a3855..a9d323a29 100644 --- a/dist/lodash.underscore.min.js +++ b/dist/lodash.underscore.min.js @@ -4,36 +4,37 @@ * Build: `lodash underscore -o ./dist/lodash.underscore.js` */ ;(function(){function n(n,r,t){t=(0|t)-1;for(var e=n?n.length:0;++te||typeof t=="undefined"){t=1;break n}if(tu(r,i)&&o.push(i)}return o}function p(n,r){var t=-1,e=n?n.length:0;if(typeof e=="number")for(e|=0;++t(t|=0)?0:t;t--&&r(n[t],t,n)!==ar;);else for(var t=at(n),e=t.length;e--;){var u=t[e]; -if(r(n[u],u,n)===ar)break}}function g(n,r,t,e){e=(0|e)-1;for(var u=n?n.length:0,o=[];++eo(f,c)&&(t&&f.push(c),i.push(a))}return i}function _(n,r){return function(t,e,u){var o=r?[[],[]]:{}; -e=nr(e,u,3),u=-1;var i=t?0|t.length:0;if(0r?0:r)}function A(r,t,e){var u=r?r.length:0;if(typeof e=="number")e=0|(0>e?Lr(0,u+e):e);else if(e)return e=O(r,t),u&&r[e]===t?e:-1;return n(r,t,e)}function T(n,r,t){return E(n,null==r||t?1:0>r?0:r)}function E(n,r,t){var e=-1,u=n?n.length:0;for(typeof r=="undefined"?r=0:0>r?r=Lr(u+r,0):r>u&&(r=u),typeof t=="undefined"?t=u:0>t?t=Lr(u+t,0):t>u&&(t=u),u=0>(u=t-r|0)?0:u,t=Array(u);++e>>1,t(n[e])=e){var u;return p(n,function(n,t,e){return r(n,t,e)?(u=n,ar):void 0}),u}for(;++tu&&(u=t);else r=nr(r,t,3),p(n,function(n,t,o){t=r(n,t,o),t>e&&(e=t,u=n)});return u}function I(n,r,t,e){var u=3>arguments.length;r=nr(r,e,4);var o=-1,i=n?0|n.length:0;if(0arguments.length;return r=nr(r,e,4),s(n,function(n,e,o){t=u?(u=false,n):r(t,n,e,o)}),t}function D(n){var r=-1,t=n?0|n.length:0,e=Array(0>t?0:t);return p(n,function(n){var t;t=++r,t=0+Dr(Yr()*(t-0+1)),e[r]=e[t],e[t]=n}),e}function W(n,r,t){var e;r=nr(r,t,3),t=-1;var u=n?0|n.length:0;if(0arguments.length?d(n,ir,r):d(n,ir|fr,r,E(arguments,2)) -}function C(n,r,t){function e(){l&&clearTimeout(l),i=l=p=or,(h||g!==r)&&(s=ct(),f=n.apply(c,o),l||i||(o=c=null))}function u(){var t=r-(ct()-a);0>=t||t>r?(i&&clearTimeout(i),t=p,i=l=p=or,t&&(s=ct(),f=n.apply(c,o),l||i||(o=c=null))):l=setTimeout(u,t)}var o,i,f,a,c,l,p,s=0,g=false,h=true;if(!J(n))throw new TypeError;if(r=0>r?0:r,true===t)var v=true,h=false;else K(t)&&(v=t.leading,g="maxWait"in t&&(Lr(r,t.maxWait)||0),h="trailing"in t?t.trailing:h);return function(){if(o=arguments,a=ct(),c=this,p=h&&(l||!v),false===g)var t=v&&!l; -else{i||v||(s=a);var y=g-(a-s),m=0>=y||y>g;m?(i&&(i=clearTimeout(i)),s=a,f=n.apply(c,o)):i||(i=setTimeout(e,y))}return m&&l?l=clearTimeout(l):l||r===g||(l=setTimeout(u,r)),t&&(m=true,f=n.apply(c,o)),!m||l||i||(o=c=null),f}}function P(n){if(!J(n))throw new TypeError;return function(){return!n.apply(this,arguments)}}function U(n,r,t){if(!n)return n;var e=arguments,u=0,o=e.length,i=typeof t;for("number"!=i&&"string"!=i||!e[3]||e[3][t]!==r||(o=2);++u"']/g,sr=/($^)/,gr=/[.*+?^${}()|[\]\\]/g,hr=/['\n\r\t\u2028\u2029\\]/g,vr="[object Arguments]",yr="[object Array]",mr="[object Boolean]",_r="[object Date]",dr="[object Number]",br="[object Object]",wr="[object RegExp]",jr="[object String]",xr={"&":"&","<":"<",">":">",'"':""","'":"'"},Ar={"&":"&","<":"<",">":">",""":'"',"'":"'"},Tr={"function":true,object:true},Er={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"},Or=Tr[typeof window]&&window||this,Sr=Tr[typeof exports]&&exports&&!exports.nodeType&&exports,kr=Tr[typeof module]&&module&&!module.nodeType&&module,Nr=Sr&&kr&&typeof global=="object"&&global; -!Nr||Nr.global!==Nr&&Nr.window!==Nr&&Nr.self!==Nr||(Or=Nr);var qr=kr&&kr.exports===Sr&&Sr,Fr=Array.prototype,Br=Object.prototype,Rr=Or._,$r=Br.toString,Ir=RegExp("^"+(null==$r?"":($r+"").replace(gr,"\\$&")).replace(/toString|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Mr=Math.ceil,Dr=Math.floor,Wr=Function.prototype.toString,zr=Br.hasOwnProperty,Cr=Fr.push,Pr=Br.propertyIsEnumerable,Ur=Fr.splice,Vr=w(Vr=Object.create)&&Vr,Gr=w(Gr=Array.isArray)&&Gr,Hr=Or.isFinite,Jr=Or.isNaN,Kr=w(Kr=Object.keys)&&Kr,Lr=Math.max,Qr=Math.min,Xr=w(Xr=Date.now)&&Xr,Yr=Math.random; -i.prototype=o.prototype;var Zr={};!function(){var n={0:1,length:1};Zr.spliceObjects=(Ur.call(n,0,1),!n[0])}(1),o.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,variable:""},Vr||(f=function(){function n(){}return function(r){if(K(r)){n.prototype=r;var t=new n;n.prototype=null}return t||Or.Object()}}());var nt=T,rt=_(function(n,r,t){zr.call(n,t)?n[t]++:n[t]=1}),tt=_(function(n,r,t){zr.call(n,t)?n[t].push(r):n[t]=[r]}),et=_(function(n,r,t){n[t]=r -}),ut=_(function(n,r,t){n[t?0:1].push(r)},true),ot=R,it=q;H(arguments)||(H=function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&zr.call(n,"callee")&&!Pr.call(n,"callee")||false});var ft=Gr||function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&$r.call(n)==yr||false};J(/x/)&&(J=function(n){return typeof n=="function"&&"[object Function]"==$r.call(n)});var at=Kr?function(n){return K(n)?Kr(n):[]}:j,ct=Xr||function(){return(new Date).getTime()};o.after=function(n,r){if(!J(r))throw new TypeError; -return function(){return 1>--n?r.apply(this,arguments):void 0}},o.bind=z,o.bindAll=function(n){for(var r=1r?0:r)},o.intersection=function(){for(var n=[],r=-1,t=arguments.length;++ri(a,e)){for(r=t;--r;)if(0>i(n[r],e))continue n;a.push(e)}return a},o.invert=function(n){for(var r=-1,t=at(n),e=t.length,u={};++ro?0:o); -return p(n,function(n){i[++e]=(u?r:n[r]).apply(n,t)}),i},o.keys=at,o.map=R,o.matches=tr,o.max=$,o.memoize=function(n,r){var t={};return function(){var e=r?r.apply(this,arguments):"_"+arguments[0];return zr.call(t,e)?t[e]:t[e]=n.apply(this,arguments)}},o.min=function(n,r,t){var e=1/0,u=e,o=typeof r;"number"!=o&&"string"!=o||!t||t[r]!==n||(r=null);var o=-1,i=n?0|n.length:0;if(null==r&&0o?0:o);for(t=nr(t,e,3),p(n,function(n,r,e){i[++u]={a:t(n,r,e),b:u,c:n}}),o=i.length,i.sort(r);o--;)i[o]=i[o].c;return i},o.tap=function(n,r){return r(n),n},o.throttle=function(n,r,t){var e=true,u=true;if(!J(n))throw new TypeError;return false===t?e=false:K(t)&&(e="leading"in t?t.leading:e,u="trailing"in t?t.trailing:u),C(n,r,{leading:e,maxWait:r,trailing:u})},o.times=function(n,r,t){n=-1<(n=+n)?n:0;var e=-1,u=Array(n);for(r=a(r,t,1);++er?0:r);++nt?Lr(0,e+t):Qr(t,e-1))+1);e--;)if(n[e]===r)return e;return-1},o.mixin=er,o.noConflict=function(){return Or._=Rr,this},o.now=ct,o.random=function(n,r){return null==n&&null==r&&(r=1),n=+n||0,null==r?(r=n,n=0):r=+r||0,n+Dr(Yr()*(r-n+1))},o.reduce=I,o.reduceRight=M,o.result=function(n,r){if(null!=n){var t=n[r];return J(t)?n[r]():t}},o.size=function(n){var r=n?n.length:0;return typeof r=="number"&&-1n.indexOf(";")?n:n.replace(lr,u))},o.uniqueId=function(n){var r=++cr+"";return n?n+r:r},o.all=N,o.any=W,o.detect=F,o.findWhere=F,o.foldl=I,o.foldr=M,o.include=k,o.inject=I,o.first=x,o.last=function(n,r,t){var e=n?n.length:0;return null==r||t?n?n[e-1]:or:(r=e-r,E(n,0>r?0:r))},o.sample=function(n,r,t){return n&&typeof n.length!="number"&&(n=Z(n)),null==r||t?(r=n?0|n.length:0,0u(r,i)&&o.push(i)}return o}function p(n,r){var t=-1,e=n?n.length:0;if(typeof e=="number"&&-1(t|=0)?0:t;t--&&r(n[t],t,n)!==ar;);else for(var t=at(n),e=t.length;e--;){var u=t[e]; +if(r(n[u],u,n)===ar)break}return n}function g(n,r,t,e){e=(0|e)-1;for(var u=n?n.length:0,o=[];++eo(f,c)&&(t&&f.push(c),i.push(a))}return i}function m(n,r){return function(t,e,u){var o=r?[[],[]]:{}; +e=nr(e,u,3),u=-1;var i=0|(t&&t.length);if(0r?0:r)}function x(r,t,e){var u=r?r.length:0;if(typeof e=="number")e=0|(0>e?Lr(0,u+e):e);else if(e)return e=E(r,t),u&&r[e]===t?e:-1;return n(r,t,e)}function A(n,r,t){return T(n,null==r||t?1:0>r?0:r)}function T(n,r,t){var e=-1,u=n?n.length:0;for(r|=0,0>r?r=Lr(u+r,0):r>u&&(r=u),t=typeof t=="undefined"?u:0|t,0>t?t=Lr(u+t,0):t>u&&(t=u),u=r>t?0:t-r,t=Array(u);++e>>1,t(n[e])u&&(u=t);else r=nr(r,t,3),p(n,function(n,t,o){t=r(n,t,o),t>e&&(e=t,u=n)});return u}function $(n,r,t,e){var u=3>arguments.length;r=nr(r,e,4);var o=-1,i=0|(n&&n.length);if(0arguments.length;return r=nr(r,e,4),s(n,function(n,e,o){t=u?(u=false,n):r(t,n,e,o)}),t}function M(n){var r=-1,t=0|(n&&n.length),e=Array(0>t?0:t);return p(n,function(n){var t;t=++r,t=0+Dr(Yr()*(t-0+1)),e[r]=e[t],e[t]=n}),e}function D(n,r,t){var e;r=nr(r,t,3),t=-1;var u=0|(n&&n.length);if(0arguments.length?_(n,ir,null,r):_(n,ir|fr,null,r,T(arguments,2)) +}function z(n,r,t){var e,u,o,i,f,a,c,l=0,p=false,s=true;if(!J(n))throw new TypeError;if(r=0>r?0:r,true===t)var g=true,s=false;else K(t)&&(g=t.leading,p="maxWait"in t&&(Lr(r,t.maxWait)||0),s="trailing"in t?t.trailing:s);var h=function(){var t=r-(ct()-i);0>=t||t>r?(u&&clearTimeout(u),t=c,u=a=c=or,t&&(l=ct(),o=n.apply(f,e),a||u||(e=f=null))):a=setTimeout(h,t)},v=function(){a&&clearTimeout(a),u=a=c=or,(s||p!==r)&&(l=ct(),o=n.apply(f,e),a||u||(e=f=null))};return function(){if(e=arguments,i=ct(),f=this,c=s&&(a||!g),false===p)var t=g&&!a; +else{u||g||(l=i);var y=p-(i-l),m=0>=y||y>p;m?(u&&(u=clearTimeout(u)),l=i,o=n.apply(f,e)):u||(u=setTimeout(v,y))}return m&&a?a=clearTimeout(a):a||r===p||(a=setTimeout(h,r)),t&&(m=true,o=n.apply(f,e)),!m||a||u||(e=f=null),o}}function C(n){if(!J(n))throw new TypeError;return function(){return!n.apply(this,arguments)}}function P(n,r,t){if(!n)return n;var e=arguments,u=0,o=e.length,i=typeof t;for("number"!=i&&"string"!=i||!e[3]||e[3][t]!==r||(o=2);++u"']/g,sr=/($^)/,gr=/[.*+?^${}()|[\]\\]/g,hr=/['\n\r\t\u2028\u2029\\]/g,vr="[object Arguments]",yr="[object Array]",mr="[object Boolean]",_r="[object Date]",dr="[object Number]",br="[object Object]",wr="[object RegExp]",jr="[object String]",xr={"&":"&","<":"<",">":">",'"':""","'":"'"},Ar={"&":"&","<":"<",">":">",""":'"',"'":"'"},Tr={"function":true,object:true},Er={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"},Or=Tr[typeof window]&&window||this,Sr=Tr[typeof exports]&&exports&&!exports.nodeType&&exports,kr=Tr[typeof module]&&module&&!module.nodeType&&module,Nr=Sr&&kr&&typeof global=="object"&&global; +!Nr||Nr.global!==Nr&&Nr.window!==Nr&&Nr.self!==Nr||(Or=Nr);var qr=kr&&kr.exports===Sr&&Sr,Fr=Array.prototype,Br=Object.prototype,Rr=Or._,$r=Br.toString,Ir=RegExp("^"+(null==$r?"":($r+"").replace(gr,"\\$&")).replace(/toString|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Mr=Math.ceil,Dr=Math.floor,Wr=Function.prototype.toString,zr=Br.hasOwnProperty,Cr=Fr.push,Pr=Br.propertyIsEnumerable,Ur=Fr.splice,Vr=b(Vr=Object.create)&&Vr,Gr=b(Gr=Array.isArray)&&Gr,Hr=Or.isFinite,Jr=Or.isNaN,Kr=b(Kr=Object.keys)&&Kr,Lr=Math.max,Qr=Math.min,Xr=b(Xr=Date.now)&&Xr,Yr=Math.random; +i.prototype=o.prototype;var Zr={};!function(){var n={0:1,length:1};Zr.spliceObjects=(Ur.call(n,0,1),!n[0])}(1),o.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,variable:""},Vr||(f=function(){function n(){}return function(r){if(K(r)){n.prototype=r;var t=new n;n.prototype=null}return t||Or.Object()}}());var nt=A,rt=m(function(n,r,t){zr.call(n,t)?n[t]++:n[t]=1}),tt=m(function(n,r,t){zr.call(n,t)?n[t].push(r):n[t]=[r]}),et=m(function(n,r,t){n[t]=r +}),ut=m(function(n,r,t){n[t?0:1].push(r)},true),ot=B,it=N;H(arguments)||(H=function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&zr.call(n,"callee")&&!Pr.call(n,"callee")||false});var ft=Gr||function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&$r.call(n)==yr||false};J(/x/)&&(J=function(n){return typeof n=="function"&&"[object Function]"==$r.call(n)});var at=Kr?function(n){return K(n)?Kr(n):[]}:w,ct=Xr||function(){return(new Date).getTime()};o.after=function(n,r){if(!J(r))throw new TypeError; +return function(){return 1>--n?r.apply(this,arguments):void 0}},o.bind=W,o.bindAll=function(n){for(var r=1r?0:r)},o.intersection=function(){for(var n=[],r=-1,t=arguments.length;++ri(a,e)){for(r=t;--r;)if(0>i(n[r],e))continue n;a.push(e)}return a},o.invert=function(n){for(var r=-1,t=at(n),e=t.length,u={};++ro?0:o); +return p(n,function(n){i[++e]=(u?r:n[r]).apply(n,t)}),i},o.keys=at,o.map=B,o.matches=tr,o.max=R,o.memoize=function(n,r){var t={};return function(){var e=r?r.apply(this,arguments):"_"+arguments[0];return zr.call(t,e)?t[e]:t[e]=n.apply(this,arguments)}},o.min=function(n,r,t){var e=1/0,u=e,o=typeof r;"number"!=o&&"string"!=o||!t||t[r]!==n||(r=null);var o=-1,i=0|(n&&n.length);if(null==r&&0o?0:o);for(t=nr(t,e,3),p(n,function(n,r,e){i[++u]={a:t(n,r,e),b:u,c:n}}),o=i.length,i.sort(r);o--;)i[o]=i[o].c;return i},o.tap=function(n,r){return r(n),n},o.throttle=function(n,r,t){var e=true,u=true;if(!J(n))throw new TypeError;return false===t?e=false:K(t)&&(e="leading"in t?t.leading:e,u="trailing"in t?t.trailing:u),z(n,r,{leading:e,maxWait:r,trailing:u})},o.times=function(n,r,t){n=-1<(n=+n)?n:0; +var e=-1,u=Array(n);for(r=a(r,t,1);++er?0:r);++nt?Lr(0,e+t):Qr(t,e-1))+1);e--;)if(n[e]===r)return e;return-1},o.mixin=er,o.noConflict=function(){return Or._=Rr,this},o.now=ct,o.random=function(n,r){return null==n&&null==r&&(r=1),n|=0,null==r?(r=n,n=0):r|=0,n+Dr(Yr()*(r-n+1))},o.reduce=$,o.reduceRight=I,o.result=function(n,r){if(null!=n){var t=n[r];return J(t)?n[r]():t}},o.size=function(n){var r=n?n.length:0;return typeof r=="number"&&-1n.indexOf(";")?n:n.replace(lr,u))},o.uniqueId=function(n){var r=++cr+"";return n?n+r:r},o.all=k,o.any=D,o.detect=q,o.findWhere=q,o.foldl=$,o.foldr=I,o.include=S,o.inject=$,o.first=j,o.last=function(n,r,t){var e=n?n.length:0;return null==r||t?n?n[e-1]:or:(r=e-r,T(n,0>r?0:r))},o.sample=function(n,r,t){return n&&typeof n.length!="number"&&(n=Z(n)),null==r||t?(r=0|(n&&n.length),0