You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
878 B
29 lines
878 B
import isArray from './isArray.js'; |
|
import isSymbol from './isSymbol.js'; |
|
|
|
/** Used to match property names within property paths. */ |
|
var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/, |
|
reIsPlainProp = /^\w*$/; |
|
|
|
/** |
|
* Checks if `value` is a property name and not a property path. |
|
* |
|
* @private |
|
* @param {*} value The value to check. |
|
* @param {Object} [object] The object to query keys on. |
|
* @returns {boolean} Returns `true` if `value` is a property name, else `false`. |
|
*/ |
|
function isKey(value, object) { |
|
if (isArray(value)) { |
|
return false; |
|
} |
|
var type = typeof value; |
|
if (type == 'number' || type == 'symbol' || type == 'boolean' || |
|
value == null || isSymbol(value)) { |
|
return true; |
|
} |
|
return reIsPlainProp.test(value) || !reIsDeepProp.test(value) || |
|
(object != null && value in Object(object)); |
|
} |
|
|
|
export default isKey;
|
|
|