Last change
on this file since eed0bf8 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
880 bytes
|
Rev | Line | |
---|
[6a3a178] | 1 | var isArray = require('./isArray'),
|
---|
| 2 | isSymbol = require('./isSymbol');
|
---|
| 3 |
|
---|
| 4 | /** Used to match property names within property paths. */
|
---|
| 5 | var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
|
---|
| 6 | reIsPlainProp = /^\w*$/;
|
---|
| 7 |
|
---|
| 8 | /**
|
---|
| 9 | * Checks if `value` is a property name and not a property path.
|
---|
| 10 | *
|
---|
| 11 | * @private
|
---|
| 12 | * @param {*} value The value to check.
|
---|
| 13 | * @param {Object} [object] The object to query keys on.
|
---|
| 14 | * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
|
---|
| 15 | */
|
---|
| 16 | function isKey(value, object) {
|
---|
| 17 | if (isArray(value)) {
|
---|
| 18 | return false;
|
---|
| 19 | }
|
---|
| 20 | var type = typeof value;
|
---|
| 21 | if (type == 'number' || type == 'symbol' || type == 'boolean' ||
|
---|
| 22 | value == null || isSymbol(value)) {
|
---|
| 23 | return true;
|
---|
| 24 | }
|
---|
| 25 | return reIsPlainProp.test(value) || !reIsDeepProp.test(value) ||
|
---|
| 26 | (object != null && value in Object(object));
|
---|
| 27 | }
|
---|
| 28 |
|
---|
| 29 | module.exports = isKey;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.