mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-11 11:27:50 +00:00
Cleanup path methods.
This commit is contained in:
@@ -2538,7 +2538,7 @@
|
|||||||
function baseMatchesProperty(path, value) {
|
function baseMatchesProperty(path, value) {
|
||||||
var isArr = isArray(path),
|
var isArr = isArray(path),
|
||||||
isCommon = isKey(path) && isStrictComparable(value),
|
isCommon = isKey(path) && isStrictComparable(value),
|
||||||
pathKey = isArr ? undefined : (path + '');
|
pathKey = (path + '');
|
||||||
|
|
||||||
path = toPath(path);
|
path = toPath(path);
|
||||||
return function(object) {
|
return function(object) {
|
||||||
@@ -2688,7 +2688,7 @@
|
|||||||
* @returns {Function} Returns the new function.
|
* @returns {Function} Returns the new function.
|
||||||
*/
|
*/
|
||||||
function basePropertyDeep(path) {
|
function basePropertyDeep(path) {
|
||||||
var pathKey = isArray(path) ? undefined : (path + '');
|
var pathKey = (path + '');
|
||||||
path = toPath(path);
|
path = toPath(path);
|
||||||
return function(object) {
|
return function(object) {
|
||||||
return baseGet(object, path, pathKey);
|
return baseGet(object, path, pathKey);
|
||||||
@@ -9573,9 +9573,7 @@
|
|||||||
* // => 'default'
|
* // => 'default'
|
||||||
*/
|
*/
|
||||||
function get(object, path, defaultValue) {
|
function get(object, path, defaultValue) {
|
||||||
var pathKey = isArray(path) ? undefined : (path + ''),
|
var result = object == null ? undefined : baseGet(object, toPath(path), path + '');
|
||||||
result = baseGet(object, toPath(path), pathKey);
|
|
||||||
|
|
||||||
return result === undefined ? defaultValue : result;
|
return result === undefined ? defaultValue : result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -9605,9 +9603,7 @@
|
|||||||
if (object == null) {
|
if (object == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
var pathKey = isArray(path) ? undefined : (path + ''),
|
var result = hasOwnProperty.call(object, path);
|
||||||
result = pathKey !== undefined && hasOwnProperty.call(object, path);
|
|
||||||
|
|
||||||
if (!result && !isKey(path)) {
|
if (!result && !isKey(path)) {
|
||||||
path = toPath(path);
|
path = toPath(path);
|
||||||
object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
|
object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
|
||||||
@@ -10020,14 +10016,14 @@
|
|||||||
* // => 'default'
|
* // => 'default'
|
||||||
*/
|
*/
|
||||||
function result(object, path, defaultValue) {
|
function result(object, path, defaultValue) {
|
||||||
if (object != null && !isKey(path, object)) {
|
|
||||||
path = toPath(path);
|
|
||||||
object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
|
|
||||||
path = last(path);
|
|
||||||
}
|
|
||||||
var result = object == null ? undefined : toObject(object)[path];
|
var result = object == null ? undefined : toObject(object)[path];
|
||||||
if (result === undefined) {
|
if (result === undefined) {
|
||||||
result = defaultValue;
|
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(result) ? result.call(object) : result;
|
return isFunction(result) ? result.call(object) : result;
|
||||||
}
|
}
|
||||||
@@ -10056,6 +10052,14 @@
|
|||||||
* // => 5
|
* // => 5
|
||||||
*/
|
*/
|
||||||
function set(object, path, value) {
|
function set(object, path, value) {
|
||||||
|
if (object == null) {
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
var pathKey = (path + '');
|
||||||
|
if (pathKey in toObject(object)) {
|
||||||
|
object[pathKey] = value;
|
||||||
|
return object;
|
||||||
|
}
|
||||||
path = isKey(path, object) ? [path] : toPath(path);
|
path = isKey(path, object) ? [path] : toPath(path);
|
||||||
|
|
||||||
var index = -1,
|
var index = -1,
|
||||||
@@ -11560,8 +11564,7 @@
|
|||||||
*/
|
*/
|
||||||
function propertyOf(object) {
|
function propertyOf(object) {
|
||||||
return function(path) {
|
return function(path) {
|
||||||
var pathKey = isArray(path) ? undefined : (path + '');
|
return baseGet(object, toPath(path), path + '');
|
||||||
return baseGet(object, toPath(path), pathKey);
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user