blob: d4d09c92a7eb04ecc1dde77df0edcea0460448d7 [file] [log] [blame]
Leo Repp58b9f112021-11-22 11:57:47 +01001/*!
2 * is-data-descriptor <https://github.com/jonschlinkert/is-data-descriptor>
3 *
4 * Copyright (c) 2015, Jon Schlinkert.
5 * Licensed under the MIT License.
6 */
7
8'use strict';
9
10var typeOf = require('kind-of');
11
12// data descriptor properties
13var data = {
14 configurable: 'boolean',
15 enumerable: 'boolean',
16 writable: 'boolean'
17};
18
19function isDataDescriptor(obj, prop) {
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}
50
51/**
52 * Expose `isDataDescriptor`
53 */
54
55module.exports = isDataDescriptor;