From 7ad81390f63e9b3ef74a2013ec4e4daa76a11749 Mon Sep 17 00:00:00 2001 From: Spencer Alger Date: Mon, 11 Nov 2013 14:47:47 -0700 Subject: [PATCH 1/3] updated dep list, added versions, and checked that the tests run well against the latest 1.0 beta and 0.90 --- Gruntfile.js | 21 +- dist/elasticsearch.angular.js | 1328 ++++++++------- dist/elasticsearch.angular.min.js | 6 +- dist/elasticsearch.js | 1328 ++++++++------- dist/elasticsearch.min.js | 6 +- package.json | 44 +- src/lib/connectors/http.js | 13 +- src/lib/log.js | 5 + test/browser_integration/yaml_tests.js | 2072 ++++++++++++------------ 9 files changed, 2641 insertions(+), 2182 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 5aebed23d..3f34c27ba 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -158,24 +158,12 @@ module.exports = function (grunt) { } } } - }, - mocha: { - yaml_suite: { - options: { - // log: true, - run: true, - urls: [ 'http://localhost:8888' ], - timeout: 10e3, - '--web-security': false - } - } } }); // load plugins grunt.loadNpmTasks('grunt-run'); grunt.loadNpmTasks('grunt-open'); - grunt.loadNpmTasks('grunt-mocha'); grunt.loadNpmTasks('grunt-browserify'); grunt.loadNpmTasks('grunt-mocha-test'); grunt.loadNpmTasks('grunt-contrib-clean'); @@ -190,9 +178,7 @@ module.exports = function (grunt) { 'jshint', 'mochaTest:unit', 'build', - 'mochaTest:yaml_suite', - // 'start:integration_server', - // 'mocha:yaml_suite' -- this will fail because of the way that PhantomJS handle's DELETE requests with body's + 'mochaTest:yaml_suite' ]); grunt.registerTask('build', [ @@ -227,6 +213,11 @@ module.exports = function (grunt) { var taskData = this.data; + /** + * You must always run the build task first, to ensure that the lastest API and yaml tests are available. + * This is run in the default and browser_tests:{{browser}} tests. + */ + grunt.task.requires('build'); grunt.task.requires('run:integration_server'); grunt.config.set('open.yaml_suite_' + this.target, { diff --git a/dist/elasticsearch.angular.js b/dist/elasticsearch.angular.js index abc39cbb2..c43ca257d 100644 --- a/dist/elasticsearch.angular.js +++ b/dist/elasticsearch.angular.js @@ -3839,7 +3839,7 @@ process.chdir = function (dir) { },{}],13:[function(require,module,exports){ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {};/** * @license - * Lo-Dash 2.2.1 (Custom Build) + * Lo-Dash 2.3.0 (Custom Build) * Build: `lodash modern -o ./dist/lodash.js` * Copyright 2012-2013 The Dojo Foundation * Based on Underscore.js 1.5.2 @@ -3894,7 +3894,7 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? var reFlags = /\w*$/; /** Used to detected named functions */ - var reFuncName = /^function[ \n\r\t]+\w/; + var reFuncName = /^\s*function[ \n\r\t]+\w/; /** Used to match "interpolate" template delimiters */ var reInterpolate = /<%=([\s\S]+?)%>/g; @@ -4192,15 +4192,6 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? }; } - /** - * A no-operation function. - * - * @private - */ - function noop() { - // no operation performed - } - /** * Releases the given array back to the array pool. * @@ -4303,11 +4294,14 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? /** Used to restore the original `_` reference in `noConflict` */ var oldDash = context._; + /** Used to resolve the internal [[Class]] of values */ + var toString = objectProto.toString; + /** Used to detect if a method is native */ var reNative = RegExp('^' + - String(objectProto.valueOf) + String(toString) .replace(/[.*+?^${}()|[\]\\]/g, '\\$&') - .replace(/valueOf|for [^\]]+/g, '.+?') + '$' + .replace(/toString| for [^\]]+/g, '.*?') + '$' ); /** Native method shortcuts */ @@ -4319,13 +4313,16 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? hasOwnProperty = objectProto.hasOwnProperty, now = reNative.test(now = Date.now) && now || function() { return +new Date; }, push = arrayRef.push, - setImmediate = context.setImmediate, setTimeout = context.setTimeout, - splice = arrayRef.splice, - toString = objectProto.toString, - unshift = arrayRef.unshift; + splice = arrayRef.splice; + /** Used to detect `setImmediate` in Node.js */ + var setImmediate = typeof (setImmediate = freeGlobal && moduleExports && freeGlobal.setImmediate) == 'function' && + !reNative.test(setImmediate) && setImmediate; + + /** Used to set meta data on functions */ var defineProperty = (function() { + // IE 8 only accepts DOM elements try { var o = {}, func = reNative.test(func = Object.defineProperty) && func, @@ -4335,8 +4332,7 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? }()); /* Native method shortcuts for methods with the same name as other `lodash` methods */ - var nativeBind = reNative.test(nativeBind = toString.bind) && nativeBind, - nativeCreate = reNative.test(nativeCreate = Object.create) && nativeCreate, + var nativeCreate = reNative.test(nativeCreate = Object.create) && nativeCreate, nativeIsArray = reNative.test(nativeIsArray = Array.isArray) && nativeIsArray, nativeIsFinite = context.isFinite, nativeIsNaN = context.isNaN, @@ -4344,12 +4340,7 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? nativeMax = Math.max, nativeMin = Math.min, nativeParseInt = context.parseInt, - nativeRandom = Math.random, - nativeSlice = arrayRef.slice; - - /** Detect various environments */ - var isIeOpera = reNative.test(context.attachEvent), - isV8 = nativeBind && !/\n|true/.test(nativeBind + isIeOpera); + nativeRandom = Math.random; /** Used to lookup a built-in constructor by [[Class]] */ var ctorByClass = {}; @@ -4377,15 +4368,16 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * * The chainable wrapper functions are: * `after`, `assign`, `bind`, `bindAll`, `bindKey`, `chain`, `compact`, - * `compose`, `concat`, `countBy`, `createCallback`, `curry`, `debounce`, - * `defaults`, `defer`, `delay`, `difference`, `filter`, `flatten`, `forEach`, - * `forEachRight`, `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `functions`, - * `groupBy`, `indexBy`, `initial`, `intersection`, `invert`, `invoke`, `keys`, - * `map`, `max`, `memoize`, `merge`, `min`, `object`, `omit`, `once`, `pairs`, - * `partial`, `partialRight`, `pick`, `pluck`, `pull`, `push`, `range`, `reject`, - * `remove`, `rest`, `reverse`, `shuffle`, `slice`, `sort`, `sortBy`, `splice`, - * `tap`, `throttle`, `times`, `toArray`, `transform`, `union`, `uniq`, `unshift`, - * `unzip`, `values`, `where`, `without`, `wrap`, and `zip` + * `compose`, `concat`, `countBy`, `create`, `createCallback`, `curry`, + * `debounce`, `defaults`, `defer`, `delay`, `difference`, `filter`, `flatten`, + * `forEach`, `forEachRight`, `forIn`, `forInRight`, `forOwn`, `forOwnRight`, + * `functions`, `groupBy`, `indexBy`, `initial`, `intersection`, `invert`, + * `invoke`, `keys`, `map`, `max`, `memoize`, `merge`, `min`, `object`, `omit`, + * `once`, `pairs`, `partial`, `partialRight`, `pick`, `pluck`, `pull`, `push`, + * `range`, `reject`, `remove`, `rest`, `reverse`, `shuffle`, `slice`, `sort`, + * `sortBy`, `splice`, `tap`, `throttle`, `times`, `toArray`, `transform`, + * `union`, `uniq`, `unshift`, `unzip`, `values`, `where`, `without`, `wrap`, + * and `zip` * * The non-chainable wrapper functions are: * `clone`, `cloneDeep`, `contains`, `escape`, `every`, `find`, `findIndex`, @@ -4459,14 +4451,6 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? */ var support = lodash.support = {}; - /** - * Detect if `Function#bind` exists and is inferred to be fast (all but V8). - * - * @memberOf _.support - * @type boolean - */ - support.fastBind = nativeBind && !isV8; - /** * Detect if functions can be decompiled by `Function#toString` * (all but PS3 and older Opera mobile browsers & avoided in Windows 8 apps). @@ -4547,19 +4531,53 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? /*--------------------------------------------------------------------------*/ + /** + * The base implementation of `_.bind` that creates the bound function and + * sets its meta data. + * + * @private + * @param {Array} bindData The bind data array. + * @returns {Function} Returns the new bound function. + */ + function baseBind(bindData) { + var func = bindData[0], + partialArgs = bindData[2], + thisArg = bindData[4]; + + function bound() { + // `Function#bind` spec + // http://es5.github.io/#x15.3.4.5 + if (partialArgs) { + var args = partialArgs.slice(); + push.apply(args, arguments); + } + // mimic the constructor's `return` behavior + // http://es5.github.io/#x13.2.2 + if (this instanceof bound) { + // ensure `new bound` is an instance of `func` + var thisBinding = baseCreate(func.prototype), + result = func.apply(thisBinding, args || arguments); + return isObject(result) ? result : thisBinding; + } + return func.apply(thisArg, args || arguments); + } + setBindData(bound, bindData); + return bound; + } + /** * The base implementation of `_.clone` without argument juggling or support * for `thisArg` binding. * * @private * @param {*} value The value to clone. - * @param {boolean} [deep=false] Specify a deep clone. + * @param {boolean} [isDeep=false] Specify a deep clone. * @param {Function} [callback] The function to customize cloning values. * @param {Array} [stackA=[]] Tracks traversed source objects. * @param {Array} [stackB=[]] Associates clones with source counterparts. * @returns {*} Returns the cloned value. */ - function baseClone(value, deep, callback, stackA, stackB) { + function baseClone(value, isDeep, callback, stackA, stackB) { if (callback) { var result = callback(value); if (typeof result != 'undefined') { @@ -4592,7 +4610,7 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? return value; } var isArr = isArray(value); - if (deep) { + if (isDeep) { // check for circular references and return corresponding clone var initedStack = !stackA; stackA || (stackA = getArray()); @@ -4619,7 +4637,7 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? } } // exit for shallow clone - if (!deep) { + if (!isDeep) { return result; } // add the source value to the stack of traversed objects @@ -4629,7 +4647,7 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? // recursively populate clone (susceptible to call stack limits) (isArr ? forEach : forOwn)(value, function(objValue, key) { - result[key] = baseClone(objValue, deep, callback, stackA, stackB); + result[key] = baseClone(objValue, isDeep, callback, stackA, stackB); }); if (initedStack) { @@ -4639,6 +4657,32 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? return result; } + /** + * The base implementation of `_.create` without support for assigning + * properties to the created object. + * + * @private + * @param {Object} prototype The object to inherit from. + * @returns {Object} Returns the new object. + */ + function baseCreate(prototype, properties) { + return isObject(prototype) ? nativeCreate(prototype) : {}; + } + // fallback for browsers without `Object.create` + if (!nativeCreate) { + baseCreate = (function() { + function Object() {} + return function(prototype) { + if (isObject(prototype)) { + Object.prototype = prototype; + var result = new Object; + Object.prototype = null; + } + return result || context.Object(); + }; + }()); + } + /** * The base implementation of `_.createCallback` without support for creating * "_.pluck" or "_.where" style callbacks. @@ -4653,24 +4697,30 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? if (typeof func != 'function') { return identity; } - // exit early if there is no `thisArg` - if (typeof thisArg == 'undefined') { + // exit early for no `thisArg` or already bound by `Function#bind` + if (typeof thisArg == 'undefined' || !('prototype' in func)) { return func; } - var bindData = func.__bindData__ || (support.funcNames && !func.name); + var bindData = func.__bindData__; if (typeof bindData == 'undefined') { - var source = reThis && fnToString.call(func); - if (!support.funcNames && source && !reFuncName.test(source)) { - bindData = true; + if (support.funcNames) { + bindData = !func.name; } - if (support.funcNames || !bindData) { - // checks if `func` references the `this` keyword and stores the result - bindData = !support.funcDecomp || reThis.test(source); - setBindData(func, bindData); + bindData = bindData || !support.funcDecomp; + if (!bindData) { + var source = fnToString.call(func); + if (!support.funcNames) { + bindData = !reFuncName.test(source); + } + if (!bindData) { + // checks if `func` references the `this` keyword and stores the result + bindData = reThis.test(source); + setBindData(func, bindData); + } } } // exit early if there are no `this` references or `func` is bound - if (bindData !== true && (bindData && bindData[1] & 1)) { + if (bindData === false || (bindData !== true && bindData[1] & 1)) { return func; } switch (argCount) { @@ -4690,6 +4740,96 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? return bind(func, thisArg); } + /** + * The base implementation of `createWrapper` that creates the wrapper and + * sets its meta data. + * + * @private + * @param {Array} bindData The bind data array. + * @returns {Function} Returns the new function. + */ + function baseCreateWrapper(bindData) { + var func = bindData[0], + bitmask = bindData[1], + partialArgs = bindData[2], + partialRightArgs = bindData[3], + thisArg = bindData[4], + arity = bindData[5]; + + var isBind = bitmask & 1, + isBindKey = bitmask & 2, + isCurry = bitmask & 4, + isCurryBound = bitmask & 8, + key = func; + + function bound() { + var thisBinding = isBind ? thisArg : this; + if (partialArgs) { + var args = partialArgs.slice(); + push.apply(args, arguments); + } + if (partialRightArgs || isCurry) { + args || (args = slice(arguments)); + if (partialRightArgs) { + push.apply(args, partialRightArgs); + } + if (isCurry && args.length < arity) { + bitmask |= 16 & ~32; + return baseCreateWrapper([func, (isCurryBound ? bitmask : bitmask & ~3), args, null, thisArg, arity]); + } + } + args || (args = arguments); + if (isBindKey) { + func = thisBinding[key]; + } + if (this instanceof bound) { + thisBinding = baseCreate(func.prototype); + var result = func.apply(thisBinding, args); + return isObject(result) ? result : thisBinding; + } + return func.apply(thisBinding, args); + } + setBindData(bound, bindData); + return bound; + } + + /** + * The base implementation of `_.difference` that accepts a single array + * of values to exclude. + * + * @private + * @param {Array} array The array to process. + * @param {Array} [values] The array of values to exclude. + * @returns {Array} Returns a new array of filtered values. + */ + function baseDifference(array, values) { + var index = -1, + indexOf = getIndexOf(), + length = array ? array.length : 0, + isLarge = length >= largeArraySize && indexOf === baseIndexOf, + result = []; + + if (isLarge) { + var cache = createCache(values); + if (cache) { + indexOf = cacheIndexOf; + values = cache; + } else { + isLarge = false; + } + } + while (++index < length) { + var value = array[index]; + if (indexOf(values, value) < 0) { + result.push(value); + } + } + if (isLarge) { + releaseObject(values); + } + return result; + } + /** * The base implementation of `_.flatten` without support for callback * shorthands or `thisArg` binding. @@ -4697,11 +4837,11 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * @private * @param {Array} array The array to flatten. * @param {boolean} [isShallow=false] A flag to restrict flattening to a single level. - * @param {boolean} [isArgArrays=false] A flag to restrict flattening to arrays and `arguments` objects. + * @param {boolean} [isStrict=false] A flag to restrict flattening to arrays and `arguments` objects. * @param {number} [fromIndex=0] The index to start from. * @returns {Array} Returns a new flattened array. */ - function baseFlatten(array, isShallow, isArgArrays, fromIndex) { + function baseFlatten(array, isShallow, isStrict, fromIndex) { var index = (fromIndex || 0) - 1, length = array ? array.length : 0, result = []; @@ -4713,7 +4853,7 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? && (isArray(value) || isArguments(value))) { // recursively flatten arrays (susceptible to call stack limits) if (!isShallow) { - value = baseFlatten(value, isShallow, isArgArrays); + value = baseFlatten(value, isShallow, isStrict); } var valIndex = -1, valLength = value.length, @@ -4723,7 +4863,7 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? while (++valIndex < valLength) { result[resIndex++] = value[valIndex]; } - } else if (!isArgArrays) { + } else if (!isStrict) { result.push(value); } } @@ -4806,8 +4946,11 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? var isArr = className == arrayClass; if (!isArr) { // unwrap any `lodash` wrapped values - if (hasOwnProperty.call(a, '__wrapped__ ') || hasOwnProperty.call(b, '__wrapped__')) { - return baseIsEqual(a.__wrapped__ || a, b.__wrapped__ || b, callback, isWhere, stackA, stackB); + var aWrapped = hasOwnProperty.call(a, '__wrapped__'), + bWrapped = hasOwnProperty.call(b, '__wrapped__'); + + if (aWrapped || bWrapped) { + return baseIsEqual(aWrapped ? a.__wrapped__ : a, bWrapped ? b.__wrapped__ : b, callback, isWhere, stackA, stackB); } // exit for functions and DOM nodes if (className != objectClass) { @@ -4818,10 +4961,10 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? ctorB = b.constructor; // non `Object` object instances with different constructors are not equal - if (ctorA != ctorB && !( - isFunction(ctorA) && ctorA instanceof ctorA && - isFunction(ctorB) && ctorB instanceof ctorB - )) { + if (ctorA != ctorB && + !(isFunction(ctorA) && ctorA instanceof ctorA && isFunction(ctorB) && ctorB instanceof ctorB) && + ('constructor' in a && 'constructor' in b) + ) { return false; } } @@ -4964,6 +5107,19 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? }); } + /** + * The base implementation of `_.random` without argument juggling or support + * for returning floating-point numbers. + * + * @private + * @param {number} min The minimum possible value. + * @param {number} max The maximum possible value. + * @returns {number} Returns a random number. + */ + function baseRandom(min, max) { + return min + floor(nativeRandom() * (max - min + 1)); + } + /** * The base implementation of `_.uniq` without support for callback shorthands * or `thisArg` binding. @@ -5068,16 +5224,15 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * provided to the new function. * @param {*} [thisArg] The `this` binding of `func`. * @param {number} [arity] The arity of `func`. - * @returns {Function} Returns the new bound function. + * @returns {Function} Returns the new function. */ - function createBound(func, bitmask, partialArgs, partialRightArgs, thisArg, arity) { + function createWrapper(func, bitmask, partialArgs, partialRightArgs, thisArg, arity) { var isBind = bitmask & 1, isBindKey = bitmask & 2, isCurry = bitmask & 4, isCurryBound = bitmask & 8, isPartial = bitmask & 16, - isPartialRight = bitmask & 32, - key = func; + isPartialRight = bitmask & 32; if (!isBindKey && !isFunction(func)) { throw new TypeError; @@ -5091,96 +5246,36 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? isPartialRight = partialRightArgs = false; } var bindData = func && func.__bindData__; - if (bindData) { + if (bindData && bindData !== true) { + bindData = bindData.slice(); + + // set `thisBinding` is not previously bound if (isBind && !(bindData[1] & 1)) { bindData[4] = thisArg; } + // set if previously bound but not currently (subsequent curried functions) if (!isBind && bindData[1] & 1) { bitmask |= 8; } + // set curried arity if not yet set if (isCurry && !(bindData[1] & 4)) { bindData[5] = arity; } + // append partial left arguments if (isPartial) { push.apply(bindData[2] || (bindData[2] = []), partialArgs); } + // append partial right arguments if (isPartialRight) { push.apply(bindData[3] || (bindData[3] = []), partialRightArgs); } + // merge flags bindData[1] |= bitmask; - return createBound.apply(null, bindData); + return createWrapper.apply(null, bindData); } - // use `Function#bind` if it exists and is fast - // (in V8 `Function#bind` is slower except when partially applied) - if (isBind && !(isBindKey || isCurry || isPartialRight) && - (support.fastBind || (nativeBind && isPartial))) { - if (isPartial) { - var args = [thisArg]; - push.apply(args, partialArgs); - } - var bound = isPartial - ? nativeBind.apply(func, args) - : nativeBind.call(func, thisArg); - } - else { - bound = function() { - // `Function#bind` spec - // http://es5.github.io/#x15.3.4.5 - var args = arguments, - thisBinding = isBind ? thisArg : this; - - if (isCurry || isPartial || isPartialRight) { - args = nativeSlice.call(args); - if (isPartial) { - unshift.apply(args, partialArgs); - } - if (isPartialRight) { - push.apply(args, partialRightArgs); - } - if (isCurry && args.length < arity) { - bitmask |= 16 & ~32; - return createBound(func, (isCurryBound ? bitmask : bitmask & ~3), args, null, thisArg, arity); - } - } - if (isBindKey) { - func = thisBinding[key]; - } - if (this instanceof bound) { - // ensure `new bound` is an instance of `func` - thisBinding = createObject(func.prototype); - - // mimic the constructor's `return` behavior - // http://es5.github.io/#x13.2.2 - var result = func.apply(thisBinding, args); - return isObject(result) ? result : thisBinding; - } - return func.apply(thisBinding, args); - }; - } - setBindData(bound, nativeSlice.call(arguments)); - return bound; - } - - /** - * Creates a new object with the specified `prototype`. - * - * @private - * @param {Object} prototype The prototype object. - * @returns {Object} Returns the new object. - */ - function createObject(prototype) { - return isObject(prototype) ? nativeCreate(prototype) : {}; - } - // fallback for browsers without `Object.create` - if (!nativeCreate) { - createObject = function(prototype) { - if (isObject(prototype)) { - noop.prototype = prototype; - var result = new noop; - noop.prototype = null; - } - return result || {}; - }; + // fast path for `_.bind` + var creater = (bitmask == 1 || bitmask === 17) ? baseBind : baseCreateWrapper; + return creater([func, bitmask, partialArgs, partialRightArgs, thisArg, arity]); } /** @@ -5212,7 +5307,7 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * * @private * @param {Function} func The function to set data on. - * @param {*} value The value to set. + * @param {Array} value The data array to set. */ var setBindData = !defineProperty ? noop : function(func, value) { descriptor.value = value; @@ -5388,16 +5483,16 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * @returns {Object} Returns the destination object. * @example * - * _.assign({ 'name': 'moe' }, { 'age': 40 }); - * // => { 'name': 'moe', 'age': 40 } + * _.assign({ 'name': 'fred' }, { 'employer': 'slate' }); + * // => { 'name': 'fred', 'employer': 'slate' } * * var defaults = _.partialRight(_.assign, function(a, b) { * return typeof a == 'undefined' ? b : a; * }); * - * var food = { 'name': 'apple' }; - * defaults(food, { 'name': 'banana', 'type': 'fruit' }); - * // => { 'name': 'apple', 'type': 'fruit' } + * var object = { 'name': 'barney' }; + * defaults(object, { 'name': 'fred', 'employer': 'slate' }); + * // => { 'name': 'barney', 'employer': 'slate' } */ var assign = function(object, source, guard) { var index, iterable = object, result = iterable; @@ -5427,7 +5522,7 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? }; /** - * Creates a clone of `value`. If `deep` is `true` nested objects will also + * Creates a clone of `value`. If `isDeep` is `true` nested objects will also * be cloned, otherwise they will be assigned by reference. If a callback * is provided it will be executed to produce the cloned values. If the * callback returns `undefined` cloning will be handled by the method instead. @@ -5437,23 +5532,23 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * @memberOf _ * @category Objects * @param {*} value The value to clone. - * @param {boolean} [deep=false] Specify a deep clone. + * @param {boolean} [isDeep=false] Specify a deep clone. * @param {Function} [callback] The function to customize cloning values. * @param {*} [thisArg] The `this` binding of `callback`. * @returns {*} Returns the cloned value. * @example * - * var stooges = [ - * { 'name': 'moe', 'age': 40 }, - * { 'name': 'larry', 'age': 50 } + * var characters = [ + * { 'name': 'barney', 'age': 36 }, + * { 'name': 'fred', 'age': 40 } * ]; * - * var shallow = _.clone(stooges); - * shallow[0] === stooges[0]; + * var shallow = _.clone(characters); + * shallow[0] === characters[0]; * // => true * - * var deep = _.clone(stooges, true); - * deep[0] === stooges[0]; + * var deep = _.clone(characters, true); + * deep[0] === characters[0]; * // => false * * _.mixin({ @@ -5466,15 +5561,15 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * clone.childNodes.length; * // => 0 */ - function clone(value, deep, callback, thisArg) { + function clone(value, isDeep, callback, thisArg) { // allows working with "Collections" methods without using their `index` - // and `collection` arguments for `deep` and `callback` - if (typeof deep != 'boolean' && deep != null) { + // and `collection` arguments for `isDeep` and `callback` + if (typeof isDeep != 'boolean' && isDeep != null) { thisArg = callback; - callback = deep; - deep = false; + callback = isDeep; + isDeep = false; } - return baseClone(value, deep, typeof callback == 'function' && baseCreateCallback(callback, thisArg, 1)); + return baseClone(value, isDeep, typeof callback == 'function' && baseCreateCallback(callback, thisArg, 1)); } /** @@ -5497,13 +5592,13 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * @returns {*} Returns the deep cloned value. * @example * - * var stooges = [ - * { 'name': 'moe', 'age': 40 }, - * { 'name': 'larry', 'age': 50 } + * var characters = [ + * { 'name': 'barney', 'age': 36 }, + * { 'name': 'fred', 'age': 40 } * ]; * - * var deep = _.cloneDeep(stooges); - * deep[0] === stooges[0]; + * var deep = _.cloneDeep(characters); + * deep[0] === characters[0]; * // => false * * var view = { @@ -5522,6 +5617,42 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? return baseClone(value, true, typeof callback == 'function' && baseCreateCallback(callback, thisArg, 1)); } + /** + * Creates an object that inherits from the given `prototype` object. If a + * `properties` object is provided its own enumerable properties are assigned + * to the created object. + * + * @static + * @memberOf _ + * @category Objects + * @param {Object} prototype The object to inherit from. + * @param {Object} [properties] The properties to assign to the object. + * @returns {Object} Returns the new object. + * @example + * + * function Shape() { + * this.x = 0; + * this.y = 0; + * } + * + * function Circle() { + * Shape.call(this); + * } + * + * Circle.prototype = _.create(Shape.prototype, { 'constructor': Circle }); + * + * var circle = new Circle; + * circle instanceof Circle; + * // => true + * + * circle instanceof Shape; + * // => true + */ + function create(prototype, properties) { + var result = baseCreate(prototype); + return properties ? assign(result, properties) : result; + } + /** * Assigns own enumerable properties of source object(s) to the destination * object for all destination properties that resolve to `undefined`. Once a @@ -5538,9 +5669,9 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * @returns {Object} Returns the destination object. * @example * - * var food = { 'name': 'apple' }; - * _.defaults(food, { 'name': 'banana', 'type': 'fruit' }); - * // => { 'name': 'apple', 'type': 'fruit' } + * var object = { 'name': 'barney' }; + * _.defaults(object, { 'name': 'fred', 'employer': 'slate' }); + * // => { 'name': 'barney', 'employer': 'slate' } */ var defaults = function(object, source, guard) { var index, iterable = object, result = iterable; @@ -5568,6 +5699,13 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * This method is like `_.findIndex` except that it returns the key of the * first element that passes the callback check, instead of the element itself. * + * If a property name is provided for `callback` the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is provided for `callback` the created "_.where" style callback + * will return `true` for elements that have the properties of the given object, + * else `false`. + * * @static * @memberOf _ * @category Objects @@ -5579,10 +5717,24 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * @returns {string|undefined} Returns the key of the found element, else `undefined`. * @example * - * _.findKey({ 'a': 1, 'b': 2, 'c': 3, 'd': 4 }, function(num) { - * return num % 2 == 0; + * var characters = { + * 'barney': { 'age': 36, 'blocked': false }, + * 'fred': { 'age': 40, 'blocked': true }, + * 'pebbles': { 'age': 1, 'blocked': false } + * }; + * + * _.findKey(characters, function(chr) { + * return chr.age < 40; * }); - * // => 'b' (property order is not guaranteed across environments) + * // => '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, callback, thisArg) { var result; @@ -5600,6 +5752,13 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * This method is like `_.findKey` except that it iterates over elements * of a `collection` in the opposite order. * + * If a property name is provided for `callback` the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is provided for `callback` the created "_.where" style callback + * will return `true` for elements that have the properties of the given object, + * else `false`. + * * @static * @memberOf _ * @category Objects @@ -5611,10 +5770,24 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * @returns {string|undefined} Returns the key of the found element, else `undefined`. * @example * - * _.findLastKey({ 'a': 1, 'b': 2, 'c': 3, 'd': 4 }, function(num) { - * return num % 2 == 1; + * var characters = { + * 'barney': { 'age': 36, 'blocked': true }, + * 'fred': { 'age': 40, 'blocked': false }, + * 'pebbles': { 'age': 1, 'blocked': true } + * }; + * + * _.findLastKey(characters, function(chr) { + * return chr.age < 40; * }); - * // => returns `c`, assuming `_.findKey` returns `a` + * // => returns `pebbles`, assuming `_.findKey` returns `barney` + * + * // using "_.where" callback shorthand + * _.findLastKey(characters, { 'age': 40 }); + * // => 'fred' + * + * // using "_.pluck" callback shorthand + * _.findLastKey(characters, 'blocked'); + * // => 'pebbles' */ function findLastKey(object, callback, thisArg) { var result; @@ -5644,18 +5817,20 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * @returns {Object} Returns `object`. * @example * - * function Dog(name) { - * this.name = name; + * function Shape() { + * this.x = 0; + * this.y = 0; * } * - * Dog.prototype.bark = function() { - * console.log('Woof, woof!'); + * Shape.prototype.move = function(x, y) { + * this.x += x; + * this.y += y; * }; * - * _.forIn(new Dog('Dagny'), function(value, key) { + * _.forIn(new Shape, function(value, key) { * console.log(key); * }); - * // => logs 'bark' and 'name' (property order is not guaranteed across environments) + * // => logs 'x', 'y', and 'move' (property order is not guaranteed across environments) */ var forIn = function(collection, callback, thisArg) { var index, iterable = collection, result = iterable; @@ -5681,18 +5856,20 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * @returns {Object} Returns `object`. * @example * - * function Dog(name) { - * this.name = name; + * function Shape() { + * this.x = 0; + * this.y = 0; * } * - * Dog.prototype.bark = function() { - * console.log('Woof, woof!'); + * Shape.prototype.move = function(x, y) { + * this.x += x; + * this.y += y; * }; * - * _.forInRight(new Dog('Dagny'), function(value, key) { + * _.forInRight(new Shape, function(value, key) { * console.log(key); * }); - * // => logs 'name' and 'bark' assuming `_.forIn ` logs 'bark' and 'name' + * // => logs 'move', 'y', and 'x' assuming `_.forIn ` logs 'x', 'y', and 'move' */ function forInRight(object, callback, thisArg) { var pairs = []; @@ -5834,8 +6011,8 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * @returns {Object} Returns the created inverted object. * @example * - * _.invert({ 'first': 'moe', 'second': 'larry' }); - * // => { 'moe': 'first', 'larry': 'second' } + * _.invert({ 'first': 'fred', 'second': 'barney' }); + * // => { 'fred': 'first', 'barney': 'second' } */ function invert(object) { var index = -1, @@ -5864,7 +6041,8 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * // => false */ function isBoolean(value) { - return value === true || value === false || toString.call(value) == boolClass; + return value === true || value === false || + value && typeof value == 'object' && toString.call(value) == boolClass || false; } /** @@ -5881,7 +6059,7 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * // => true */ function isDate(value) { - return value ? (typeof value == 'object' && toString.call(value) == dateClass) : false; + return value && typeof value == 'object' && toString.call(value) == dateClass || false; } /** @@ -5898,7 +6076,7 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * // => true */ function isElement(value) { - return value ? value.nodeType === 1 : false; + return value && value.nodeType === 1 || false; } /** @@ -5957,13 +6135,13 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * @returns {boolean} Returns `true` if the values are equivalent, else `false`. * @example * - * var moe = { 'name': 'moe', 'age': 40 }; - * var copy = { 'name': 'moe', 'age': 40 }; + * var object = { 'name': 'fred' }; + * var copy = { 'name': 'fred' }; * - * moe == copy; + * object == copy; * // => false * - * _.isEqual(moe, copy); + * _.isEqual(object, copy); * // => true * * var words = ['hello', 'goodbye']; @@ -6126,7 +6304,8 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * // => true */ function isNumber(value) { - return typeof value == 'number' || toString.call(value) == numberClass; + return typeof value == 'number' || + value && typeof value == 'object' && toString.call(value) == numberClass || false; } /** @@ -6139,18 +6318,18 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * @returns {boolean} Returns `true` if `value` is a plain object, else `false`. * @example * - * function Stooge(name, age) { - * this.name = name; - * this.age = age; + * function Shape() { + * this.x = 0; + * this.y = 0; * } * - * _.isPlainObject(new Stooge('moe', 40)); + * _.isPlainObject(new Shape); * // => false * * _.isPlainObject([1, 2, 3]); * // => false * - * _.isPlainObject({ 'name': 'moe', 'age': 40 }); + * _.isPlainObject({ 'x': 0, 'y': 0 }); * // => true */ var isPlainObject = function(value) { @@ -6175,11 +6354,11 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * @returns {boolean} Returns `true` if the `value` is a regular expression, else `false`. * @example * - * _.isRegExp(/moe/); + * _.isRegExp(/fred/); * // => true */ function isRegExp(value) { - return value ? (typeof value == 'object' && toString.call(value) == regexpClass) : false; + return value && typeof value == 'object' && toString.call(value) == regexpClass || false; } /** @@ -6192,11 +6371,12 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * @returns {boolean} Returns `true` if the `value` is a string, else `false`. * @example * - * _.isString('moe'); + * _.isString('fred'); * // => true */ function isString(value) { - return typeof value == 'string' || toString.call(value) == stringClass; + return typeof value == 'string' || + value && typeof value == 'object' && toString.call(value) == stringClass || false; } /** @@ -6236,21 +6416,21 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * @example * * var names = { - * 'stooges': [ - * { 'name': 'moe' }, - * { 'name': 'larry' } + * 'characters': [ + * { 'name': 'barney' }, + * { 'name': 'fred' } * ] * }; * * var ages = { - * 'stooges': [ - * { 'age': 40 }, - * { 'age': 50 } + * 'characters': [ + * { 'age': 36 }, + * { 'age': 40 } * ] * }; * * _.merge(names, ages); - * // => { 'stooges': [{ 'name': 'moe', 'age': 40 }, { 'name': 'larry', 'age': 50 }] } + * // => { 'characters': [{ 'name': 'barney', 'age': 36 }, { 'name': 'fred', 'age': 40 }] } * * var food = { * 'fruits': ['apple'], @@ -6274,6 +6454,7 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? if (!isObject(object)) { return object; } + // allows working with `_.reduce` and `_.reduceRight` without using // their `index` and `collection` arguments if (typeof args[2] != 'number') { @@ -6284,7 +6465,7 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? } else if (length > 2 && typeof args[length - 1] == 'function') { callback = args[--length]; } - var sources = nativeSlice.call(arguments, 1, length), + var sources = slice(arguments, 1, length), index = -1, stackA = getArray(), stackB = getArray(); @@ -6315,32 +6496,38 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * @returns {Object} Returns an object without the omitted properties. * @example * - * _.omit({ 'name': 'moe', 'age': 40 }, 'age'); - * // => { 'name': 'moe' } + * _.omit({ 'name': 'fred', 'age': 40 }, 'age'); + * // => { 'name': 'fred' } * - * _.omit({ 'name': 'moe', 'age': 40 }, function(value) { + * _.omit({ 'name': 'fred', 'age': 40 }, function(value) { * return typeof value == 'number'; * }); - * // => { 'name': 'moe' } + * // => { 'name': 'fred' } */ function omit(object, callback, thisArg) { - var indexOf = getIndexOf(), - isFunc = typeof callback == 'function', - result = {}; + var result = {}; + if (typeof callback != 'function') { + var props = []; + forIn(object, function(value, key) { + props.push(key); + }); + props = baseDifference(props, baseFlatten(arguments, true, false, 1)); - if (isFunc) { - callback = lodash.createCallback(callback, thisArg, 3); - } else { - var props = baseFlatten(arguments, true, false, 1); - } - forIn(object, function(value, key, object) { - if (isFunc - ? !callback(value, key, object) - : indexOf(props, key) < 0 - ) { - result[key] = value; + var index = -1, + length = props.length; + + while (++index < length) { + var key = props[index]; + result[key] = object[key]; } - }); + } else { + callback = lodash.createCallback(callback, thisArg, 3); + forIn(object, function(value, key, object) { + if (!callback(value, key, object)) { + result[key] = value; + } + }); + } return result; } @@ -6355,8 +6542,8 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * @returns {Array} Returns new array of key-value pairs. * @example * - * _.pairs({ 'moe': 30, 'larry': 40 }); - * // => [['moe', 30], ['larry', 40]] (property order is not guaranteed across environments) + * _.pairs({ 'barney': 36, 'fred': 40 }); + * // => [['barney', 36], ['fred', 40]] (property order is not guaranteed across environments) */ function pairs(object) { var index = -1, @@ -6390,13 +6577,13 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * @returns {Object} Returns an object composed of the picked properties. * @example * - * _.pick({ 'name': 'moe', '_userid': 'moe1' }, 'name'); - * // => { 'name': 'moe' } + * _.pick({ 'name': 'fred', '_userid': 'fred1' }, 'name'); + * // => { 'name': 'fred' } * - * _.pick({ 'name': 'moe', '_userid': 'moe1' }, function(value, key) { + * _.pick({ 'name': 'fred', '_userid': 'fred1' }, function(value, key) { * return key.charAt(0) != '_'; * }); - * // => { 'name': 'moe' } + * // => { 'name': 'fred' } */ function pick(object, callback, thisArg) { var result = {}; @@ -6433,7 +6620,7 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * @static * @memberOf _ * @category Objects - * @param {Array|Object} collection The collection to iterate over. + * @param {Array|Object} object The object to iterate over. * @param {Function} [callback=identity] The function called per iteration. * @param {*} [accumulator] The custom accumulator value. * @param {*} [thisArg] The `this` binding of `callback`. @@ -6455,8 +6642,6 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? */ function transform(object, callback, accumulator, thisArg) { var isArr = isArray(object); - callback = baseCreateCallback(callback, thisArg, 4); - if (accumulator == null) { if (isArr) { accumulator = []; @@ -6464,12 +6649,15 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? var ctor = object && object.constructor, proto = ctor && ctor.prototype; - accumulator = createObject(proto); + accumulator = baseCreate(proto); } } - (isArr ? forEach : forOwn)(object, function(value, index, object) { - return callback(accumulator, value, index, object); - }); + if (callback) { + callback = lodash.createCallback(callback, thisArg, 4); + (isArr ? forEach : forOwn)(object, function(value, index, object) { + return callback(accumulator, value, index, object); + }); + } return accumulator; } @@ -6518,8 +6706,8 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * _.at(['a', 'b', 'c', 'd', 'e'], [0, 2, 4]); * // => ['a', 'c', 'e'] * - * _.at(['moe', 'larry', 'curly'], 0, 2); - * // => ['moe', 'curly'] + * _.at(['fred', 'barney', 'pebbles'], 0, 2); + * // => ['fred', 'pebbles'] */ function at(collection) { var args = arguments, @@ -6555,10 +6743,10 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * _.contains([1, 2, 3], 1, 2); * // => false * - * _.contains({ 'name': 'moe', 'age': 40 }, 'moe'); + * _.contains({ 'name': 'fred', 'age': 40 }, 'fred'); * // => true * - * _.contains('curly', 'ur'); + * _.contains('pebbles', 'eb'); * // => true */ function contains(collection, target, fromIndex) { @@ -6645,20 +6833,20 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * else `false`. * @example * - * _.every([true, 1, null, 'yes'], Boolean); + * _.every([true, 1, null, 'yes']); * // => false * - * var stooges = [ - * { 'name': 'moe', 'age': 40 }, - * { 'name': 'larry', 'age': 50 } + * var characters = [ + * { 'name': 'barney', 'age': 36 }, + * { 'name': 'fred', 'age': 40 } * ]; * * // using "_.pluck" callback shorthand - * _.every(stooges, 'age'); + * _.every(characters, 'age'); * // => true * * // using "_.where" callback shorthand - * _.every(stooges, { 'age': 50 }); + * _.every(characters, { 'age': 36 }); * // => false */ function every(collection, callback, thisArg) { @@ -6709,18 +6897,18 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * var evens = _.filter([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); * // => [2, 4, 6] * - * var food = [ - * { 'name': 'apple', 'organic': false, 'type': 'fruit' }, - * { 'name': 'carrot', 'organic': true, 'type': 'vegetable' } + * var characters = [ + * { 'name': 'barney', 'age': 36, 'blocked': false }, + * { 'name': 'fred', 'age': 40, 'blocked': true } * ]; * * // using "_.pluck" callback shorthand - * _.filter(food, 'organic'); - * // => [{ 'name': 'carrot', 'organic': true, 'type': 'vegetable' }] + * _.filter(characters, 'blocked'); + * // => [{ 'name': 'fred', 'age': 40, 'blocked': true }] * * // using "_.where" callback shorthand - * _.filter(food, { 'type': 'fruit' }); - * // => [{ 'name': 'apple', 'organic': false, 'type': 'fruit' }] + * _.filter(characters, { 'age': 36 }); + * // => [{ 'name': 'barney', 'age': 36, 'blocked': false }] */ function filter(collection, callback, thisArg) { var result = []; @@ -6770,24 +6958,24 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * @returns {*} Returns the found element, else `undefined`. * @example * - * _.find([1, 2, 3, 4], function(num) { - * return num % 2 == 0; - * }); - * // => 2 - * - * var food = [ - * { 'name': 'apple', 'organic': false, 'type': 'fruit' }, - * { 'name': 'banana', 'organic': true, 'type': 'fruit' }, - * { 'name': 'beet', 'organic': false, 'type': 'vegetable' } + * var characters = [ + * { 'name': 'barney', 'age': 36, 'blocked': false }, + * { 'name': 'fred', 'age': 40, 'blocked': true }, + * { 'name': 'pebbles', 'age': 1, 'blocked': false } * ]; * + * _.find(characters, function(chr) { + * return chr.age < 40; + * }); + * // => { 'name': 'barney', 'age': 36, 'blocked': false } + * * // using "_.where" callback shorthand - * _.find(food, { 'type': 'vegetable' }); - * // => { 'name': 'beet', 'organic': false, 'type': 'vegetable' } + * _.find(characters, { 'age': 1 }); + * // => { 'name': 'pebbles', 'age': 1, 'blocked': false } * * // using "_.pluck" callback shorthand - * _.find(food, 'organic'); - * // => { 'name': 'banana', 'organic': true, 'type': 'fruit' } + * _.find(characters, 'blocked'); + * // => { 'name': 'fred', 'age': 40, 'blocked': true } */ function find(collection, callback, thisArg) { callback = lodash.createCallback(callback, thisArg, 3); @@ -6852,6 +7040,10 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * (value, index|key, collection). Callbacks may exit iteration early by * explicitly returning `false`. * + * Note: As with other "Collections" methods, objects with a `length` property + * are iterated like arrays. To avoid this behavior `_.forIn` or `_.forOwn` + * may be used for object iteration. + * * @static * @memberOf _ * @alias each @@ -6997,7 +7189,7 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * _.indexBy(keys, function(key) { return String.fromCharCode(key.code); }); * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } } * - * _.indexBy(stooges, function(key) { this.fromCharCode(key.code); }, String); + * _.indexBy(characters, function(key) { this.fromCharCode(key.code); }, String); * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } } */ var indexBy = createAggregator(function(result, value, key) { @@ -7027,7 +7219,7 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * // => [['1', '2', '3'], ['4', '5', '6']] */ function invoke(collection, methodName) { - var args = nativeSlice.call(arguments, 2), + var args = slice(arguments, 2), index = -1, isFunc = typeof methodName == 'function', length = collection ? collection.length : 0, @@ -7069,14 +7261,14 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * _.map({ 'one': 1, 'two': 2, 'three': 3 }, function(num) { return num * 3; }); * // => [3, 6, 9] (property order is not guaranteed across environments) * - * var stooges = [ - * { 'name': 'moe', 'age': 40 }, - * { 'name': 'larry', 'age': 50 } + * var characters = [ + * { 'name': 'barney', 'age': 36 }, + * { 'name': 'fred', 'age': 40 } * ]; * * // using "_.pluck" callback shorthand - * _.map(stooges, 'name'); - * // => ['moe', 'larry'] + * _.map(characters, 'name'); + * // => ['barney', 'fred'] */ function map(collection, callback, thisArg) { var index = -1, @@ -7125,23 +7317,28 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * _.max([4, 2, 8, 6]); * // => 8 * - * var stooges = [ - * { 'name': 'moe', 'age': 40 }, - * { 'name': 'larry', 'age': 50 } + * var characters = [ + * { 'name': 'barney', 'age': 36 }, + * { 'name': 'fred', 'age': 40 } * ]; * - * _.max(stooges, function(stooge) { return stooge.age; }); - * // => { 'name': 'larry', 'age': 50 }; + * _.max(characters, function(chr) { return chr.age; }); + * // => { 'name': 'fred', 'age': 40 }; * * // using "_.pluck" callback shorthand - * _.max(stooges, 'age'); - * // => { 'name': 'larry', 'age': 50 }; + * _.max(characters, 'age'); + * // => { 'name': 'fred', 'age': 40 }; */ function max(collection, callback, thisArg) { var computed = -Infinity, result = computed; - if (!callback && isArray(collection)) { + // allows working with functions like `_.map` without using + // their `index` argument as a callback + if (typeof callback != 'function' && thisArg && thisArg[callback] === collection) { + callback = null; + } + if (callback == null && isArray(collection)) { var index = -1, length = collection.length; @@ -7152,7 +7349,7 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? } } } else { - callback = (!callback && isString(collection)) + callback = (callback == null && isString(collection)) ? charAtCallback : lodash.createCallback(callback, thisArg, 3); @@ -7195,23 +7392,28 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * _.min([4, 2, 8, 6]); * // => 2 * - * var stooges = [ - * { 'name': 'moe', 'age': 40 }, - * { 'name': 'larry', 'age': 50 } + * var characters = [ + * { 'name': 'barney', 'age': 36 }, + * { 'name': 'fred', 'age': 40 } * ]; * - * _.min(stooges, function(stooge) { return stooge.age; }); - * // => { 'name': 'moe', 'age': 40 }; + * _.min(characters, function(chr) { return chr.age; }); + * // => { 'name': 'barney', 'age': 36 }; * * // using "_.pluck" callback shorthand - * _.min(stooges, 'age'); - * // => { 'name': 'moe', 'age': 40 }; + * _.min(characters, 'age'); + * // => { 'name': 'barney', 'age': 36 }; */ function min(collection, callback, thisArg) { var computed = Infinity, result = computed; - if (!callback && isArray(collection)) { + // allows working with functions like `_.map` without using + // their `index` argument as a callback + if (typeof callback != 'function' && thisArg && thisArg[callback] === collection) { + callback = null; + } + if (callback == null && isArray(collection)) { var index = -1, length = collection.length; @@ -7222,7 +7424,7 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? } } } else { - callback = (!callback && isString(collection)) + callback = (callback == null && isString(collection)) ? charAtCallback : lodash.createCallback(callback, thisArg, 3); @@ -7238,7 +7440,7 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? } /** - * Retrieves the value of a specified property from all elements in the `collection`. + * Retrieves the value of a specified property from all elements in the collection. * * @static * @memberOf _ @@ -7249,13 +7451,13 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * @returns {Array} Returns a new array of property values. * @example * - * var stooges = [ - * { 'name': 'moe', 'age': 40 }, - * { 'name': 'larry', 'age': 50 } + * var characters = [ + * { 'name': 'barney', 'age': 36 }, + * { 'name': 'fred', 'age': 40 } * ]; * - * _.pluck(stooges, 'name'); - * // => ['moe', 'larry'] + * _.pluck(characters, 'name'); + * // => ['barney', 'fred'] */ function pluck(collection, property) { var index = -1, @@ -7303,7 +7505,7 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? function reduce(collection, callback, accumulator, thisArg) { if (!collection) return accumulator; var noaccum = arguments.length < 3; - callback = baseCreateCallback(callback, thisArg, 4); + callback = lodash.createCallback(callback, thisArg, 4); var index = -1, length = collection.length; @@ -7346,7 +7548,7 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? */ function reduceRight(collection, callback, accumulator, thisArg) { var noaccum = arguments.length < 3; - callback = baseCreateCallback(callback, thisArg, 4); + callback = lodash.createCallback(callback, thisArg, 4); forEachRight(collection, function(value, index, collection) { accumulator = noaccum ? (noaccum = false, value) @@ -7380,18 +7582,18 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * var odds = _.reject([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); * // => [1, 3, 5] * - * var food = [ - * { 'name': 'apple', 'organic': false, 'type': 'fruit' }, - * { 'name': 'carrot', 'organic': true, 'type': 'vegetable' } + * var characters = [ + * { 'name': 'barney', 'age': 36, 'blocked': false }, + * { 'name': 'fred', 'age': 40, 'blocked': true } * ]; * * // using "_.pluck" callback shorthand - * _.reject(food, 'organic'); - * // => [{ 'name': 'apple', 'organic': false, 'type': 'fruit' }] + * _.reject(characters, 'blocked'); + * // => [{ 'name': 'barney', 'age': 36, 'blocked': false }] * * // using "_.where" callback shorthand - * _.reject(food, { 'type': 'fruit' }); - * // => [{ 'name': 'carrot', 'organic': true, 'type': 'vegetable' }] + * _.reject(characters, { 'age': 36 }); + * // => [{ 'name': 'fred', 'age': 40, 'blocked': true }] */ function reject(collection, callback, thisArg) { callback = lodash.createCallback(callback, thisArg, 3); @@ -7408,8 +7610,8 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * @category Collections * @param {Array|Object|string} collection The collection to sample. * @param {number} [n] The number of elements to sample. - * @param- {Object} [guard] Allows working with functions, like `_.map`, - * without using their `key` and `object` arguments as sources. + * @param- {Object} [guard] Allows working with functions like `_.map` + * without using their `index` arguments as `n`. * @returns {Array} Returns the random sample(s) of `collection`. * @example * @@ -7420,12 +7622,11 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * // => [3, 1] */ function sample(collection, n, guard) { - var length = collection ? collection.length : 0; - if (typeof length != 'number') { + if (collection && typeof collection.length != 'number') { collection = values(collection); } if (n == null || guard) { - return collection ? collection[random(length - 1)] : undefined; + return collection ? collection[baseRandom(0, collection.length - 1)] : undefined; } var result = shuffle(collection); result.length = nativeMin(nativeMax(0, n), result.length); @@ -7452,7 +7653,7 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? result = Array(typeof length == 'number' ? length : 0); forEach(collection, function(value) { - var rand = random(++index); + var rand = baseRandom(0, ++index); result[index] = result[rand]; result[rand] = value; }); @@ -7476,7 +7677,7 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * _.size({ 'one': 1, 'two': 2, 'three': 3 }); * // => 3 * - * _.size('curly'); + * _.size('pebbles'); * // => 5 */ function size(collection) { @@ -7513,17 +7714,17 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * _.some([null, 0, 'yes', false], Boolean); * // => true * - * var food = [ - * { 'name': 'apple', 'organic': false, 'type': 'fruit' }, - * { 'name': 'carrot', 'organic': true, 'type': 'vegetable' } + * var characters = [ + * { 'name': 'barney', 'age': 36, 'blocked': false }, + * { 'name': 'fred', 'age': 40, 'blocked': true } * ]; * * // using "_.pluck" callback shorthand - * _.some(food, 'organic'); + * _.some(characters, 'blocked'); * // => true * * // using "_.where" callback shorthand - * _.some(food, { 'type': 'meat' }); + * _.some(characters, { 'age': 1 }); * // => false */ function some(collection, callback, thisArg) { @@ -7639,16 +7840,16 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * @returns {Array} Returns a new array of elements that have the given properties. * @example * - * var stooges = [ - * { 'name': 'curly', 'age': 30, 'quotes': ['Oh, a wise guy, eh?', 'Poifect!'] }, - * { 'name': 'moe', 'age': 40, 'quotes': ['Spread out!', 'You knucklehead!'] } + * var characters = [ + * { 'name': 'barney', 'age': 36, 'pets': ['hoppy'] }, + * { 'name': 'fred', 'age': 40, 'pets': ['baby puss', 'dino'] } * ]; * - * _.where(stooges, { 'age': 40 }); - * // => [{ 'name': 'moe', 'age': 40, 'quotes': ['Spread out!', 'You knucklehead!'] }] + * _.where(characters, { 'age': 36 }); + * // => [{ 'name': 'barney', 'age': 36, 'pets': ['hoppy'] }] * - * _.where(stooges, { 'quotes': ['Poifect!'] }); - * // => [{ 'name': 'curly', 'age': 30, 'quotes': ['Oh, a wise guy, eh?', 'Poifect!'] }] + * _.where(characters, { 'pets': ['dino'] }); + * // => [{ 'name': 'fred', 'age': 40, 'pets': ['baby puss', 'dino'] }] */ var where = filter; @@ -7690,7 +7891,7 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * @memberOf _ * @category Arrays * @param {Array} array The array to process. - * @param {...Array} [array] The arrays of values to exclude. + * @param {...Array} [values] The arrays of values to exclude. * @returns {Array} Returns a new array of filtered values. * @example * @@ -7698,39 +7899,20 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * // => [1, 3, 4] */ function difference(array) { - var index = -1, - indexOf = getIndexOf(), - length = array ? array.length : 0, - seen = baseFlatten(arguments, true, true, 1), - result = []; - - var isLarge = length >= largeArraySize && indexOf === baseIndexOf; - - if (isLarge) { - var cache = createCache(seen); - if (cache) { - indexOf = cacheIndexOf; - seen = cache; - } else { - isLarge = false; - } - } - while (++index < length) { - var value = array[index]; - if (indexOf(seen, value) < 0) { - result.push(value); - } - } - if (isLarge) { - releaseObject(seen); - } - return result; + return baseDifference(array, baseFlatten(arguments, true, true, 1)); } /** * This method is like `_.find` except that it returns the index of the first * element that passes the callback check, instead of the element itself. * + * If a property name is provided for `callback` the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is provided for `callback` the created "_.where" style callback + * will return `true` for elements that have the properties of the given object, + * else `false`. + * * @static * @memberOf _ * @category Arrays @@ -7742,9 +7924,23 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * @returns {number} Returns the index of the found element, else `-1`. * @example * - * _.findIndex(['apple', 'banana', 'beet'], function(food) { - * return /^b/.test(food); + * var characters = [ + * { 'name': 'barney', 'age': 36, 'blocked': false }, + * { 'name': 'fred', 'age': 40, 'blocked': true }, + * { 'name': 'pebbles', 'age': 1, 'blocked': false } + * ]; + * + * _.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, callback, thisArg) { @@ -7764,6 +7960,13 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * This method is like `_.findIndex` except that it iterates over elements * of a `collection` from right to left. * + * If a property name is provided for `callback` the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is provided for `callback` the created "_.where" style callback + * will return `true` for elements that have the properties of the given object, + * else `false`. + * * @static * @memberOf _ * @category Arrays @@ -7775,9 +7978,23 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * @returns {number} Returns the index of the found element, else `-1`. * @example * - * _.findLastIndex(['apple', 'banana', 'beet'], function(food) { - * return /^b/.test(food); + * var characters = [ + * { 'name': 'barney', 'age': 36, 'blocked': true }, + * { 'name': 'fred', 'age': 40, 'blocked': false }, + * { 'name': 'pebbles', 'age': 1, 'blocked': true } + * ]; + * + * _.findLastIndex(characters, function(chr) { + * return chr.age > 30; * }); + * // => 1 + * + * // using "_.where" callback shorthand + * _.findLastIndex(characters, { 'age': 36 }); + * // => 0 + * + * // using "_.pluck" callback shorthand + * _.findLastIndex(characters, 'blocked'); * // => 2 */ function findLastIndex(array, callback, thisArg) { @@ -7828,24 +8045,19 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * }); * // => [1, 2] * - * var food = [ - * { 'name': 'banana', 'organic': true }, - * { 'name': 'beet', 'organic': false }, + * var characters = [ + * { 'name': 'barney', 'blocked': true, 'employer': 'slate' }, + * { 'name': 'fred', 'blocked': false, 'employer': 'slate' }, + * { 'name': 'pebbles', 'blocked': true, 'employer': 'na' } * ]; * * // using "_.pluck" callback shorthand - * _.first(food, 'organic'); - * // => [{ 'name': 'banana', 'organic': true }] - * - * var food = [ - * { 'name': 'apple', 'type': 'fruit' }, - * { 'name': 'banana', 'type': 'fruit' }, - * { 'name': 'beet', 'type': 'vegetable' } - * ]; + * _.first(characters, 'blocked'); + * // => [{ 'name': 'barney', 'blocked': true, 'employer': 'slate' }] * * // using "_.where" callback shorthand - * _.first(food, { 'type': 'fruit' }); - * // => [{ 'name': 'apple', 'type': 'fruit' }, { 'name': 'banana', 'type': 'fruit' }] + * _.pluck(_.first(characters, { 'employer': 'slate' }), 'name'); + * // => ['barney', 'fred'] */ function first(array, callback, thisArg) { var n = 0, @@ -7898,20 +8110,20 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * _.flatten([1, [2], [3, [[4]]]], true); * // => [1, 2, 3, [[4]]]; * - * var stooges = [ - * { 'name': 'curly', 'quotes': ['Oh, a wise guy, eh?', 'Poifect!'] }, - * { 'name': 'moe', 'quotes': ['Spread out!', 'You knucklehead!'] } + * var characters = [ + * { 'name': 'barney', 'age': 30, 'pets': ['hoppy'] }, + * { 'name': 'fred', 'age': 40, 'pets': ['baby puss', 'dino'] } * ]; * * // using "_.pluck" callback shorthand - * _.flatten(stooges, 'quotes'); - * // => ['Oh, a wise guy, eh?', 'Poifect!', 'Spread out!', 'You knucklehead!'] + * _.flatten(characters, 'pets'); + * // => ['hoppy', 'baby puss', 'dino'] */ function flatten(array, isShallow, callback, thisArg) { // juggle arguments if (typeof isShallow != 'boolean' && isShallow != null) { thisArg = callback; - callback = !(thisArg && thisArg[isShallow] === array) ? isShallow : null; + callback = (typeof isShallow != 'function' && thisArg && thisArg[isShallow] === array) ? null : isShallow; isShallow = false; } if (callback != null) { @@ -7991,24 +8203,19 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * }); * // => [1] * - * var food = [ - * { 'name': 'beet', 'organic': false }, - * { 'name': 'carrot', 'organic': true } + * var characters = [ + * { 'name': 'barney', 'blocked': false, 'employer': 'slate' }, + * { 'name': 'fred', 'blocked': true, 'employer': 'slate' }, + * { 'name': 'pebbles', 'blocked': true, 'employer': 'na' } * ]; * * // using "_.pluck" callback shorthand - * _.initial(food, 'organic'); - * // => [{ 'name': 'beet', 'organic': false }] - * - * var food = [ - * { 'name': 'banana', 'type': 'fruit' }, - * { 'name': 'beet', 'type': 'vegetable' }, - * { 'name': 'carrot', 'type': 'vegetable' } - * ]; + * _.initial(characters, 'blocked'); + * // => [{ 'name': 'barney', 'blocked': false, 'employer': 'slate' }] * * // using "_.where" callback shorthand - * _.initial(food, { 'type': 'vegetable' }); - * // => [{ 'name': 'banana', 'type': 'fruit' }] + * _.pluck(_.initial(characters, { 'employer': 'na' }), 'name'); + * // => ['barney', 'fred'] */ function initial(array, callback, thisArg) { var n = 0, @@ -8121,24 +8328,19 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * }); * // => [2, 3] * - * var food = [ - * { 'name': 'beet', 'organic': false }, - * { 'name': 'carrot', 'organic': true } + * var characters = [ + * { 'name': 'barney', 'blocked': false, 'employer': 'slate' }, + * { 'name': 'fred', 'blocked': true, 'employer': 'slate' }, + * { 'name': 'pebbles', 'blocked': true, 'employer': 'na' } * ]; * * // using "_.pluck" callback shorthand - * _.last(food, 'organic'); - * // => [{ 'name': 'carrot', 'organic': true }] - * - * var food = [ - * { 'name': 'banana', 'type': 'fruit' }, - * { 'name': 'beet', 'type': 'vegetable' }, - * { 'name': 'carrot', 'type': 'vegetable' } - * ]; + * _.pluck(_.last(characters, 'blocked'), 'name'); + * // => ['fred', 'pebbles'] * * // using "_.where" callback shorthand - * _.last(food, { 'type': 'vegetable' }); - * // => [{ 'name': 'beet', 'type': 'vegetable' }, { 'name': 'carrot', 'type': 'vegetable' }] + * _.last(characters, { 'employer': 'na' }); + * // => [{ 'name': 'pebbles', 'blocked': true, 'employer': 'na' }] */ function last(array, callback, thisArg) { var n = 0, @@ -8164,6 +8366,13 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * equality for comparisons, i.e. `===`. If `fromIndex` is negative, it is used * as the offset from the end of the collection. * + * If a property name is provided for `callback` the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is provided for `callback` the created "_.where" style callback + * will return `true` for elements that have the properties of the given object, + * else `false`. + * * @static * @memberOf _ * @category Arrays @@ -8242,17 +8451,17 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * @returns {Array} Returns a new range array. * @example * - * _.range(10); - * // => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] + * _.range(4); + * // => [0, 1, 2, 3] * - * _.range(1, 11); - * // => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + * _.range(1, 5); + * // => [1, 2, 3, 4] * - * _.range(0, 30, 5); - * // => [0, 5, 10, 15, 20, 25] + * _.range(0, 20, 5); + * // => [0, 5, 10, 15] * - * _.range(0, -10, -1); - * // => [0, -1, -2, -3, -4, -5, -6, -7, -8, -9] + * _.range(0, -4, -1); + * // => [0, -1, -2, -3] * * _.range(1, 4, 0); * // => [1, 1, 1] @@ -8268,7 +8477,7 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? end = start; start = 0; } - // use `Array(length)` so engines, like Chakra and V8, avoid slower modes + // 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))), @@ -8368,24 +8577,19 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * }); * // => [3] * - * var food = [ - * { 'name': 'banana', 'organic': true }, - * { 'name': 'beet', 'organic': false }, + * var characters = [ + * { 'name': 'barney', 'blocked': true, 'employer': 'slate' }, + * { 'name': 'fred', 'blocked': false, 'employer': 'slate' }, + * { 'name': 'pebbles', 'blocked': true, 'employer': 'na' } * ]; * * // using "_.pluck" callback shorthand - * _.rest(food, 'organic'); - * // => [{ 'name': 'beet', 'organic': false }] - * - * var food = [ - * { 'name': 'apple', 'type': 'fruit' }, - * { 'name': 'banana', 'type': 'fruit' }, - * { 'name': 'beet', 'type': 'vegetable' } - * ]; + * _.pluck(_.rest(characters, 'blocked'), 'name'); + * // => ['fred', 'pebbles'] * * // using "_.where" callback shorthand - * _.rest(food, { 'type': 'fruit' }); - * // => [{ 'name': 'beet', 'type': 'vegetable' }] + * _.rest(characters, { 'employer': 'slate' }); + * // => [{ 'name': 'pebbles', 'blocked': true, 'employer': 'na' }] */ function rest(array, callback, thisArg) { if (typeof callback != 'number' && callback != null) { @@ -8534,7 +8738,7 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? // juggle arguments if (typeof isSorted != 'boolean' && isSorted != null) { thisArg = callback; - callback = !(thisArg && thisArg[isSorted] === array) ? isSorted : null; + callback = (typeof isSorted != 'function' && thisArg && thisArg[isSorted] === array) ? null : isSorted; isSorted = false; } if (callback != null) { @@ -8559,7 +8763,7 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * // => [2, 3, 4] */ function without(array) { - return difference(array, nativeSlice.call(arguments, 1)); + return baseDifference(array, slice(arguments, 1)); } /** @@ -8575,8 +8779,8 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * @returns {Array} Returns a new array of grouped elements. * @example * - * _.zip(['moe', 'larry'], [30, 40], [true, false]); - * // => [['moe', 30, true], ['larry', 40, false]] + * _.zip(['fred', 'barney'], [30, 40], [true, false]); + * // => [['fred', 30, true], ['barney', 40, false]] */ function zip() { var array = arguments.length > 1 ? arguments : arguments[0], @@ -8605,8 +8809,8 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * corresponding values. * @example * - * _.zipObject(['moe', 'larry'], [30, 40]); - * // => { 'moe': 30, 'larry': 40 } + * _.zipObject(['fred', 'barney'], [30, 40]); + * // => { 'fred': 30, 'barney': 40 } */ function zipObject(keys, values) { var index = -1, @@ -8679,14 +8883,14 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * return greeting + ' ' + this.name; * }; * - * func = _.bind(func, { 'name': 'moe' }, 'hi'); + * func = _.bind(func, { 'name': 'fred' }, 'hi'); * func(); - * // => 'hi moe' + * // => 'hi fred' */ function bind(func, thisArg) { return arguments.length > 2 - ? createBound(func, 17, nativeSlice.call(arguments, 2), null, thisArg) - : createBound(func, 1, null, null, thisArg); + ? createWrapper(func, 17, slice(arguments, 2), null, thisArg) + : createWrapper(func, 1, null, null, thisArg); } /** @@ -8720,7 +8924,7 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? while (++index < length) { var key = funcs[index]; - object[key] = createBound(object[key], 1, null, null, object); + object[key] = createWrapper(object[key], 1, null, null, object); } return object; } @@ -8742,7 +8946,7 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * @example * * var object = { - * 'name': 'moe', + * 'name': 'fred', * 'greet': function(greeting) { * return greeting + ' ' + this.name; * } @@ -8750,19 +8954,19 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * * var func = _.bindKey(object, 'greet', 'hi'); * func(); - * // => 'hi moe' + * // => 'hi fred' * * object.greet = function(greeting) { - * return greeting + ', ' + this.name + '!'; + * return greeting + 'ya ' + this.name + '!'; * }; * * func(); - * // => 'hi, moe!' + * // => 'hiya fred!' */ function bindKey(object, key) { return arguments.length > 2 - ? createBound(key, 19, nativeSlice.call(arguments, 2), null, object) - : createBound(key, 3, null, null, object); + ? createWrapper(key, 19, slice(arguments, 2), null, object) + : createWrapper(key, 3, null, null, object); } /** @@ -8779,7 +8983,7 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * @example * * var realNameMap = { - * 'curly': 'jerome' + * 'pebbles': 'penelope' * }; * * var format = function(name) { @@ -8792,8 +8996,8 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * }; * * var welcome = _.compose(greet, format); - * welcome('curly'); - * // => 'Hiya Jerome!' + * welcome('pebbles'); + * // => 'Hiya Penelope!' */ function compose() { var funcs = arguments, @@ -8830,9 +9034,9 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * @returns {Function} Returns a callback function. * @example * - * var stooges = [ - * { 'name': 'moe', 'age': 40 }, - * { 'name': 'larry', 'age': 50 } + * var characters = [ + * { 'name': 'barney', 'age': 36 }, + * { 'name': 'fred', 'age': 40 } * ]; * * // wrap to create custom callback shorthands @@ -8843,8 +9047,8 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * }; * }); * - * _.filter(stooges, 'age__gt45'); - * // => [{ 'name': 'larry', 'age': 50 }] + * _.filter(characters, 'age__gt38'); + * // => [{ 'name': 'fred', 'age': 40 }] */ function createCallback(func, thisArg, argCount) { var type = typeof func; @@ -8913,7 +9117,7 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? */ function curry(func, arity) { arity = typeof arity == 'number' ? arity : (+arity || func.length); - return createBound(func, 4, null, null, null, arity); + return createWrapper(func, 4, null, null, null, arity); } /** @@ -8990,6 +9194,9 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? if (isCalled) { lastCalled = now(); result = func.apply(thisArg, args); + if (!timeoutId && !maxTimeoutId) { + args = thisArg = null; + } } } else { timeoutId = setTimeout(delayed, remaining); @@ -9004,6 +9211,9 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? if (trailing || (maxWait !== wait)) { lastCalled = now(); result = func.apply(thisArg, args); + if (!timeoutId && !maxTimeoutId) { + args = thisArg = null; + } } }; @@ -9019,8 +9229,10 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? if (!maxTimeoutId && !leading) { lastCalled = stamp; } - var remaining = maxWait - (stamp - lastCalled); - if (remaining <= 0) { + var remaining = maxWait - (stamp - lastCalled), + isCalled = remaining <= 0; + + if (isCalled) { if (maxTimeoutId) { maxTimeoutId = clearTimeout(maxTimeoutId); } @@ -9031,12 +9243,19 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? maxTimeoutId = setTimeout(maxDelayed, remaining); } } - if (!timeoutId && wait !== maxWait) { + if (isCalled && timeoutId) { + timeoutId = clearTimeout(timeoutId); + } + else if (!timeoutId && wait !== maxWait) { timeoutId = setTimeout(delayed, wait); } if (leadingCall) { + isCalled = true; result = func.apply(thisArg, args); } + if (isCalled && !timeoutId && !maxTimeoutId) { + args = thisArg = null; + } return result; }; } @@ -9060,11 +9279,11 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? if (!isFunction(func)) { throw new TypeError; } - var args = nativeSlice.call(arguments, 1); + var args = slice(arguments, 1); return setTimeout(function() { func.apply(undefined, args); }, 1); } // use `setImmediate` if available in Node.js - if (isV8 && moduleExports && typeof setImmediate == 'function') { + if (setImmediate) { defer = function(func) { if (!isFunction(func)) { throw new TypeError; @@ -9094,7 +9313,7 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? if (!isFunction(func)) { throw new TypeError; } - var args = nativeSlice.call(arguments, 2); + var args = slice(arguments, 2); return setTimeout(function() { func.apply(undefined, args); }, wait); } @@ -9118,19 +9337,22 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * return n < 2 ? n : fibonacci(n - 1) + fibonacci(n - 2); * }); * + * fibonacci(9) + * // => 34 + * * var data = { - * 'moe': { 'name': 'moe', 'age': 40 }, - * 'curly': { 'name': 'curly', 'age': 60 } + * 'fred': { 'name': 'fred', 'age': 40 }, + * 'pebbles': { 'name': 'pebbles', 'age': 1 } * }; * * // modifying the result cache - * var stooge = _.memoize(function(name) { return data[name]; }, _.identity); - * stooge('curly'); - * // => { 'name': 'curly', 'age': 60 } + * var get = _.memoize(function(name) { return data[name]; }, _.identity); + * get('pebbles'); + * // => { 'name': 'pebbles', 'age': 1 } * - * stooge.cache.curly.name = 'jerome'; - * stooge('curly'); - * // => { 'name': 'jerome', 'age': 60 } + * get.cache.pebbles.name = 'penelope'; + * get('pebbles'); + * // => { 'name': 'penelope', 'age': 1 } */ function memoize(func, resolver) { if (!isFunction(func)) { @@ -9200,11 +9422,11 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * * var greet = function(greeting, name) { return greeting + ' ' + name; }; * var hi = _.partial(greet, 'hi'); - * hi('moe'); - * // => 'hi moe' + * hi('fred'); + * // => 'hi fred' */ function partial(func) { - return createBound(func, 16, nativeSlice.call(arguments, 1)); + return createWrapper(func, 16, slice(arguments, 1)); } /** @@ -9235,7 +9457,7 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * // => { '_': _, 'jq': $ } */ function partialRight(func) { - return createBound(func, 32, null, nativeSlice.call(arguments, 1)); + return createWrapper(func, 32, null, slice(arguments, 1)); } /** @@ -9286,8 +9508,7 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? debounceOptions.maxWait = wait; debounceOptions.trailing = trailing; - var result = debounce(func, wait, debounceOptions); - return result; + return debounce(func, wait, debounceOptions); } /** @@ -9304,22 +9525,15 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * @returns {Function} Returns the new function. * @example * - * var hello = function(name) { return 'hello ' + name; }; - * hello = _.wrap(hello, function(func) { - * return 'before, ' + func('moe') + ', after'; + * var p = _.wrap(_.escape, function(func, text) { + * return '

' + func(text) + '

'; * }); - * hello(); - * // => 'before, hello moe, after' + * + * p('Fred, Wilma, & Pebbles'); + * // => '

Fred, Wilma, & Pebbles

' */ function wrap(value, wrapper) { - if (!isFunction(wrapper)) { - throw new TypeError; - } - return function() { - var args = [value]; - push.apply(args, arguments); - return wrapper.apply(this, args); - }; + return createWrapper(wrapper, 16, [value]); } /*--------------------------------------------------------------------------*/ @@ -9335,8 +9549,8 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * @returns {string} Returns the escaped string. * @example * - * _.escape('Moe, Larry & Curly'); - * // => 'Moe, Larry & Curly' + * _.escape('Fred, Wilma, & Pebbles'); + * // => 'Fred, Wilma, & Pebbles' */ function escape(string) { return string == null ? '' : String(string).replace(reUnescapedHtml, escapeHtmlChar); @@ -9352,8 +9566,8 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * @returns {*} Returns `value`. * @example * - * var moe = { 'name': 'moe' }; - * moe === _.identity(moe); + * var object = { 'name': 'fred' }; + * _.identity(object) === object; * // => true */ function identity(value) { @@ -9377,11 +9591,11 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * } * }); * - * _.capitalize('moe'); - * // => 'Moe' + * _.capitalize('fred'); + * // => 'Fred' * - * _('moe').capitalize(); - * // => 'Moe' + * _('fred').capitalize(); + * // => 'Fred' */ function mixin(object, source) { var ctor = object, @@ -9429,6 +9643,22 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? return this; } + /** + * A no-operation function. + * + * @static + * @memberOf _ + * @category Utilities + * @example + * + * var object = { 'name': 'fred' }; + * _.noop(object) === undefined; + * // => true + */ + function noop() { + // no operation performed + } + /** * Converts the given value into an integer of the specified radix. * If `radix` is `undefined` or `0` a `radix` of `10` is used unless the @@ -9449,7 +9679,7 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * // => 8 */ var parseInt = nativeParseInt(whitespace + '08') == 8 ? nativeParseInt : function(value, radix) { - // Firefox and Opera still follow the ES3 specified implementation of `parseInt` + // Firefox < 21 and Opera < 15 follow the ES3 specified implementation of `parseInt` return nativeParseInt(isString(value) ? value.replace(reLeadingSpacesAndZeros, '') : value, radix || 0); }; @@ -9504,10 +9734,11 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? } else { max = +max || 0; } - var rand = nativeRandom(); - return (floating || min % 1 || max % 1) - ? nativeMin(min + (rand * (max - min + parseFloat('1e-' + ((rand +'').length - 1)))), max) - : min + floor(rand * (max - min + 1)); + if (floating || min % 1 || max % 1) { + var rand = nativeRandom(); + return nativeMin(min + (rand * (max - min + parseFloat('1e-' + ((rand +'').length - 1)))), max); + } + return baseRandom(min, max); } /** @@ -9552,7 +9783,7 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * debugging. See http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl * * For more information on precompiling templates see: - * http://lodash.com/#custom-builds + * http://lodash.com/custom-builds * * For more information on Chrome extension sandboxes see: * http://developer.chrome.com/stable/extensions/sandboxingEval.html @@ -9575,8 +9806,8 @@ var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? * * // using the "interpolate" delimiter to create a compiled template * var compiled = _.template('hello <%= name %>'); - * compiled({ 'name': 'moe' }); - * // => 'hello moe' + * compiled({ 'name': 'fred' }); + * // => 'hello fred' * * // using the "escape" delimiter to escape HTML in data property values * _.template('<%- value %>', { 'value': '