-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
41 lines (37 loc) · 1000 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
'use strict';
var hasOwn = require('hasown');
var gOPD = require('gopd');
var isObject = function (val) {
return val !== null && typeof val === 'object' && !Array.isArray(val);
};
module.exports = function isDataDescriptor(obj, key) {
if (!isObject(obj)) {
return false;
}
var desc = arguments.length > 1 ? gOPD(obj, key) : obj;
if (isObject(desc)) {
if (
!hasOwn(desc, 'value')
|| hasOwn(desc, 'get')
|| hasOwn(desc, 'set')
|| (hasOwn(desc, 'configurable') && typeof desc.configurable !== 'boolean')
|| (hasOwn(desc, 'enumerable') && typeof desc.enumerable !== 'boolean')
|| (hasOwn(desc, 'writable') && typeof desc.writable !== 'boolean')
) {
return false;
}
for (var descKey in desc) { // eslint-disable-line no-restricted-syntax
if (
hasOwn(desc, descKey)
&& descKey !== 'configurable'
&& descKey !== 'enumerable'
&& descKey !== 'writable'
&& descKey !== 'value'
) {
return false;
}
}
return true;
}
return false;
};