Permalink
Browse files

Rebuild files and docs.

  • Loading branch information...
1 parent 2fe4fe7 commit 40b0b71421c48517793b7703677a7cbfc2807c85 @jdalton jdalton committed Mar 18, 2013
View
@@ -156,7 +156,7 @@
/** Used to detect if a method is native */
var reNative = RegExp('^' +
- (objectRef.valueOf + '')
+ String(objectRef.valueOf)
.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
.replace(/valueOf|for [^\]]+/g, '.+?') + '$'
);
@@ -373,7 +373,7 @@
* @type Boolean
*/
try {
- support.nodeClass = !(toString.call(document) == objectClass && !({ 'toString': 0 } + ''));
+ support.nodeClass = !(toString.call(document) == objectClass && !String({ 'toString': 0 }));
} catch(e) {
support.nodeClass = true;
}
@@ -587,13 +587,13 @@
while (++index < length) {
// manually coerce `value` to a string because `hasOwnProperty`, in some
// older versions of Firefox, coerces objects incorrectly
- var key = array[index] + '';
+ var key = String(array[index]);
(hasOwnProperty.call(cache, key) ? cache[key] : (cache[key] = [])).push(array[index]);
}
}
return function(value) {
if (isLarge) {
- var key = value + '';
+ var key = String(value);
return hasOwnProperty.call(cache, key) && indexOf(cache[key], value) > -1;
}
return indexOf(array, value, fromIndex) > -1;
@@ -792,7 +792,7 @@
function isNode(value) {
// IE < 9 presents DOM nodes as `Object` objects except they have `toString`
// methods that are `typeof` "string" and still can coerce nodes to strings
- return typeof value.toString != 'function' && typeof (value + '') == 'string';
+ return typeof value.toString != 'function' && typeof String(value) == 'string';
}
/**
@@ -885,6 +885,37 @@
}
/**
+ * This method is similar to `_.find`, except that it returns the key of the
+ * element that passes the callback check, instead of the element itself.
+ *
+ * @static
+ * @memberOf _
+ * @alias detect
+ * @category Object
+ * @param {Array|Object|String} collection The collection to iterate over.
+ * @param {Function|Object|String} [callback=identity] The function called per
+ * iteration. If a property name or object is passed, it will be used to create
+ * a "_.pluck" or "_.where" style callback, respectively.
+ * @param {Mixed} [thisArg] The `this` binding of `callback`.
+ * @returns {Mixed} 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; });
+ * // => 'b'
+ */
+ function findKey(collection, callback, thisArg) {
+ var result;
+ callback = lodash.createCallback(callback, thisArg);
+ forOwn(collection, function(value, key, collection) {
+ if (callback(value, key, collection)) {
+ result = key;
+ return false;
+ }
+ });
+ return result;
+ }
+
+ /**
* Iterates over `object`'s own and inherited enumerable properties, executing
* the `callback` for each property. The `callback` is bound to `thisArg` and
* invoked with three arguments; (value, key, object). Callbacks may exit iteration
@@ -1120,8 +1151,8 @@
* @param {Boolean} [deep=false] A flag to indicate a deep clone.
* @param {Function} [callback] The function to customize cloning values.
* @param {Mixed} [thisArg] The `this` binding of `callback`.
- * @param- {Array} [stackA=[]] Internally used to track traversed source objects.
- * @param- {Array} [stackB=[]] Internally used to associate clones with source counterparts.
+ * @param- {Array} [stackA=[]] Tracks traversed source objects.
+ * @param- {Array} [stackB=[]] Associates clones with source counterparts.
* @returns {Mixed} Returns the cloned `value`.
* @example
*
@@ -1288,8 +1319,8 @@
* @category Objects
* @param {Object} object The destination object.
* @param {Object} [source1, source2, ...] The source objects.
- * @param- {Object} [guard] Internally used to allow working with `_.reduce`
- * without using its callback's `key` and `object` arguments as sources.
+ * @param- {Object} [guard] Allows working with `_.reduce` without using its
+ * callback's `key` and `object` arguments as sources.
* @returns {Object} Returns the destination object.
* @example
*
@@ -1474,8 +1505,8 @@
* @param {Mixed} b The other value to compare.
* @param {Function} [callback] The function to customize comparing values.
* @param {Mixed} [thisArg] The `this` binding of `callback`.
- * @param- {Array} [stackA=[]] Internally used track traversed `a` objects.
- * @param- {Array} [stackB=[]] Internally used track traversed `b` objects.
+ * @param- {Array} [stackA=[]] Tracks traversed `a` objects.
+ * @param- {Array} [stackB=[]] Tracks traversed `b` objects.
* @returns {Boolean} Returns `true`, if the values are equivalent, else `false`.
* @example
*
@@ -1563,7 +1594,7 @@
case stringClass:
// coerce regexes to strings (http://es5.github.com/#x15.10.6.4)
// treat string primitives and their corresponding object instances as equal
- return a == b + '';
+ return a == String(b);
}
var isArr = className == arrayClass;
if (!isArr) {
@@ -1910,11 +1941,10 @@
* @param {Object} [source1, source2, ...] The source objects.
* @param {Function} [callback] The function to customize merging properties.
* @param {Mixed} [thisArg] The `this` binding of `callback`.
- * @param- {Object} [deepIndicator] Internally used to indicate that `stackA`
- * and `stackB` are arrays of traversed objects instead of source objects.
- * @param- {Array} [stackA=[]] Internally used to track traversed source objects.
- * @param- {Array} [stackB=[]] Internally used to associate values with their
- * source counterparts.
+ * @param- {Object} [deepIndicator] Indicates that `stackA` and `stackB` are
+ * arrays of traversed objects, instead of source objects.
+ * @param- {Array} [stackA=[]] Tracks traversed source objects.
+ * @param- {Array} [stackB=[]] Associates values with source counterparts.
* @returns {Object} Returns the destination object.
* @example
*
@@ -2302,7 +2332,7 @@
callback = lodash.createCallback(callback, thisArg);
forEach(collection, function(value, key, collection) {
- key = callback(value, key, collection) + '';
+ key = String(callback(value, key, collection));
(hasOwnProperty.call(result, key) ? result[key]++ : result[key] = 1);
});
return result;
@@ -2455,39 +2485,49 @@
* iteration. If a property name or object is passed, it will be used to create
* a "_.pluck" or "_.where" style callback, respectively.
* @param {Mixed} [thisArg] The `this` binding of `callback`.
- * @returns {Mixed} Returns the element that passed the callback check,
- * else `undefined`.
+ * @returns {Mixed} Returns the found element, else `undefined`.
* @example
*
- * var even = _.find([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; });
+ * _.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' },
- * { 'name': 'carrot', 'organic': true, 'type': 'vegetable' }
+ * { 'name': 'beet', 'organic': false, 'type': 'vegetable' }
* ];
*
* // using "_.where" callback shorthand
- * var veggie = _.find(food, { 'type': 'vegetable' });
+ * _.find(food, { 'type': 'vegetable' });
* // => { 'name': 'beet', 'organic': false, 'type': 'vegetable' }
*
* // using "_.pluck" callback shorthand
- * var healthy = _.find(food, 'organic');
+ * _.find(food, 'organic');
* // => { 'name': 'banana', 'organic': true, 'type': 'fruit' }
*/
function find(collection, callback, thisArg) {
- var result;
callback = lodash.createCallback(callback, thisArg);
- forEach(collection, function(value, index, collection) {
- if (callback(value, index, collection)) {
- result = value;
- return false;
+ if (isArray(collection)) {
+ var index = -1,
+ length = collection.length;
+
+ while (++index < length) {
+ var value = collection[index];
+ if (callback(value, index, collection)) {
+ return value;
+ }
}
- });
- return result;
+ } else {
+ var result;
+ each(collection, function(value, index, collection) {
+ if (callback(value, index, collection)) {
+ result = value;
+ return false;
+ }
+ });
+ return result;
+ }
}
/**
@@ -2567,7 +2607,7 @@
callback = lodash.createCallback(callback, thisArg);
forEach(collection, function(value, key, collection) {
- key = callback(value, key, collection) + '';
+ key = String(callback(value, key, collection));
(hasOwnProperty.call(result, key) ? result[key] : result[key] = []).push(value);
});
return result;
@@ -3247,6 +3287,38 @@
}
/**
+ * This method is similar to `_.find`, except that it returns the index of
+ * the element that passes the callback check, instead of the element itself.
+ *
+ * @static
+ * @memberOf _
+ * @alias detect
+ * @category Arrays
+ * @param {Array|Object|String} collection The collection to iterate over.
+ * @param {Function|Object|String} [callback=identity] The function called per
+ * iteration. If a property name or object is passed, it will be used to create
+ * a "_.pluck" or "_.where" style callback, respectively.
+ * @param {Mixed} [thisArg] The `this` binding of `callback`.
+ * @returns {Mixed} Returns the index of the found element, else `-1`.
+ * @example
+ *
+ * _.findIndex(['apple', 'banana', 'beet'], function(food) { return /^b/.test(food); });
+ * // => 1
+ */
+ function findIndex(collection, callback, thisArg) {
+ var index = -1,
+ length = collection ? collection.length : 0;
+
+ callback = lodash.createCallback(callback, thisArg);
+ while (++index < length) {
+ if (callback(collection[index], index, collection)) {
+ return index;
+ }
+ }
+ return -1;
+ }
+
+ /**
* Gets the first element of the `array`. If a number `n` is passed, the first
* `n` elements of the `array` are returned. If a `callback` function is passed,
* elements at the beginning of the array are returned as long as the `callback`
@@ -3540,7 +3612,7 @@
while (++index < length) {
var value = array[index];
if (isLarge) {
- var key = value + '';
+ var key = String(value);
var inited = hasOwnProperty.call(cache[0], key)
? !(seen = cache[0][key])
: (seen = cache[0][key] = []);
@@ -3948,7 +4020,7 @@
computed = callback ? callback(value, index, array) : value;
if (isLarge) {
- var key = computed + '';
+ var key = String(computed);
var inited = hasOwnProperty.call(cache, key)
? !(seen = cache[key])
: (seen = cache[key] = []);
@@ -4233,8 +4305,7 @@
* If `func` is an object, the created callback will return `true` for elements
* that contain the equivalent object properties, otherwise it will return `false`.
*
- * Note: All Lo-Dash methods, that accept a `callback` argument, internally
- * use `_.createCallback`.
+ * Note: All Lo-Dash methods, that accept a `callback` argument, use `_.createCallback`.
*
* @static
* @memberOf _
@@ -4435,7 +4506,7 @@
function memoize(func, resolver) {
var cache = {};
return function() {
- var key = (resolver ? resolver.apply(this, arguments) : arguments[0]) + '';
+ var key = String(resolver ? resolver.apply(this, arguments) : arguments[0]);
return hasOwnProperty.call(cache, key)
? cache[key]
: (cache[key] = func.apply(this, arguments));
@@ -4625,7 +4696,7 @@
* // => 'Moe, Larry &amp; Curly'
*/
function escape(string) {
- return string == null ? '' : (string + '').replace(reUnescapedHtml, escapeHtmlChar);
+ return string == null ? '' : String(string).replace(reUnescapedHtml, escapeHtmlChar);
}
/**
@@ -5020,7 +5091,7 @@
* // => 'Moe, Larry & Curly'
*/
function unescape(string) {
- return string == null ? '' : (string + '').replace(reEscapedHtml, unescapeHtmlChar);
+ return string == null ? '' : String(string).replace(reEscapedHtml, unescapeHtmlChar);
}
/**
@@ -5041,7 +5112,7 @@
*/
function uniqueId(prefix) {
var id = ++idCounter;
- return (prefix == null ? '' : prefix + '') + id;
+ return String(prefix == null ? '' : prefix) + id;
}
/*--------------------------------------------------------------------------*/
@@ -5085,7 +5156,7 @@
* // => '1,2,3'
*/
function wrapperToString() {
- return this.__wrapped__ + '';
+ return String(this.__wrapped__);
}
/**
@@ -5188,6 +5259,8 @@
lodash.escape = escape;
lodash.every = every;
lodash.find = find;
+ lodash.findIndex = findIndex;
+ lodash.findKey = findKey;
lodash.has = has;
lodash.identity = identity;
lodash.indexOf = indexOf;
Oops, something went wrong.

0 comments on commit 40b0b71

Please sign in to comment.