-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
43 lines (37 loc) · 984 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
42
43
'use strict';
var gOPD = require('gopd');
var hasOwn = require('hasown');
var isDataDescriptor = require('is-data-descriptor');
var isAccessorDescriptor = require('is-accessor-descriptor');
var isObject = function (val) {
return val !== null && typeof val === 'object';
};
module.exports = function isDescriptor(obj, key, checkProto) {
if (!isObject(obj)) {
return false;
}
var desc;
if (arguments.length > 1) {
if (gOPD) {
desc = gOPD(obj, key);
if (desc) {
return isDescriptor(desc);
}
return checkProto !== false
&& obj.contructor
&& isDescriptor(gOPD(obj.constructor.prototype, key));
}
if (hasOwn(obj, key)) {
return true;
}
if (checkProto !== false && obj.constructor) {
return hasOwn(obj.constructor.prototype, key);
}
return false;
}
desc = obj;
if (typeof desc.configurable !== 'boolean' || typeof desc.enumerable !== 'boolean') {
return false;
}
return isDataDescriptor(desc) || isAccessorDescriptor(desc);
};