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

39 lines
888 B
JavaScript
Raw Normal View History

2020-01-28 13:07:56 +08:00
/*!
* define-property <https://github.com/jonschlinkert/define-property>
*
2020-03-22 05:13:25 +08:00
* Copyright (c) 2015-2018, Jon Schlinkert.
* Released under the MIT License.
2020-01-28 13:07:56 +08:00
*/
'use strict';
2020-03-22 05:13:25 +08:00
var isobject = require('isobject');
2020-01-28 13:07:56 +08:00
var isDescriptor = require('is-descriptor');
2020-03-22 05:13:25 +08:00
var define = (typeof Reflect !== 'undefined' && Reflect.defineProperty)
? Reflect.defineProperty
: Object.defineProperty;
2020-01-28 13:07:56 +08:00
2020-03-22 05:13:25 +08:00
module.exports = function defineProperty(obj, key, val) {
if (!isobject(obj) && typeof obj !== 'function' && !Array.isArray(obj)) {
throw new TypeError('expected an object, function, or array');
2020-01-28 13:07:56 +08:00
}
2020-03-22 05:13:25 +08:00
if (typeof key !== 'string') {
throw new TypeError('expected "key" to be a string');
2020-01-28 13:07:56 +08:00
}
2020-03-22 05:13:25 +08:00
if (isDescriptor(val)) {
define(obj, key, val);
return obj;
2020-01-28 13:07:56 +08:00
}
2020-03-22 05:13:25 +08:00
define(obj, key, {
2020-01-28 13:07:56 +08:00
configurable: true,
enumerable: false,
writable: true,
value: val
});
2020-03-22 05:13:25 +08:00
return obj;
2020-01-28 13:07:56 +08:00
};