1
|
/*!
|
2
|
* is-data-descriptor <https://github.com/jonschlinkert/is-data-descriptor>
|
3
|
*
|
4
|
* Copyright (c) 2015-2017, Jon Schlinkert.
|
5
|
* Released under the MIT License.
|
6
|
*/
|
7
|
|
8
|
'use strict';
|
9
|
|
10
|
var typeOf = require('kind-of');
|
11
|
|
12
|
module.exports = function isDataDescriptor(obj, prop) {
|
13
|
// data descriptor properties
|
14
|
var data = {
|
15
|
configurable: 'boolean',
|
16
|
enumerable: 'boolean',
|
17
|
writable: 'boolean'
|
18
|
};
|
19
|
|
20
|
if (typeOf(obj) !== 'object') {
|
21
|
return false;
|
22
|
}
|
23
|
|
24
|
if (typeof prop === 'string') {
|
25
|
var val = Object.getOwnPropertyDescriptor(obj, prop);
|
26
|
return typeof val !== 'undefined';
|
27
|
}
|
28
|
|
29
|
if (!('value' in obj) && !('writable' in obj)) {
|
30
|
return false;
|
31
|
}
|
32
|
|
33
|
for (var key in obj) {
|
34
|
if (key === 'value') continue;
|
35
|
|
36
|
if (!data.hasOwnProperty(key)) {
|
37
|
continue;
|
38
|
}
|
39
|
|
40
|
if (typeOf(obj[key]) === data[key]) {
|
41
|
continue;
|
42
|
}
|
43
|
|
44
|
if (typeof obj[key] !== 'undefined') {
|
45
|
return false;
|
46
|
}
|
47
|
}
|
48
|
return true;
|
49
|
};
|