index.js 774 B

123456789101112131415161718192021222324252627
  1. 'use strict';
  2. var GetIntrinsic = require('get-intrinsic');
  3. var $defineProperty = GetIntrinsic('%Object.defineProperty%', true);
  4. var hasToStringTag = require('has-tostringtag/shams')();
  5. var hasOwn = require('hasown');
  6. var toStringTag = hasToStringTag ? Symbol.toStringTag : null;
  7. /** @type {import('.')} */
  8. module.exports = function setToStringTag(object, value) {
  9. var overrideIfSet = arguments.length > 2 && arguments[2] && arguments[2].force;
  10. if (toStringTag && (overrideIfSet || !hasOwn(object, toStringTag))) {
  11. if ($defineProperty) {
  12. $defineProperty(object, toStringTag, {
  13. configurable: true,
  14. enumerable: false,
  15. value: value,
  16. writable: false
  17. });
  18. } else {
  19. object[toStringTag] = value; // eslint-disable-line no-param-reassign
  20. }
  21. }
  22. };