rangestar
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

Range*

Build Status Coverage npm bundle size npm version

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(STOPnumber)Generator<number>
 
// From START to STOP with optional STEP:
range.rangeGenerator(STARTnumber, STOPnumber, STEP?: number)Generator<number>

Range array

Same concept.

// From 0 to STOP:
range.rangeGenerator(STOPnumber)number[]
 
// From START to STOP with optional STEP:
range.rangeGenerator(STARTnumber, STOPnumber, 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.

Readme

Keywords

Package Sidebar

Install

npm i rangestar

Weekly Downloads

3

Version

1.0.0

License

MIT

Unpacked Size

6.77 kB

Total Files

7

Last publish

Collaborators

  • krmax44