
Product
Introducing GitHub Actions Scanning Support
Detect malware, unsafe data flows, and license issues in GitHub Actions with Socket’s new workflow scanning support.
@blakek/range
Advanced tools
🔢 Generate a range of numbers
Utilities for creating and sizing a range of numbers.
Using Yarn:
$ yarn add @blakek/range
…or using npm:
$ npm i --save @blakek/range
import { range, rangeG, rangeSize } from '@blakek/range';
// Create a list of numbers
range(1, 3); //» [ 1, 2, 3 ]
range(10, 20, 5); //» [ 10, 15, 20 ]
// Iterate over a range
for (const i of rangeG(1, 10, 4)) {
console.log(i);
}
//» 1
//» 5
//» 9
// Get how many steps a range would contain
rangeSize(1, 20); //» 20
rangeSize(1, 20, 5); //» 4
rangefunction range(from: number, to: number, step?: number = 1): number[];
Creates an array of numbers from a number to another, stepping in increments of
step.
range(1, 5); //» [ 1, 2, 3, 4, 5 ]
range(0, 20, 5); //» [ 0, 5, 10, 15, 20 ]
range(10, 0, -2); //» [ 10, 8, 6, 4, 2, 0 ]
range(5, 0, 1);
//» RangeError: would create infinte range due to stepping in the wrong direction
rangeGfunction rangeG(
from: number,
to: number,
step?: number = 1
): Generator<number, void, number>;
Generates numbers from a number to another, stepping in increments of step.
[...rangeG(1, 3)]; //» [ 1, 2, 3 ]
[...rangeG(5, 1, -1)]; //» [ 5, 4, 3, 2, 1 ]
[...rangeG(5, 1, 1)]; //» RangeError: would create infinte range due to stepping in the wrong direction
for (const i of rangeG(0, -Infinity, -2)) {
if (i < -20) break;
console.log(i);
}
//» 0, -2, -4, -6, -8, -10, -12, -14, -16, -18, -20
rangeSizefunction rangeSize(from: number, to: number, step?: number = 1): number;
Returns the number of steps necessary to go from one number to another, stepping
in increments of step.
rangeSize(1, 100); //» 100
rangeSize(2, 1024, 2); //» 512
rangeSize(100, 1, -5); //» 20
rangeSize(1, 10, -1); //» Infinity
Node.js and Yarn are required to work with this project.
To install all dependencies, run:
yarn
yarn build | Builds the project to ./dist |
yarn format | Format the source following the Prettier styles |
yarn test | Run project tests |
yarn test --watch | Run project tests, watching for file changes |
MIT
FAQs
🔢 Generate a range of numbers
We found that @blakek/range demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Detect malware, unsafe data flows, and license issues in GitHub Actions with Socket’s new workflow scanning support.

Product
Add real-time Socket webhook events to your workflows to automatically receive pull request scan results and security alerts in real time.

Research
The Socket Threat Research Team uncovered malicious NuGet packages typosquatting the popular Nethereum project to steal wallet keys.