Remove falsey checks and reduce file size.

Former-commit-id: 5263a0beaffe2a987eb65fd3631ea4aff8d9f000
This commit is contained in:
John-David Dalton
2012-09-28 00:46:57 -07:00
parent 30666aa111
commit 7036ed5e2f
5 changed files with 80 additions and 232 deletions

View File

@@ -118,10 +118,10 @@
'lastIndexOf': [], 'lastIndexOf': [],
'lateBind': ['isFunction'], 'lateBind': ['isFunction'],
'map': ['identity'], 'map': ['identity'],
'max': [], 'max': ['identity'],
'memoize': [], 'memoize': [],
'merge': ['isArray', 'isPlainObject'], 'merge': ['isArray', 'isPlainObject'],
'min': [], 'min': ['identity'],
'mixin': ['forEach', 'functions'], 'mixin': ['forEach', 'functions'],
'noConflict': [], 'noConflict': [],
'object': [], 'object': [],
@@ -142,7 +142,7 @@
'size': ['keys'], 'size': ['keys'],
'some': ['identity'], 'some': ['identity'],
'sortBy': [], 'sortBy': [],
'sortedIndex': ['bind'], 'sortedIndex': ['bind', 'identity'],
'tap': ['mixin'], 'tap': ['mixin'],
'template': ['escape'], 'template': ['escape'],
'throttle': [], 'throttle': [],
@@ -167,7 +167,6 @@
'arrayBranch', 'arrayBranch',
'beforeLoop', 'beforeLoop',
'bottom', 'bottom',
'exit',
'firstArg', 'firstArg',
'hasDontEnumBug', 'hasDontEnumBug',
'inLoop', 'inLoop',
@@ -243,7 +242,7 @@
'partial' 'partial'
])); ]));
/** List of ways to export the `LoDash` function */ /** List of ways to export the `lodash` function */
var exportsAll = [ var exportsAll = [
'amd', 'amd',
'commonjs', 'commonjs',
@@ -362,7 +361,7 @@
' lodash plus=... Comma separated method/category names to add to those included in the build', ' lodash plus=... Comma separated method/category names to add to those included in the build',
' lodash category=... Comma separated categories of methods to include in the build (case-insensitive)', ' lodash category=... Comma separated categories of methods to include in the build (case-insensitive)',
' (i.e. “arrays”, “chaining”, “collections”, “functions”, “objects”, and “utilities”)', ' (i.e. “arrays”, “chaining”, “collections”, “functions”, “objects”, and “utilities”)',
' lodash exports=... Comma separated names of ways to export the `LoDash` function', ' lodash exports=... Comma separated names of ways to export the `lodash` function',
' (i.e. “amd”, “commonjs”, “global”, “node”, and “none”)', ' (i.e. “amd”, “commonjs”, “global”, “node”, and “none”)',
' lodash iife=... Code to replace the immediately-invoked function expression that wraps Lo-Dash', ' lodash iife=... Code to replace the immediately-invoked function expression that wraps Lo-Dash',
' (e.g. `lodash iife="!function(window,undefined){%output%}(this)"`)', ' (e.g. `lodash iife="!function(window,undefined){%output%}(this)"`)',
@@ -911,7 +910,7 @@
// constructed using the "use strict" directive // constructed using the "use strict" directive
var isStrict = options.indexOf('strict') > -1; var isStrict = options.indexOf('strict') > -1;
// used to specify the ways to export the `LoDash` function // used to specify the ways to export the `lodash` function
var exportsOptions = options.reduce(function(result, value) { var exportsOptions = options.reduce(function(result, value) {
return /exports/.test(value) ? optionToArray(value).sort() : result; return /exports/.test(value) ? optionToArray(value).sort() : result;
}, isUnderscore }, isUnderscore
@@ -1324,12 +1323,10 @@
source = removeIsFunctionFallback(source); source = removeIsFunctionFallback(source);
} }
if (isRemoved(source, 'mixin')) { if (isRemoved(source, 'mixin')) {
// remove `LoDash` constructor // remove `lodash` calls
source = removeFunction(source, 'LoDash'); source = source.replace(/(?:new +lodash(?!\()|(?:new +)?lodash\([^)]*\));?/g, '');
// remove `LoDash` calls // remove `lodash.prototype` additions
source = source.replace(/(?:new +LoDash(?!\()|(?:new +)?LoDash\([^)]*\));?/g, ''); source = source.replace(/(?:\s*\/\/.*)*\s*mixin\(lodash\)[\s\S]+?\/\*-+\*\//, '');
// remove `LoDash.prototype` additions
source = source.replace(/(?:\s*\/\/.*)*\s*LoDash.prototype *=[\s\S]+?\/\*-+\*\//, '');
// remove `hasObjectSpliceBug` assignment // remove `hasObjectSpliceBug` assignment
source = source.replace(/(?:\n +\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)?\n *var hasObjectSpliceBug;|.+?hasObjectSpliceBug *=.+/g, ''); source = source.replace(/(?:\n +\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)?\n *var hasObjectSpliceBug;|.+?hasObjectSpliceBug *=.+/g, '');
} }

View File

@@ -10,10 +10,10 @@
'lodash': 'lodash':
'/*!\n' + '/*!\n' +
' Lo-Dash @VERSION lodash.com/license\n' + ' Lo-Dash @VERSION lodash.com/license\n' +
' Underscore.js 1.3.3 github.com/documentcloud/underscore/blob/master/LICENSE\n' + ' Underscore.js 1.4.0 underscorejs.org/LICENSE\n' +
'*/', '*/',
'underscore': 'underscore':
'/*! Underscore.js @VERSION github.com/documentcloud/underscore/blob/master/LICENSE */' '/*! Underscore.js @VERSION underscorejs.org/LICENSE */'
}; };
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/

View File

@@ -80,7 +80,6 @@
'arrayBranch', 'arrayBranch',
'beforeLoop', 'beforeLoop',
'bottom', 'bottom',
'exit',
'firstArg', 'firstArg',
'hasDontEnumBug', 'hasDontEnumBug',
'inLoop', 'inLoop',

245
lodash.js
View File

@@ -1,8 +1,8 @@
/*! /*!
* Lo-Dash v0.7.0 <http://lodash.com> * Lo-Dash v0.7.0 <http://lodash.com>
* Copyright 2012 John-David Dalton <http://allyoucanleet.com/> * (c) 2012 John-David Dalton <http://allyoucanleet.com/>
* Based on Underscore.js 1.3.3, copyright 2009-2012 Jeremy Ashkenas, DocumentCloud Inc. * Based on Underscore.js 1.4.0 <http://underscorejs.org>
* <http://documentcloud.github.com/underscore> * (c) 2009-2012 Jeremy Ashkenas, DocumentCloud Inc.
* Available under MIT license <http://lodash.com/license> * Available under MIT license <http://lodash.com/license>
*/ */
;(function(window, undefined) { ;(function(window, undefined) {
@@ -259,26 +259,18 @@
* *
* @name _ * @name _
* @constructor * @constructor
* @param {Mixed} value The value to wrap in a `LoDash` instance. * @param {Mixed} value The value to wrap in a `lodash` instance.
* @returns {Object} Returns a `LoDash` instance. * @returns {Object} Returns a `lodash` instance.
*/ */
function lodash(value) { function lodash(value) {
// allow invoking `lodash` without the `new` operator
return new LoDash(value);
}
/**
* Creates a `LoDash` instance that wraps a value to allow chaining.
*
* @private
* @constructor
* @param {Mixed} value The value to wrap.
*/
function LoDash(value) {
// exit early if already wrapped // exit early if already wrapped
if (value && value.__wrapped__) { if (value && value.__wrapped__) {
return value; return value;
} }
// allow invoking `lodash` without the `new` operator
if (!(this instanceof lodash)) {
return new lodash(value);
}
this.__wrapped__ = value; this.__wrapped__ = value;
} }
@@ -347,9 +339,7 @@
'var index, value, iteratee = <%= firstArg %>, ' + 'var index, value, iteratee = <%= firstArg %>, ' +
// assign the `result` variable an initial value // assign the `result` variable an initial value
'result<% if (init) { %> = <%= init %><% } %>;\n' + 'result<% if (init) { %> = <%= init %><% } %>;\n' +
// add code to exit early or do so if the first argument is falsey // add code before the iteration branches
'<%= exit %>;\n' +
// add code after the exit snippet but before the iteration branches
'<%= top %>;\n' + '<%= top %>;\n' +
// the following branch is for iterating arrays and array-like objects // the following branch is for iterating arrays and array-like objects
@@ -465,8 +455,7 @@
'top': 'top':
'if (!callback) {\n' + 'if (!callback) {\n' +
' callback = identity\n' + ' callback = identity\n' +
'}\n' + '} else if (thisArg !== undefined) {\n' +
'else if (thisArg !== undefined) {\n' +
' callback = bindCallback(callback, thisArg)\n' + ' callback = bindCallback(callback, thisArg)\n' +
'}', '}',
'inLoop': 'if (callback(value, index, collection) === false) return result' 'inLoop': 'if (callback(value, index, collection) === false) return result'
@@ -526,7 +515,6 @@
/** Reusable iterator options for `invoke`, `map`, `pluck`, and `sortBy` */ /** Reusable iterator options for `invoke`, `map`, `pluck`, and `sortBy` */
var mapIteratorOptions = { var mapIteratorOptions = {
'init': '', 'init': '',
'exit': 'if (!collection) return []',
'beforeLoop': { 'beforeLoop': {
'array': 'result = Array(length)', 'array': 'result = Array(length)',
'object': 'result = ' + (isKeysFast ? 'Array(length)' : '[]') 'object': 'result = ' + (isKeysFast ? 'Array(length)' : '[]')
@@ -712,11 +700,7 @@
* *
* init - A string to specify the initial value of the `result` variable. * init - A string to specify the initial value of the `result` variable.
* *
* exit - A string of code to use in place of the default exit-early check * top - A string of code to execute before the iteration branches.
* of `if (!arguments[0]) return result`.
*
* top - A string of code to execute after the exit-early check but before
* the iteration branches.
* *
* beforeLoop - A string or object containing an "array" or "object" property * beforeLoop - A string or object containing an "array" or "object" property
* of code to execute before the array or object loops. * of code to execute before the array or object loops.
@@ -739,8 +723,6 @@
// merge options into a template data object // merge options into a template data object
var data = { var data = {
'bottom': '', 'bottom': '',
'exit': '',
'init': '',
'top': '', 'top': '',
'arrayBranch': { 'beforeLoop': '' }, 'arrayBranch': { 'beforeLoop': '' },
'objectBranch': { 'beforeLoop': '' } 'objectBranch': { 'beforeLoop': '' }
@@ -765,10 +747,12 @@
// set additional template `data` values // set additional template `data` values
var args = data.args, var args = data.args,
firstArg = /^[^,]+/.exec(args)[0], firstArg = /^[^,]+/.exec(args)[0],
init = data.init,
useStrict = data.useStrict; useStrict = data.useStrict;
data.firstArg = firstArg; data.firstArg = firstArg;
data.hasDontEnumBug = hasDontEnumBug; data.hasDontEnumBug = hasDontEnumBug;
data.init = init == null ? firstArg : init;
data.isKeysFast = isKeysFast; data.isKeysFast = isKeysFast;
data.noArgsEnum = noArgsEnum; data.noArgsEnum = noArgsEnum;
data.shadowed = shadowed; data.shadowed = shadowed;
@@ -778,9 +762,6 @@
if (data.noCharByIndex == null) { if (data.noCharByIndex == null) {
data.noCharByIndex = noCharByIndex; data.noCharByIndex = noCharByIndex;
} }
if (!data.exit) {
data.exit = 'if (!' + firstArg + ') return result';
}
if (firstArg != 'collection' || !data.arrayBranch.inLoop) { if (firstArg != 'collection' || !data.arrayBranch.inLoop) {
data.arrayBranch = null; data.arrayBranch = null;
} }
@@ -788,7 +769,7 @@
var factory = Function( var factory = Function(
'arrayLikeClasses, ArrayProto, bind, bindCallback, compareAscending, concat, ' + 'arrayLikeClasses, ArrayProto, bind, bindCallback, compareAscending, concat, ' +
'forIn, hasOwnProperty, identity, indexOf, isArguments, isArray, isFunction, ' + 'forIn, hasOwnProperty, identity, indexOf, isArguments, isArray, isFunction, ' +
'isPlainObject, noop, objectClass, objectTypes, nativeKeys, propertyIsEnumerable, ' + 'isPlainObject, objectClass, objectTypes, nativeKeys, propertyIsEnumerable, ' +
'propertyCallback, slice, stringClass, toString, undefined', 'propertyCallback, slice, stringClass, toString, undefined',
'var callee = function(' + args + ') {\n' + iteratorTemplate(data) + '\n};\n' + 'var callee = function(' + args + ') {\n' + iteratorTemplate(data) + '\n};\n' +
'return callee' 'return callee'
@@ -797,7 +778,7 @@
return factory( return factory(
arrayLikeClasses, ArrayProto, bind, bindCallback, compareAscending, concat, arrayLikeClasses, ArrayProto, bind, bindCallback, compareAscending, concat,
forIn, hasOwnProperty, identity, indexOf, isArguments, isArray, isFunction, forIn, hasOwnProperty, identity, indexOf, isArguments, isArray, isFunction,
isPlainObject, noop, objectClass, objectTypes, nativeKeys, propertyIsEnumerable, isPlainObject, objectClass, objectTypes, nativeKeys, propertyIsEnumerable,
propertyCallback, slice, stringClass, toString propertyCallback, slice, stringClass, toString
); );
} }
@@ -825,15 +806,6 @@
return htmlEscapes[match]; return htmlEscapes[match];
} }
/**
* A no-operation function.
*
* @private
*/
function noop() {
// no operation performed
}
/** /**
* Creates a function that returns the `property` value of the given `object`. * Creates a function that returns the `property` value of the given `object`.
* *
@@ -1268,7 +1240,7 @@
* // => true * // => true
*/ */
function has(object, property) { function has(object, property) {
return object ? hasOwnProperty.call(object, property) : false; return hasOwnProperty.call(object, property);
} }
/** /**
@@ -1366,6 +1338,7 @@
'args': 'value', 'args': 'value',
'init': 'true', 'init': 'true',
'top': 'top':
'if (!value) return result;\n' +
'var className = toString.call(value),\n' + 'var className = toString.call(value),\n' +
' length = value.length;\n' + ' length = value.length;\n' +
'if (arrayLikeClasses[className]' + 'if (arrayLikeClasses[className]' +
@@ -1411,7 +1384,7 @@
// treat `+0` vs. `-0` as not equal // treat `+0` vs. `-0` as not equal
return a !== 0 || (1 / a == 1 / b); return a !== 0 || (1 / a == 1 / b);
} }
// unwrap any LoDash wrapped values // unwrap any `lodash` wrapped values
if (objectTypes[typeof a] || objectTypes[typeof b]) { if (objectTypes[typeof a] || objectTypes[typeof b]) {
a = a.__wrapped__ || a; a = a.__wrapped__ || a;
b = b.__wrapped__ || b; b = b.__wrapped__ || b;
@@ -1732,9 +1705,7 @@
if (type == 'function' && propertyIsEnumerable.call(object, 'prototype')) { if (type == 'function' && propertyIsEnumerable.call(object, 'prototype')) {
return shimKeys(object); return shimKeys(object);
} }
return object && objectTypes[type] return nativeKeys(object);
? nativeKeys(object)
: [];
}; };
/** /**
@@ -1771,16 +1742,11 @@
var merge = createIterator(extendIteratorOptions, { var merge = createIterator(extendIteratorOptions, {
'args': 'object, source, indicator', 'args': 'object, source, indicator',
'top': 'top':
'var argsLength, isArr, stackA, stackB,\n' + 'var isArr, args = arguments, argsIndex = 0;\n' +
' args = arguments, argsIndex = 0;\n' + 'if (indicator == compareAscending) {\n' +
'if (indicator == noop) {\n' + ' var argsLength = 2, stackA = args[3], stackB = args[4]\n' +
' argsLength = 2;\n' +
' stackA = args[3];\n' +
' stackB = args[4]\n' +
'} else {\n' + '} else {\n' +
' argsLength = args.length;\n' + ' var argsLength = args.length, stackA = [], stackB = []\n' +
' stackA = [];\n' +
' stackB = []\n' +
'}\n' + '}\n' +
'while (++argsIndex < argsLength) {\n' + 'while (++argsIndex < argsLength) {\n' +
' if (iteratee = args[argsIndex]) {', ' if (iteratee = args[argsIndex]) {',
@@ -1798,7 +1764,7 @@
' ? (isArray(value) ? value : [])\n' + ' ? (isArray(value) ? value : [])\n' +
' : (isPlainObject(value) ? value : {})\n' + ' : (isPlainObject(value) ? value : {})\n' +
' );\n' + ' );\n' +
' result[index] = callee(value, source, noop, stackA, stackB)\n' + ' result[index] = callee(value, source, compareAscending, stackA, stackB)\n' +
' }\n' + ' }\n' +
'} else if (source != null) {\n' + '} else if (source != null) {\n' +
' result[index] = source\n' + ' result[index] = source\n' +
@@ -2243,9 +2209,6 @@
* // => [4, 5, 2, 3, 0, 1] * // => [4, 5, 2, 3, 0, 1]
*/ */
function reduceRight(collection, callback, accumulator, thisArg) { function reduceRight(collection, callback, accumulator, thisArg) {
if (!collection) {
return accumulator;
}
var iteratee = collection, var iteratee = collection,
length = collection.length, length = collection.length,
noaccum = arguments.length < 3; noaccum = arguments.length < 3;
@@ -2465,12 +2428,9 @@
* // => [1, 2, 3] * // => [1, 2, 3]
*/ */
function compact(array) { function compact(array) {
var result = [];
if (!array) {
return result;
}
var index = -1, var index = -1,
length = array.length; length = array.length,
result = [];
while (++index < length) { while (++index < length) {
if (array[index]) { if (array[index]) {
@@ -2497,14 +2457,11 @@
* // => [1, 3, 4] * // => [1, 3, 4]
*/ */
function difference(array) { function difference(array) {
var result = [];
if (!array) {
return result;
}
var index = -1, var index = -1,
length = array.length, length = array.length,
flattened = concat.apply(ArrayProto, arguments), flattened = concat.apply(ArrayProto, arguments),
contains = cachedContains(flattened, length); contains = cachedContains(flattened, length),
result = [];
while (++index < length) { while (++index < length) {
if (!contains(array[index])) { if (!contains(array[index])) {
@@ -2534,9 +2491,7 @@
* // => 5 * // => 5
*/ */
function first(array, n, guard) { function first(array, n, guard) {
if (array) { return (n == null || guard) ? array[0] : slice.call(array, 0, n);
return (n == null || guard) ? array[0] : slice.call(array, 0, n);
}
} }
/** /**
@@ -2558,13 +2513,10 @@
* // => [1, 2, 3, [[4]]]; * // => [1, 2, 3, [[4]]];
*/ */
function flatten(array, shallow) { function flatten(array, shallow) {
var result = [];
if (!array) {
return result;
}
var value, var value,
index = -1, index = -1,
length = array.length; length = array.length,
result = [];
while (++index < length) { while (++index < length) {
value = array[index]; value = array[index];
@@ -2604,9 +2556,6 @@
* // => 2 * // => 2
*/ */
function indexOf(array, value, fromIndex) { function indexOf(array, value, fromIndex) {
if (!array) {
return -1;
}
var index = -1, var index = -1,
length = array.length; length = array.length;
@@ -2644,9 +2593,6 @@
* // => [3, 2] * // => [3, 2]
*/ */
function initial(array, n, guard) { function initial(array, n, guard) {
if (!array) {
return [];
}
return slice.call(array, 0, -((n == null || guard) ? 1 : n)); return slice.call(array, 0, -((n == null || guard) ? 1 : n));
} }
@@ -2666,15 +2612,12 @@
* // => [1, 2] * // => [1, 2]
*/ */
function intersection(array) { function intersection(array) {
var result = [];
if (!array) {
return result;
}
var value, var value,
argsLength = arguments.length, argsLength = arguments.length,
cache = [], cache = [],
index = -1, index = -1,
length = array.length; length = array.length,
result = [];
array: while (++index < length) { array: while (++index < length) {
value = array[index]; value = array[index];
@@ -2709,10 +2652,8 @@
* // => 1 * // => 1
*/ */
function last(array, n, guard) { function last(array, n, guard) {
if (array) { var length = array.length;
var length = array.length; return (n == null || guard) ? array[length - 1] : slice.call(array, -n || length);
return (n == null || guard) ? array[length - 1] : slice.call(array, -n || length);
}
} }
/** /**
@@ -2735,9 +2676,6 @@
* // => 1 * // => 1
*/ */
function lastIndexOf(array, value, fromIndex) { function lastIndexOf(array, value, fromIndex) {
if (!array) {
return -1;
}
var index = array.length; var index = array.length;
if (fromIndex && typeof fromIndex == 'number') { if (fromIndex && typeof fromIndex == 'number') {
index = (fromIndex < 0 ? nativeMax(0, index + fromIndex) : nativeMin(fromIndex, index - 1)) + 1; index = (fromIndex < 0 ? nativeMax(0, index + fromIndex) : nativeMin(fromIndex, index - 1)) + 1;
@@ -2786,14 +2724,8 @@
length = array.length; length = array.length;
if (!callback) { if (!callback) {
while (++index < length) { callback = identity;
if (array[index] > result) { } else if (thisArg !== undefined) {
result = array[index];
}
}
return result;
}
if (thisArg !== undefined) {
callback = bindCallback(callback, thisArg); callback = bindCallback(callback, thisArg);
} }
while (++index < length) { while (++index < length) {
@@ -2836,14 +2768,8 @@
length = array.length; length = array.length;
if (!callback) { if (!callback) {
while (++index < length) { callback = identity;
if (array[index] < result) { } else if (thisArg !== undefined) {
result = array[index];
}
}
return result;
}
if (thisArg !== undefined) {
callback = bindCallback(callback, thisArg); callback = bindCallback(callback, thisArg);
} }
while (++index < length) { while (++index < length) {
@@ -2874,9 +2800,6 @@
* // => { 'moe': 30, 'larry': 40, 'curly': 50 } * // => { 'moe': 30, 'larry': 40, 'curly': 50 }
*/ */
function object(keys, values) { function object(keys, values) {
if (!keys) {
return {};
}
var index = -1, var index = -1,
length = keys.length, length = keys.length,
result = {}; result = {};
@@ -2960,9 +2883,6 @@
* // => [2, 1] * // => [2, 1]
*/ */
function rest(array, n, guard) { function rest(array, n, guard) {
if (!array) {
return [];
}
return slice.call(array, (n == null || guard) ? 1 : n); return slice.call(array, (n == null || guard) ? 1 : n);
} }
@@ -2981,9 +2901,6 @@
* // => [4, 1, 6, 3, 5, 2] * // => [4, 1, 6, 3, 5, 2]
*/ */
function shuffle(array) { function shuffle(array) {
if (!array) {
return [];
}
var rand, var rand,
index = -1, index = -1,
length = array.length, length = array.length,
@@ -3033,29 +2950,21 @@
* // => 2 * // => 2
*/ */
function sortedIndex(array, value, callback, thisArg) { function sortedIndex(array, value, callback, thisArg) {
if (!array) {
return 0;
}
var mid, var mid,
low = 0, low = 0,
high = array.length; high = array.length;
if (callback) { if (!callback) {
if (typeof callback != 'function') { callback = identity;
callback = propertyCallback(callback); } else if (typeof callback != 'function') {
} else if (thisArg !== undefined) { callback = propertyCallback(callback);
callback = bind(callback, thisArg); } else if (thisArg !== undefined) {
} callback = bind(callback, thisArg);
value = callback(value); }
while (low < high) { value = callback(value);
mid = (low + high) >>> 1; while (low < high) {
callback(array[mid]) < value ? low = mid + 1 : high = mid; mid = (low + high) >>> 1;
} callback(array[mid]) < value ? low = mid + 1 : high = mid;
} else {
while (low < high) {
mid = (low + high) >>> 1;
array[mid] < value ? low = mid + 1 : high = mid;
}
} }
return low; return low;
} }
@@ -3120,13 +3029,10 @@
* // => [1, 2, 3] * // => [1, 2, 3]
*/ */
function uniq(array, isSorted, callback, thisArg) { function uniq(array, isSorted, callback, thisArg) {
var result = [];
if (!array) {
return result;
}
var computed, var computed,
index = -1, index = -1,
length = array.length, length = array.length,
result = [],
seen = []; seen = [];
// juggle arguments // juggle arguments
@@ -3169,13 +3075,10 @@
* // => [2, 3, 4] * // => [2, 3, 4]
*/ */
function without(array) { function without(array) {
var result = [];
if (!array) {
return result;
}
var index = -1, var index = -1,
length = array.length, length = array.length,
contains = cachedContains(arguments, 1, 20); contains = cachedContains(arguments, 1, 20),
result = [];
while (++index < length) { while (++index < length) {
if (!contains(array[index])) { if (!contains(array[index])) {
@@ -3202,9 +3105,6 @@
* // => [['moe', 30, true], ['larry', 40, false], ['curly', 50, false]] * // => [['moe', 30, true], ['larry', 40, false], ['curly', 50, false]]
*/ */
function zip(array) { function zip(array) {
if (!array) {
return [];
}
var index = -1, var index = -1,
length = max(pluck(arguments, 'length')), length = max(pluck(arguments, 'length')),
result = Array(length); result = Array(length);
@@ -3303,7 +3203,6 @@
'useHas': false, 'useHas': false,
'useStrict': false, 'useStrict': false,
'args': 'object', 'args': 'object',
'init': 'object',
'top': 'top':
'var funcs = arguments,\n' + 'var funcs = arguments,\n' +
' length = funcs.length;\n' + ' length = funcs.length;\n' +
@@ -3704,14 +3603,14 @@
forEach(functions(object), function(methodName) { forEach(functions(object), function(methodName) {
var func = lodash[methodName] = object[methodName]; var func = lodash[methodName] = object[methodName];
LoDash.prototype[methodName] = function() { lodash.prototype[methodName] = function() {
var args = [this.__wrapped__]; var args = [this.__wrapped__];
if (arguments.length) { if (arguments.length) {
push.apply(args, arguments); push.apply(args, arguments);
} }
var result = func.apply(lodash, args); var result = func.apply(lodash, args);
if (this.__chain__) { if (this.__chain__) {
result = new LoDash(result); result = new lodash(result);
result.__chain__ = true; result.__chain__ = true;
} }
return result; return result;
@@ -3872,7 +3771,6 @@
// and Laura Doktorova's doT.js // and Laura Doktorova's doT.js
// https://github.com/olado/doT // https://github.com/olado/doT
options || (options = {}); options || (options = {});
text += '';
var isEvaluating, var isEvaluating,
result, result,
@@ -3990,14 +3888,8 @@
var index = -1, var index = -1,
result = Array(n); result = Array(n);
if (thisArg !== undefined) { while (++index < n) {
while (++index < n) { result[index] = callback.call(thisArg, index);
result[index] = callback.call(thisArg, index);
}
} else {
while (++index < n) {
result[index] = callback(index);
}
} }
return result; return result;
} }
@@ -4065,7 +3957,7 @@
* // => 'moe is 40' * // => 'moe is 40'
*/ */
function chain(value) { function chain(value) {
value = new LoDash(value); value = new lodash(value);
value.__chain__ = true; value.__chain__ = true;
return value; return value;
} }
@@ -4261,22 +4153,19 @@
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
// assign private `LoDash` constructor's prototype // add all static functions to `lodash.prototype`
LoDash.prototype = lodash.prototype;
// add all static functions to `LoDash.prototype`
mixin(lodash); mixin(lodash);
// add `LoDash.prototype.chain` after calling `mixin()` to avoid overwriting // add `lodash.prototype.chain` after calling `mixin()` to avoid overwriting
// it with the wrapped `lodash.chain` // it with the wrapped `lodash.chain`
LoDash.prototype.chain = wrapperChain; lodash.prototype.chain = wrapperChain;
LoDash.prototype.value = wrapperValue; lodash.prototype.value = wrapperValue;
// add all mutator Array functions to the wrapper. // add all mutator Array functions to the wrapper.
forEach(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(methodName) { forEach(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(methodName) {
var func = ArrayProto[methodName]; var func = ArrayProto[methodName];
LoDash.prototype[methodName] = function() { lodash.prototype[methodName] = function() {
var value = this.__wrapped__; var value = this.__wrapped__;
func.apply(value, arguments); func.apply(value, arguments);
@@ -4286,7 +4175,7 @@
delete value[0]; delete value[0];
} }
if (this.__chain__) { if (this.__chain__) {
value = new LoDash(value); value = new lodash(value);
value.__chain__ = true; value.__chain__ = true;
} }
return value; return value;
@@ -4297,12 +4186,12 @@
forEach(['concat', 'join', 'slice'], function(methodName) { forEach(['concat', 'join', 'slice'], function(methodName) {
var func = ArrayProto[methodName]; var func = ArrayProto[methodName];
LoDash.prototype[methodName] = function() { lodash.prototype[methodName] = function() {
var value = this.__wrapped__, var value = this.__wrapped__,
result = func.apply(value, arguments); result = func.apply(value, arguments);
if (this.__chain__) { if (this.__chain__) {
result = new LoDash(result); result = new lodash(result);
result.__chain__ = true; result.__chain__ = true;
} }
return result; return result;

View File

@@ -394,7 +394,7 @@
} else { } else {
func(object, { 'a': 1 }); func(object, { 'a': 1 });
} }
} catch(e) { } catch(e) {console.log(e);
pass = false; pass = false;
} }
ok(pass); ok(pass);
@@ -1696,43 +1696,6 @@
QUnit.module('lodash methods'); QUnit.module('lodash methods');
(function() { (function() {
test('should allow falsey arguments', function() {
var funcs = _.without.apply(_, [_.functions(_)].concat([
'_',
'_iteratorTemplate',
'_shimKeys',
'after',
'bind',
'bindAll',
'compose',
'debounce',
'defer',
'delay',
'functions',
'memoize',
'once',
'partial',
'tap',
'throttle',
'wrap'
]));
_.each(funcs, function(methodName) {
var func = _[methodName],
pass = true;
_.each(falsey, function(value, index) {
try {
index ? func(value) : func();
} catch(e) {
pass = false;
}
});
ok(pass, '_.' + methodName + ' allows falsey arguments');
});
});
test('should handle `null` `thisArg` arguments', function() { test('should handle `null` `thisArg` arguments', function() {
var thisArg, var thisArg,
array = ['a'], array = ['a'],