Bump to v3.2.0.

This commit is contained in:
John-David Dalton
2015-12-16 17:46:22 -08:00
parent 1608d89174
commit 3ccb5e7da3
92 changed files with 1541 additions and 712 deletions

View File

@@ -1,8 +1,11 @@
define(['../lang/isError'], function(isError) {
define(['../internal/baseSlice', '../lang/isError'], function(baseSlice, isError) {
/** Used as a safe reference for `undefined` in pre-ES5 environments. */
var undefined;
/**
* Attempts to invoke `func`, returning either the result or the caught
* error object.
* Attempts to invoke `func`, returning either the result or the caught error
* object. Any additional arguments are provided to `func` when it is invoked.
*
* @static
* @memberOf _
@@ -12,9 +15,9 @@ define(['../lang/isError'], function(isError) {
* @example
*
* // avoid throwing errors for invalid selectors
* var elements = _.attempt(function() {
* var elements = _.attempt(function(selector) {
* return document.querySelectorAll(selector);
* });
* }, '>_>');
*
* if (_.isError(elements)) {
* elements = [];
@@ -22,9 +25,9 @@ define(['../lang/isError'], function(isError) {
*/
function attempt(func) {
try {
return func();
return func.apply(undefined, baseSlice(arguments, 1));
} catch(e) {
return isError(e) ? e : Error(e);
return isError(e) ? e : new Error(e);
}
}

View File

@@ -1,10 +1,11 @@
define(['../internal/baseCallback', '../internal/isIterateeCall', '../internal/isObjectLike', './matches'], function(baseCallback, isIterateeCall, isObjectLike, matches) {
/**
* Creates a function bound to an optional `thisArg`. If `func` is a property
* name the created callback returns the property value for a given element.
* If `func` is an object the created callback returns `true` for elements
* that contain the equivalent object properties, otherwise it returns `false`.
* Creates a function that invokes `func` with the `this` binding of `thisArg`
* and arguments of the created function. If `func` is a property name the
* created callback returns the property value for a given element. If `func`
* is an object the created callback returns `true` for elements that contain
* the equivalent object properties, otherwise it returns `false`.
*
* @static
* @memberOf _

View File

@@ -5,6 +5,11 @@ define(['../internal/baseClone', '../internal/baseMatches'], function(baseClone,
* and `source`, returning `true` if the given object has equivalent property
* values, else `false`.
*
* **Note:** This method supports comparing arrays, booleans, `Date` objects,
* numbers, `Object` objects, regexes, and strings. Objects are compared by
* their own, not inherited, enumerable properties. For comparing a single
* own or inherited property value see `_.matchesProperty`.
*
* @static
* @memberOf _
* @category Utility
@@ -13,17 +18,12 @@ define(['../internal/baseClone', '../internal/baseMatches'], function(baseClone,
* @example
*
* var users = [
* { 'user': 'fred', 'age': 40 },
* { 'user': 'barney', 'age': 36 }
* { 'user': 'barney', 'age': 36, 'active': true },
* { 'user': 'fred', 'age': 40, 'active': false }
* ];
*
* var matchesAge = _.matches({ 'age': 36 });
*
* _.filter(users, matchesAge);
* // => [{ 'user': 'barney', 'age': 36 }]
*
* _.find(users, matchesAge);
* // => { 'user': 'barney', 'age': 36 }
* _.filter(users, _.matches({ 'age': 40, 'active': false }));
* // => [{ 'user': 'fred', 'age': 40, 'active': false }]
*/
function matches(source) {
return baseMatches(baseClone(source, true));

View File

@@ -0,0 +1,33 @@
define(['../internal/baseClone', '../internal/baseMatchesProperty'], function(baseClone, baseMatchesProperty) {
/**
* Creates a function which compares the property value of `key` on a given
* object to `value`.
*
* **Note:** This method supports comparing arrays, booleans, `Date` objects,
* numbers, `Object` objects, regexes, and strings. Objects are compared by
* their own, not inherited, enumerable properties.
*
* @static
* @memberOf _
* @category Utility
* @param {string} key The key of the property to get.
* @param {*} value The value to compare.
* @returns {Function} Returns the new function.
* @example
*
* var users = [
* { 'user': 'barney' },
* { 'user': 'fred' },
* { 'user': 'pebbles' }
* ];
*
* _.find(users, _.matchesProperty('user', 'fred'));
* // => { 'user': 'fred', 'age': 40 }
*/
function matchesProperty(key, value) {
return baseMatchesProperty(key + '', baseClone(value, true));
}
return matchesProperty;
});

View File

@@ -28,6 +28,9 @@ define(['../internal/arrayCopy', '../internal/baseFunctions', '../lang/isFunctio
* });
* }
*
* // use `_.runInContext` to avoid potential conflicts (esp. in Node.js)
* var _ = require('lodash').runInContext();
*
* _.mixin({ 'vowels': vowels });
* _.vowels('fred');
* // => ['e']