mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-12 03:47:50 +00:00
Optimize isKey.
This commit is contained in:
@@ -89,6 +89,7 @@
|
|||||||
|
|
||||||
/** Used to match property names within property paths. */
|
/** Used to match property names within property paths. */
|
||||||
var reIsDeepProp = /\.|\[(?:[^[\]]+|(["'])(?:(?!\1)[^\n\\]|\\.)*?)\1\]/,
|
var reIsDeepProp = /\.|\[(?:[^[\]]+|(["'])(?:(?!\1)[^\n\\]|\\.)*?)\1\]/,
|
||||||
|
reIsPlainProp = /^\w*$/,
|
||||||
rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\n\\]|\\.)*?)\2)\]/g;
|
rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\n\\]|\\.)*?)\2)\]/g;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -4330,6 +4331,10 @@
|
|||||||
* @returns {boolean} Returns `true` if `value` is a property name, else `false`.
|
* @returns {boolean} Returns `true` if `value` is a property name, else `false`.
|
||||||
*/
|
*/
|
||||||
function isKey(value, object) {
|
function isKey(value, object) {
|
||||||
|
var type = typeof value;
|
||||||
|
if ((type == 'string' && reIsPlainProp.test(value)) || type == 'number') {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (isArray(value)) {
|
if (isArray(value)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user