1.0.0 • Published 5 years ago
rangestar v1.0.0
Range*
Another range array generator. Written in TypeScript, well tested, no floating-point BS, super fast and tiny.
Installation
yarn add rangestar
Examples
Supports generators...
const range = require('rangestar');
for (const r of range.rangeGenerator(3)) {
console.log(r);
}
// 0
// 1
// 2
for (const r of range.rangeGenerator(1, 3)) {
console.log(r);
}
// 1
// 2
...and arrays...
const a = range.rangeArray(3);
console.log(a);
// [0, 1, 2]
const b = rangeArray(3, 3.4, 0.1);
console.log(b);
// [3, 3.1, 3.2, 3.3]
...and humans:
const lodashRange = require('lodash.range');
const c = lodashRange(3, 3.4, 0.1);
console.log(c);
// [3, 3.1, 3.2, 3.3000000000000003]
// WHAT THE F$#%?
API
The START
value will be included in the result, while STOP
will not.
Range generator
// From 0 to STOP:
range.rangeGenerator(STOP: number): Generator<number>
// From START to STOP with optional STEP:
range.rangeGenerator(START: number, STOP: number, STEP?: number): Generator<number>
Range array
Same concept.
// From 0 to STOP:
range.rangeGenerator(STOP: number): number[]
// From START to STOP with optional STEP:
range.rangeGenerator(START: number, STOP: number, STEP?: number): number[]
Benchmarks
Use yarn benchmark
to run the benchmarks. Python and Bash are required.
Library | Results |
---|---|
Range* | 14.424ms |
Lodash | 13.017ms |
range | 19.874ms |
Python range | 20.853ms |
Credits
This library is based on Lodash's range function.
1.0.0
5 years ago