index.js 888 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /*!
  2. * define-property <https://github.com/jonschlinkert/define-property>
  3. *
  4. * Copyright (c) 2015-2018, Jon Schlinkert.
  5. * Released under the MIT License.
  6. */
  7. 'use strict';
  8. var isobject = require('isobject');
  9. var isDescriptor = require('is-descriptor');
  10. var define = (typeof Reflect !== 'undefined' && Reflect.defineProperty)
  11. ? Reflect.defineProperty
  12. : Object.defineProperty;
  13. module.exports = function defineProperty(obj, key, val) {
  14. if (!isobject(obj) && typeof obj !== 'function' && !Array.isArray(obj)) {
  15. throw new TypeError('expected an object, function, or array');
  16. }
  17. if (typeof key !== 'string') {
  18. throw new TypeError('expected "key" to be a string');
  19. }
  20. if (isDescriptor(val)) {
  21. define(obj, key, val);
  22. return obj;
  23. }
  24. define(obj, key, {
  25. configurable: true,
  26. enumerable: false,
  27. writable: true,
  28. value: val
  29. });
  30. return obj;
  31. };