mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 18:37:50 +00:00
Use toKey in more functions.
This commit is contained in:
42
lodash.js
42
lodash.js
@@ -2662,7 +2662,7 @@
|
|||||||
length = path.length;
|
length = path.length;
|
||||||
|
|
||||||
while (object != null && index < length) {
|
while (object != null && index < length) {
|
||||||
object = object[path[index++]];
|
object = object[toKey(path[index++])];
|
||||||
}
|
}
|
||||||
return (index && index == length) ? object : undefined;
|
return (index && index == length) ? object : undefined;
|
||||||
}
|
}
|
||||||
@@ -2835,7 +2835,7 @@
|
|||||||
object = parent(object, path);
|
object = parent(object, path);
|
||||||
path = last(path);
|
path = last(path);
|
||||||
}
|
}
|
||||||
var func = object == null ? object : object[path];
|
var func = object == null ? object : object[toKey(path)];
|
||||||
return func == null ? undefined : apply(func, object, args);
|
return func == null ? undefined : apply(func, object, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3095,7 +3095,7 @@
|
|||||||
*/
|
*/
|
||||||
function baseMatchesProperty(path, srcValue) {
|
function baseMatchesProperty(path, srcValue) {
|
||||||
if (isKey(path) && isStrictComparable(srcValue)) {
|
if (isKey(path) && isStrictComparable(srcValue)) {
|
||||||
return matchesStrictComparable(path, srcValue);
|
return matchesStrictComparable(toKey(path), srcValue);
|
||||||
}
|
}
|
||||||
return function(object) {
|
return function(object) {
|
||||||
var objValue = get(object, path);
|
var objValue = get(object, path);
|
||||||
@@ -3309,6 +3309,7 @@
|
|||||||
* @returns {Function} Returns the new function.
|
* @returns {Function} Returns the new function.
|
||||||
*/
|
*/
|
||||||
function baseProperty(key) {
|
function baseProperty(key) {
|
||||||
|
key = toKey(key);
|
||||||
return function(object) {
|
return function(object) {
|
||||||
return object == null ? undefined : object[key];
|
return object == null ? undefined : object[key];
|
||||||
};
|
};
|
||||||
@@ -3387,11 +3388,11 @@
|
|||||||
object = parent(array, path);
|
object = parent(array, path);
|
||||||
|
|
||||||
if (object != null) {
|
if (object != null) {
|
||||||
delete object[last(path)];
|
delete object[toKey(last(path))];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
delete array[index];
|
delete array[toKey(index)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3481,7 +3482,7 @@
|
|||||||
nested = object;
|
nested = object;
|
||||||
|
|
||||||
while (nested != null && ++index < length) {
|
while (nested != null && ++index < length) {
|
||||||
var key = path[index];
|
var key = toKey(path[index]);
|
||||||
if (isObject(nested)) {
|
if (isObject(nested)) {
|
||||||
var newValue = value;
|
var newValue = value;
|
||||||
if (index != lastIndex) {
|
if (index != lastIndex) {
|
||||||
@@ -3709,7 +3710,7 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The base implementation of `_.toString` which doesn't convert nullish
|
* The base implementation of `_.toString` which doesn't convert nullish
|
||||||
* values to empty strings or preserve the sign of `-0`.
|
* values to empty strings.
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
* @param {*} value The value to process.
|
* @param {*} value The value to process.
|
||||||
@@ -3723,7 +3724,8 @@
|
|||||||
if (isSymbol(value)) {
|
if (isSymbol(value)) {
|
||||||
return symbolToString ? symbolToString.call(value) : '';
|
return symbolToString ? symbolToString.call(value) : '';
|
||||||
}
|
}
|
||||||
return (value + '');
|
var result = (value + '');
|
||||||
|
return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -3797,8 +3799,9 @@
|
|||||||
function baseUnset(object, path) {
|
function baseUnset(object, path) {
|
||||||
path = isKey(path, object) ? [path] : castPath(path);
|
path = isKey(path, object) ? [path] : castPath(path);
|
||||||
object = parent(object, path);
|
object = parent(object, path);
|
||||||
var key = last(path);
|
|
||||||
return (object != null && has(object, key)) ? delete object[key] : true;
|
var key = toKey(last(path));
|
||||||
|
return !(object != null && baseHas(object, key)) || delete object[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -5463,7 +5466,7 @@
|
|||||||
length = path.length;
|
length = path.length;
|
||||||
|
|
||||||
while (++index < length) {
|
while (++index < length) {
|
||||||
var key = path[index];
|
var key = toKey(path[index]);
|
||||||
if (!(result = object != null && hasFunc(object, key))) {
|
if (!(result = object != null && hasFunc(object, key))) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -5921,7 +5924,11 @@
|
|||||||
* @returns {string|symbol} Returns the key.
|
* @returns {string|symbol} Returns the key.
|
||||||
*/
|
*/
|
||||||
function toKey(value) {
|
function toKey(value) {
|
||||||
return (typeof value == 'string' || isSymbol(value)) ? value : (value + '');
|
if (typeof value == 'string' || isSymbol(value)) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
var result = (value + '');
|
||||||
|
return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -11717,11 +11724,7 @@
|
|||||||
* // => '1,2,3'
|
* // => '1,2,3'
|
||||||
*/
|
*/
|
||||||
function toString(value) {
|
function toString(value) {
|
||||||
if (value == null) {
|
return value == null ? '' : baseToString(value);
|
||||||
return '';
|
|
||||||
}
|
|
||||||
var result = baseToString(value);
|
|
||||||
return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*------------------------------------------------------------------------*/
|
/*------------------------------------------------------------------------*/
|
||||||
@@ -12730,7 +12733,7 @@
|
|||||||
* // => { 'a': 1, 'c': 3 }
|
* // => { 'a': 1, 'c': 3 }
|
||||||
*/
|
*/
|
||||||
var pick = rest(function(object, props) {
|
var pick = rest(function(object, props) {
|
||||||
return object == null ? {} : basePick(object, baseFlatten(props, 1));
|
return object == null ? {} : basePick(object, arrayMap(baseFlatten(props, 1), toKey));
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -12797,7 +12800,7 @@
|
|||||||
length = 1;
|
length = 1;
|
||||||
}
|
}
|
||||||
while (++index < length) {
|
while (++index < length) {
|
||||||
var value = object == null ? undefined : object[path[index]];
|
var value = object == null ? undefined : object[toKey(path[index])];
|
||||||
if (value === undefined) {
|
if (value === undefined) {
|
||||||
index = length;
|
index = length;
|
||||||
value = defaultValue;
|
value = defaultValue;
|
||||||
@@ -14447,6 +14450,7 @@
|
|||||||
*/
|
*/
|
||||||
var bindAll = rest(function(object, methodNames) {
|
var bindAll = rest(function(object, methodNames) {
|
||||||
arrayEach(baseFlatten(methodNames, 1), function(key) {
|
arrayEach(baseFlatten(methodNames, 1), function(key) {
|
||||||
|
key = toKey(key);
|
||||||
object[key] = bind(object[key], object);
|
object[key] = bind(object[key], object);
|
||||||
});
|
});
|
||||||
return object;
|
return object;
|
||||||
|
|||||||
Reference in New Issue
Block a user