wishthis/node_modules/define-property/index.js

32 lines
753 B
JavaScript
Raw Normal View History

2022-01-21 08:28:41 +00:00
/*!
* define-property <https://github.com/jonschlinkert/define-property>
*
2022-04-08 10:55:35 +00:00
* Copyright (c) 2015, Jon Schlinkert.
* Licensed under the MIT License.
2022-01-21 08:28:41 +00:00
*/
'use strict';
var isDescriptor = require('is-descriptor');
2022-04-08 10:55:35 +00:00
module.exports = function defineProperty(obj, prop, val) {
if (typeof obj !== 'object' && typeof obj !== 'function') {
throw new TypeError('expected an object or function.');
2022-01-21 08:28:41 +00:00
}
2022-04-08 10:55:35 +00:00
if (typeof prop !== 'string') {
throw new TypeError('expected `prop` to be a string.');
2022-01-21 08:28:41 +00:00
}
2022-04-08 10:55:35 +00:00
if (isDescriptor(val) && ('set' in val || 'get' in val)) {
return Object.defineProperty(obj, prop, val);
2022-01-21 08:28:41 +00:00
}
2022-04-08 10:55:35 +00:00
return Object.defineProperty(obj, prop, {
2022-01-21 08:28:41 +00:00
configurable: true,
enumerable: false,
writable: true,
value: val
});
};