@iterable-iterator/range

2.1.0 • Public • Published

⛰️ @iterable-iterator/range

A range function for JavaScript. See docs.

⚠️ Depending on your environment, the code may require regeneratorRuntime to be defined, for instance by importing regenerator-runtime/runtime.

import {range} from '@iterable-iterator/range';
range( 3 ) ; // 0 1 2
range( 2 , 5 ) ; // 2 3 4
range( 5 , 2 , -1 ) ; // 5 4 3

range(Number.MAX_SAFE_INTEGER).has(1234); // true
range(0, 10, 2).get(3); // 6

// If you only use the iterator feature you can save bytes by calling the
// IterableIterator function directly
import {forwardRangeIterator, backwardRangeIterator} from '@iterable-iterator/range';

for (const x of forwardRangeIterator(0, 10, 1)) ...
for (const x of backwardRangeIterator(10, 0, -1)) ...
// caveat: This requires you to specify all parameters, and choose the correct
// implementation depending on the sign of the `step` parameter.

// For convenience, rangeIterator will return the correct kind of
// IterableIterator without constructing a Range object. It has the same signature
// as the range function.
import {rangeIterator as range} from '@iterable-iterator/range';

License Version Tests Dependencies Dev dependencies GitHub issues Downloads

Code issues Code maintainability Code coverage (cov) Code technical debt Documentation Package size

Package Sidebar

Install

npm i @iterable-iterator/range

Weekly Downloads

36

Version

2.1.0

License

AGPL-3.0

Unpacked Size

505 kB

Total Files

14

Last publish

Collaborators

  • raskat
  • aureooms