mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-29 14:37:49 +00:00
27 lines
809 B
JavaScript
27 lines
809 B
JavaScript
import isArray from './isArray';
|
|
import isSymbol from './isSymbol';
|
|
|
|
/** 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) {
|
|
var type = typeof value;
|
|
if (type == 'number' || type == 'symbol') {
|
|
return true;
|
|
}
|
|
return !isArray(value) &&
|
|
(isSymbol(value) || reIsPlainProp.test(value) || !reIsDeepProp.test(value) ||
|
|
(object != null && value in Object(object)));
|
|
}
|
|
|
|
export default isKey;
|