Bump to v3.7.0.

This commit is contained in:
John-David Dalton
2015-12-16 17:49:35 -08:00
parent 9724afd7a6
commit fec213a98c
121 changed files with 1686 additions and 815 deletions

View File

@@ -1,4 +1,4 @@
define(['../internal/baseAssign', '../internal/createAssigner'], function(baseAssign, createAssigner) {
define(['../internal/assignWith', '../internal/baseAssign', '../internal/createAssigner'], function(assignWith, baseAssign, createAssigner) {
/**
* Assigns own enumerable properties of source object(s) to the destination
@@ -7,13 +7,17 @@ define(['../internal/baseAssign', '../internal/createAssigner'], function(baseAs
* The `customizer` is bound to `thisArg` and invoked with five arguments:
* (objectValue, sourceValue, key, object, source).
*
* **Note:** This method mutates `object` and is based on
* [`Object.assign`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.assign).
*
*
* @static
* @memberOf _
* @alias extend
* @category Object
* @param {Object} object The destination object.
* @param {...Object} [sources] The source objects.
* @param {Function} [customizer] The function to customize assigning values.
* @param {Function} [customizer] The function to customize assigned values.
* @param {*} [thisArg] The `this` binding of `customizer`.
* @returns {Object} Returns `object`.
* @example
@@ -23,13 +27,17 @@ define(['../internal/baseAssign', '../internal/createAssigner'], function(baseAs
*
* // using a customizer callback
* var defaults = _.partialRight(_.assign, function(value, other) {
* return typeof value == 'undefined' ? other : value;
* return _.isUndefined(value) ? other : value;
* });
*
* defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' });
* // => { 'user': 'barney', 'age': 36 }
*/
var assign = createAssigner(baseAssign);
var assign = createAssigner(function(object, source, customizer) {
return customizer
? assignWith(object, source, customizer)
: baseAssign(object, source);
});
return assign;
});

View File

@@ -1,4 +1,4 @@
define(['../internal/baseCopy', '../internal/baseCreate', '../internal/isIterateeCall', './keys'], function(baseCopy, baseCreate, isIterateeCall, keys) {
define(['../internal/baseAssign', '../internal/baseCreate', '../internal/isIterateeCall'], function(baseAssign, baseCreate, isIterateeCall) {
/**
* Creates an object that inherits from the given `prototype` object. If a
@@ -39,7 +39,7 @@ define(['../internal/baseCopy', '../internal/baseCreate', '../internal/isIterate
if (guard && isIterateeCall(prototype, properties, guard)) {
properties = null;
}
return properties ? baseCopy(properties, result, keys(properties)) : result;
return properties ? baseAssign(result, properties) : result;
}
return create;

View File

@@ -8,6 +8,8 @@ define(['./assign', '../internal/assignDefaults', '../function/restParam'], func
* object for all destination properties that resolve to `undefined`. Once a
* property is set, additional values of the same property are ignored.
*
* **Note:** This method mutates `object`.
*
* @static
* @memberOf _
* @category Object

View File

@@ -3,7 +3,7 @@ define(['../internal/baseFor', '../internal/createForIn'], function(baseFor, cre
/**
* Iterates over own and inherited enumerable properties of an object invoking
* `iteratee` for each property. The `iteratee` is bound to `thisArg` and invoked
* with three arguments: (value, key, object). Iterator functions may exit
* with three arguments: (value, key, object). Iteratee functions may exit
* iteration early by explicitly returning `false`.
*
* @static

View File

@@ -3,7 +3,7 @@ define(['../internal/baseForOwn', '../internal/createForOwn'], function(baseForO
/**
* Iterates over own enumerable properties of an object invoking `iteratee`
* for each property. The `iteratee` is bound to `thisArg` and invoked with
* three arguments: (value, key, object). Iterator functions may exit iteration
* three arguments: (value, key, object). Iteratee functions may exit iteration
* early by explicitly returning `false`.
*
* @static

36
object/get.js Normal file
View File

@@ -0,0 +1,36 @@
define(['../internal/baseGet', '../internal/toPath'], function(baseGet, toPath) {
/** Used as a safe reference for `undefined` in pre-ES5 environments. */
var undefined;
/**
* Gets the property value of `path` on `object`. If the resolved value is
* `undefined` the `defaultValue` is used in its place.
*
* @static
* @memberOf _
* @category Object
* @param {Object} object The object to query.
* @param {Array|string} path The path of the property to get.
* @param {*} [defaultValue] The value returned if the resolved value is `undefined`.
* @returns {*} Returns the resolved value.
* @example
*
* var object = { 'a': [{ 'b': { 'c': 3 } }] };
*
* _.get(object, 'a[0].b.c');
* // => 3
*
* _.get(object, ['a', '0', 'b', 'c']);
* // => 3
*
* _.get(object, 'a.b.c', 'default');
* // => 'default'
*/
function get(object, path, defaultValue) {
var result = object == null ? undefined : baseGet(object, toPath(path), path + '');
return result === undefined ? defaultValue : result;
}
return get;
});

View File

@@ -1,4 +1,4 @@
define([], function() {
define(['../internal/baseGet', '../internal/baseSlice', '../internal/isKey', '../array/last', '../internal/toPath'], function(baseGet, baseSlice, isKey, last, toPath) {
/** Used for native method references. */
var objectProto = Object.prototype;
@@ -7,24 +7,39 @@ define([], function() {
var hasOwnProperty = objectProto.hasOwnProperty;
/**
* Checks if `key` exists as a direct property of `object` instead of an
* inherited property.
* Checks if `path` is a direct property.
*
* @static
* @memberOf _
* @category Object
* @param {Object} object The object to inspect.
* @param {string} key The key to check.
* @returns {boolean} Returns `true` if `key` is a direct property, else `false`.
* @param {Object} object The object to query.
* @param {Array|string} path The path to check.
* @returns {boolean} Returns `true` if `path` is a direct property, else `false`.
* @example
*
* var object = { 'a': 1, 'b': 2, 'c': 3 };
* var object = { 'a': { 'b': { 'c': 3 } } };
*
* _.has(object, 'b');
* _.has(object, 'a');
* // => true
*
* _.has(object, 'a.b.c');
* // => true
*
* _.has(object, ['a', 'b', 'c']);
* // => true
*/
function has(object, key) {
return object ? hasOwnProperty.call(object, key) : false;
function has(object, path) {
if (object == null) {
return false;
}
var result = hasOwnProperty.call(object, path);
if (!result && !isKey(path)) {
path = toPath(path);
object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
path = last(path);
result = object != null && hasOwnProperty.call(object, path);
}
return result;
}
return has;

View File

@@ -13,7 +13,7 @@ define(['../internal/isLength', '../lang/isNative', '../lang/isObject', '../inte
* @static
* @memberOf _
* @category Object
* @param {Object} object The object to inspect.
* @param {Object} object The object to query.
* @returns {Array} Returns the array of property names.
* @example
*
@@ -36,7 +36,7 @@ define(['../internal/isLength', '../lang/isNative', '../lang/isObject', '../inte
length = object.length;
}
if ((typeof Ctor == 'function' && Ctor.prototype === object) ||
(typeof object != 'function' && (length && isLength(length)))) {
(typeof object != 'function' && isLength(length))) {
return shimKeys(object);
}
return isObject(object) ? nativeKeys(object) : [];

View File

@@ -14,7 +14,7 @@ define(['../lang/isArguments', '../lang/isArray', '../internal/isIndex', '../int
* @static
* @memberOf _
* @category Object
* @param {Object} object The object to inspect.
* @param {Object} object The object to query.
* @returns {Array} Returns the array of property names.
* @example
*

View File

@@ -14,7 +14,7 @@ define(['../internal/baseMerge', '../internal/createAssigner'], function(baseMer
* @category Object
* @param {Object} object The destination object.
* @param {...Object} [sources] The source objects.
* @param {Function} [customizer] The function to customize merging properties.
* @param {Function} [customizer] The function to customize assigned values.
* @param {*} [thisArg] The `this` binding of `customizer`.
* @returns {Object} Returns `object`.
* @example

View File

@@ -7,7 +7,7 @@ define(['./keys'], function(keys) {
* @static
* @memberOf _
* @category Object
* @param {Object} object The object to inspect.
* @param {Object} object The object to query.
* @returns {Array} Returns the new array of key-value pairs.
* @example
*

View File

@@ -1,44 +1,47 @@
define(['../lang/isFunction'], function(isFunction) {
define(['../internal/baseGet', '../internal/baseSlice', '../lang/isFunction', '../internal/isKey', '../array/last', '../internal/toPath'], function(baseGet, baseSlice, isFunction, isKey, last, toPath) {
/** Used as a safe reference for `undefined` in pre-ES5 environments. */
var undefined;
/**
* Resolves the value of property `key` on `object`. If the value of `key` is
* a function it is invoked with the `this` binding of `object` and its result
* is returned, else the property value is returned. If the property value is
* `undefined` the `defaultValue` is used in its place.
* This method is like `_.get` except that if the resolved value is a function
* it is invoked with the `this` binding of its parent object and its result
* is returned.
*
* @static
* @memberOf _
* @category Object
* @param {Object} object The object to query.
* @param {string} key The key of the property to resolve.
* @param {*} [defaultValue] The value returned if the property value
* resolves to `undefined`.
* @param {Array|string} path The path of the property to resolve.
* @param {*} [defaultValue] The value returned if the resolved value is `undefined`.
* @returns {*} Returns the resolved value.
* @example
*
* var object = { 'user': 'fred', 'age': _.constant(40) };
* var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };
*
* _.result(object, 'user');
* // => 'fred'
* _.result(object, 'a[0].b.c1');
* // => 3
*
* _.result(object, 'age');
* // => 40
* _.result(object, 'a[0].b.c2');
* // => 4
*
* _.result(object, 'status', 'busy');
* // => 'busy'
* _.result(object, 'a.b.c', 'default');
* // => 'default'
*
* _.result(object, 'status', _.constant('busy'));
* // => 'busy'
* _.result(object, 'a.b.c', _.constant('default'));
* // => 'default'
*/
function result(object, key, defaultValue) {
var value = object == null ? undefined : object[key];
if (typeof value == 'undefined') {
value = defaultValue;
function result(object, path, defaultValue) {
var result = object == null ? undefined : object[path];
if (result === undefined) {
if (object != null && !isKey(path, object)) {
path = toPath(path);
object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
result = object == null ? undefined : object[last(path)];
}
result = result === undefined ? defaultValue : result;
}
return isFunction(value) ? value.call(object) : value;
return isFunction(result) ? result.call(object) : result;
}
return result;

53
object/set.js Normal file
View File

@@ -0,0 +1,53 @@
define(['../internal/isIndex', '../internal/isKey', '../lang/isObject', '../internal/toPath'], function(isIndex, isKey, isObject, toPath) {
/**
* Sets the property value of `path` on `object`. If a portion of `path`
* does not exist it is created.
*
* @static
* @memberOf _
* @category Object
* @param {Object} object The object to augment.
* @param {Array|string} path The path of the property to set.
* @param {*} value The value to set.
* @returns {Object} Returns `object`.
* @example
*
* var object = { 'a': [{ 'b': { 'c': 3 } }] };
*
* _.set(object, 'a[0].b.c', 4);
* console.log(object.a[0].b.c);
* // => 4
*
* _.set(object, 'x[0].y.z', 5);
* console.log(object.x[0].y.z);
* // => 5
*/
function set(object, path, value) {
if (object == null) {
return object;
}
var pathKey = (path + '');
path = (object[pathKey] != null || isKey(path, object)) ? [pathKey] : toPath(path);
var index = -1,
length = path.length,
endIndex = length - 1,
nested = object;
while (nested != null && ++index < length) {
var key = path[index];
if (isObject(nested)) {
if (index == endIndex) {
nested[key] = value;
} else if (nested[key] == null) {
nested[key] = isIndex(path[index + 1]) ? [] : {};
}
}
nested = nested[key];
}
return object;
}
return set;
});

View File

@@ -5,7 +5,7 @@ define(['../internal/arrayEach', '../internal/baseCallback', '../internal/baseCr
* `accumulator` object which is the result of running each of its own enumerable
* properties through `iteratee`, with each invocation potentially mutating
* the `accumulator` object. The `iteratee` is bound to `thisArg` and invoked
* with four arguments: (accumulator, value, key, object). Iterator functions
* with four arguments: (accumulator, value, key, object). Iteratee functions
* may exit iteration early by explicitly returning `false`.
*
* @static