range-life
v1.0.2
Published
A range utility that no one asked for.
Downloads
1
Maintainers
Readme
Range Life
A range utility that no one asked for.
Supports stepped ranges of integers, decimals, letters, and even a supplied array of values.
"If I had a range life, then I could settle down." - Stephen Malkmus
Installation
$ npm install range-life
Usage
Inclusion
All examples are supported by the default module.
However, you may submodule for specific methods like so.
import rangeNum from 'range-life/standard'
import rangeAlpha from 'range-life/alpha'
import rangeValues from 'range-life/values'
Examples
import range from 'range-life'
range(0) // => []
range(4) // => [0, 1, 2, 3]
range(-4) // => [0, -1, -2, -3]
range(1, 5) // => [1, 2, 3, 4]
range(0, 20, 5) // => [0, 5, 10, 15]
range(0, -4, -1) // => [0, -1, -2, -3]
range(1, 4, 0) // => [1, 1, 1]
range(1, 4, 0.5) // => [1, 1.5, 2, 2.5, 3, 3.5]
// letters are inclusive
range('a', 'e') // => ['a', 'b', 'c', 'd', 'e']
range('A', 'E') // => ['A', 'B', 'C', 'D', 'E']
range('A', 'E', 2) // => ['A', 'C', 'E']
// values are exclusive
const values = ['Zero', 'One', 'Two', 'Three']
range(0, 3, values) // => ['Zero', 'One', 'Two']
range(0, Infinity, 2, values) // => ['Zero', 'Two']
API Reference
range-life/standard
Parameters
Examples
import range from 'range-life/standard'
range(1, 5) // => [1, 2, 3, 4]
range(0, 20, 5) // => [0, 5, 10, 15]
range-life/alpha
Parameters
Examples
import range from 'range-life/alpha'
range('A', 'E') // => ['A', 'B', 'C', 'D', 'E']
range('A', 'E', 2) // => ['A', 'C', 'E']
range-life/values
Parameters
Examples
import range from 'range-life/values'
const values = ['Zero', 'One', 'Two', 'Three']
range(1, 3, values) // => ['One', 'Two']
range(1, Infinity, 2, values) // => ['Zero', 'Two']
Returns Array<any>