esnext.iterator.range.js 671 B

12345678910111213141516
  1. 'use strict';
  2. /* eslint-disable es/no-bigint -- safe */
  3. var $ = require('../internals/export');
  4. var NumericRangeIterator = require('../internals/numeric-range-iterator');
  5. var $TypeError = TypeError;
  6. // `Iterator.range` method
  7. // https://github.com/tc39/proposal-Number.range
  8. $({ target: 'Iterator', stat: true, forced: true }, {
  9. range: function range(start, end, option) {
  10. if (typeof start == 'number') return new NumericRangeIterator(start, end, option, 'number', 0, 1);
  11. if (typeof start == 'bigint') return new NumericRangeIterator(start, end, option, 'bigint', BigInt(0), BigInt(1));
  12. throw new $TypeError('Incorrect Iterator.range arguments');
  13. }
  14. });