|
Last change
on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago |
|
Added visualizations
|
-
Property mode
set to
100644
|
|
File size:
576 bytes
|
| Line | |
|---|
| 1 | import { isSymbol } from '../predicate/isSymbol.mjs';
|
|---|
| 2 |
|
|---|
| 3 | const regexIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/;
|
|---|
| 4 | const regexIsPlainProp = /^\w*$/;
|
|---|
| 5 | function isKey(value, object) {
|
|---|
| 6 | if (Array.isArray(value)) {
|
|---|
| 7 | return false;
|
|---|
| 8 | }
|
|---|
| 9 | if (typeof value === 'number' || typeof value === 'boolean' || value == null || isSymbol(value)) {
|
|---|
| 10 | return true;
|
|---|
| 11 | }
|
|---|
| 12 | return ((typeof value === 'string' && (regexIsPlainProp.test(value) || !regexIsDeepProp.test(value))) ||
|
|---|
| 13 | (object != null && Object.hasOwn(object, value)));
|
|---|
| 14 | }
|
|---|
| 15 |
|
|---|
| 16 | export { isKey };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.