timepiece/node_modules/is-data-descriptor/index.js

44 lines
806 B
JavaScript
Raw Normal View History

2024-05-14 14:54:12 +00:00
'use strict';
var hasOwn = require('hasown');
// data descriptor properties
var data = {
__proto__: null,
configurable: 'boolean',
enumerable: 'boolean',
writable: 'boolean',
};
module.exports = function isDataDescriptor(obj, prop) {
if (!obj || typeof obj !== 'object') {
return false;
}
if (typeof prop === 'string') {
var val = Object.getOwnPropertyDescriptor(obj, prop);
return typeof val !== 'undefined';
}
if (
(!('value' in obj) && !('writable' in obj))
|| 'get' in obj
|| 'set' in obj
) {
return false;
}
for (var key in obj) { // eslint-disable-line no-restricted-syntax
if (
key !== 'value'
&& hasOwn(obj, key)
&& hasOwn(data, key)
&& typeof obj[key] !== data[key]
&& typeof obj[key] !== 'undefined'
) {
return false;
}
}
return true;
};