index.js 589 B

12345678910111213141516171819202122
  1. 'use strict';
  2. var hasOwn = require('hasown');
  3. var hasUnscopables = typeof Symbol === 'function' && typeof Symbol.unscopables === 'symbol';
  4. var map = hasUnscopables && Array.prototype[Symbol.unscopables];
  5. var $TypeError = TypeError;
  6. /** @type {import('.')} */
  7. module.exports = function shimUnscopables(method) {
  8. if (typeof method !== 'string' || !method) {
  9. throw new $TypeError('method must be a non-empty string');
  10. }
  11. if (!hasOwn(Array.prototype, method)) {
  12. throw new $TypeError('method must be on Array.prototype');
  13. }
  14. if (hasUnscopables && map) {
  15. map[method] = true;
  16. }
  17. };