npm.io
0.1.1 • Published 2 years ago

@webreflection/range

Licence
MIT
Version
0.1.1
Deps
0
Size
4 kB
Vulns
0
Weekly
9
Stars
13

@webreflection/range

build status Coverage Status

A Pythonic range(start[, stop[, steps = 1]]) function that works in both for / of and with value in range(...) operations.

import range from '@webreflection/range';

for (const i of range(0, 3))
  console.log(i); // 0, 1, 2

if (1 in range(0, 2))
  console.log('1 is in range [0, 1, 2]');

API

  • range(3) is equivalent of range(0, 3) and yields [0, 1, 2]
  • range(3, 5) will yield [3, 4]
  • range(0, 5, 2) will yield [0, 2, 4];
  • 1 in range(0, 2) will be true but 2 in range(0, 2) will be false
  • [...range(0, 3)] is valid as for (const i of range(0, 3));

That's it.