rangey
v1.1.0
Published
A micro NPM module for a shorthand range function (like Python).
Downloads
2
Readme
rangey
Python 3.x
range
for ES6
Installation | Usage | Example | License
Installation
With npm:
npm install rangey --save
Note: You need an engine that supports ES6 (e.g. Babel or Node 4.0+).
Usage
rangey.range([start, ]stop[, step])
Starts a loop on start
, incrementing by step
until reaching stop
.
This is a generator function that yields values one by one (and does not take up memory for an array)
Defaults:
start
= 0step
= 1
rangey.listOf(generator)
Appends all values from generator into an array.
Example
'use strict'
import { range, listOf } from 'rangey'
for (let i of range(4)) {
// 0, 1, 2, 3
}
listOf(range(1, 5, 0.5)) // 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5