Bump to v4.7.0.

This commit is contained in:
John-David Dalton
2016-03-25 23:47:49 -07:00
parent 501d6b1d41
commit 18d0f1d873
419 changed files with 4042 additions and 2066 deletions

View File

@@ -1,20 +1,19 @@
var baseCastPath = require('./_baseCastPath'),
get = require('./get'),
isFunction = require('./isFunction'),
isKey = require('./_isKey'),
parent = require('./_parent');
isKey = require('./_isKey');
/**
* This method is like `_.get` except that if the resolved value is a function
* it's invoked with the `this` binding of its parent object and its result
* is returned.
* This method is like `_.get` except that if the resolved value is a
* function it's invoked with the `this` binding of its parent object and
* its result is returned.
*
* @static
* @since 0.1.0
* @memberOf _
* @category Object
* @param {Object} object The object to query.
* @param {Array|string} path The path of the property to resolve.
* @param {*} [defaultValue] The value returned if the resolved value is `undefined`.
* @param {*} [defaultValue] The value returned for `undefined` resolved values.
* @returns {*} Returns the resolved value.
* @example
*
@@ -33,17 +32,25 @@ var baseCastPath = require('./_baseCastPath'),
* // => 'default'
*/
function result(object, path, defaultValue) {
if (!isKey(path, object)) {
path = baseCastPath(path);
var result = get(object, path);
object = parent(object, path);
} else {
result = object == null ? undefined : object[path];
path = isKey(path, object) ? [path] : baseCastPath(path);
var index = -1,
length = path.length;
// Ensure the loop is entered when path is empty.
if (!length) {
object = undefined;
length = 1;
}
if (result === undefined) {
result = defaultValue;
while (++index < length) {
var value = object == null ? undefined : object[path[index]];
if (value === undefined) {
index = length;
value = defaultValue;
}
object = isFunction(value) ? value.call(object) : value;
}
return isFunction(result) ? result.call(object) : result;
return object;
}
module.exports = result;