index.js 546 B

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