https://github.com/krmax44/rangestar
Another range array generator.
https://github.com/krmax44/rangestar
array generator range
Last synced: 8 months ago
JSON representation
Another range array generator.
- Host: GitHub
- URL: https://github.com/krmax44/rangestar
- Owner: krmax44
- License: mit
- Created: 2020-01-22T18:21:13.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-01-22T18:34:54.000Z (over 6 years ago)
- Last Synced: 2025-02-11T10:58:05.502Z (over 1 year ago)
- Topics: array, generator, range
- Language: TypeScript
- Size: 93.8 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Range\*
[](https://gitlab.com/krmax44/rangestar/pipelines)
[](https://gitlab.com/krmax44/rangestar/pipelines)
[](https://bundlephobia.com/result?p=rangestar)
[](https://npm.im/rangestar)
Another range array generator. Written in TypeScript, well tested, no floating-point BS, super fast and tiny.
## Installation
```bash
yarn add rangestar
```
## Examples
Supports generators...
```js
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...
```js
const a = range.rangeArray(3);
console.log(a);
// [0, 1, 2]
```
...and humans:
```js
const b = rangeArray(3, 3.4, 0.1);
console.log(b);
// [3, 3.1, 3.2, 3.3]
// Okay, with you so far
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
```ts
// From 0 to STOP:
range.rangeGenerator(STOP: number): Generator
// From START to STOP with optional STEP:
range.rangeGenerator(START: number, STOP: number, STEP?: number): Generator
```
### Range array
Same concept.
```ts
// 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](https://www.npmjs.com/package/lodash.range) | 13.017ms |
| [range](https://www.npmjs.com/package/range) | 19.874ms |
| [Python `range`](https://docs.python.org/3/library/functions.html#func-range) | 20.853ms |
## Credits
This library is based on [Lodash's](https://lodash.com) range function.