github-pages-deploy-action/node_modules/define-property/index.js

32 lines
753 B
JavaScript
Raw Normal View History

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