-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
55 lines (48 loc) · 1.19 KB
/
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
'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 isAccessorDescriptor(obj, key, checkProto) {
if (!isObject(obj)) {
return false;
}
if (arguments.length > 1) {
var hasKey = hasOwn(obj, key);
if (!hasKey && checkProto !== false) {
return isAccessorDescriptor(obj.constructor.prototype, key, false);
}
return gOPD ? isAccessorDescriptor(gOPD(obj, key)) : hasKey;
}
var desc = obj;
if (
!hasOwn(desc, 'get')
|| !hasOwn(desc, 'set')
|| !hasOwn(desc, 'enumerable')
|| !hasOwn(desc, 'configurable')
) {
return false;
}
for (var descKey in desc) { // eslint-disable-line no-restricted-syntax
if (hasOwn(desc, descKey)) {
if (
descKey !== 'get'
&& descKey !== 'set'
&& descKey !== 'enumerable'
&& descKey !== 'configurable'
) {
return false;
}
var val = desc[descKey];
if (descKey === 'get' || descKey === 'set') {
if (typeof val !== 'undefined' && typeof val !== 'function') {
return false;
}
} else if (typeof val !== 'boolean') {
return false;
}
}
}
return true;
};