Skip to main content
Home

Built and signed on GitHub Actions

Well-tested utility functions dealing with async iterables

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
88%
Published
2 years ago (0.6.0)
function range
range(stop: number): Range<number>

Creates a Range of numbers from 0 to stop with step 1.

import { range } from "./range.ts";

for (const value of range(4)) console.log(value);

The above example will print the following 4 lines:

0
1
2
3

Note that the type of the range is Range<number>, which implements both Iterable<number> and AsyncIterable<number>.

Parameters

stop: number

The stop of the range.

Return Type

range(stop: bigint): Range<bigint>

Creates a Range of bigints from 0 to stop with step 1.

import { range } from "./range.ts";

for (const value of range(4n)) console.log(value);

The above example will print the following 4 lines:

0
1
2
3

Note that the type of the range is Range<bigint>, which implements both Iterable<bigint> and AsyncIterable<bigint>.

Parameters

stop: bigint

The stop of the range.

Return Type

range(
start: number,
stop: number,
): Range<number>

Creates a Range of numbers with step 1.

import { range } from "./range.ts";

for (const value of range(2, 5)) console.log(value);

The above example will print the following 3 lines:

2
3
4

Note that the type of the range is Range<number>, which implements both Iterable<number> and AsyncIterable<number>.

Parameters

start: number

The start of the range.

stop: number

The stop of the range.

Return Type

range(
start: bigint,
stop: bigint,
): Range<bigint>

Creates a Range of bigints with step 1.

import { range } from "./range.ts";

for (const value of range(2n, 5n)) console.log(value);

The above example will print the following 3 lines:

2
3
4

Note that the type of the range is Range<bigint>, which implements both Iterable<bigint> and AsyncIterable<bigint>.

Parameters

start: bigint

The start of the range.

stop: bigint

The stop of the range.

Return Type

range(
start: number,
stop: number,
step: number,
): Range<number>

Creates a Range of numbers.

import { range } from "./range.ts";

for (const value of range(10, -10, -3.5)) console.log(value);

The above example will print the following 6 lines:

10
6.5
3
-0.5
-4
-7.5

Note that the type of the range is Range<number>, which implements both Iterable<number> and AsyncIterable<number>.

Parameters

start: number

The start of the range. It must be a finite number.

stop: number

The stop of the range. It must be a finite number.

step: number

The step of the range. It must be a finite number, and cannot be zero.

Return Type

range(
start: bigint,
stop: bigint,
step: bigint,
): Range<bigint>

Creates a Range of bigints.

import { range } from "./range.ts";

for (const value of range(10n, -10n, -5n)) console.log(value);

The above example will print the following 4 lines:

10
5
0
-5

Note that the type of the range is Range<bigint>, which implements both Iterable<bigint> and AsyncIterable<bigint>.

Parameters

start: bigint

The start of the range.

stop: bigint

The stop of the range.

step: bigint

The step of the range. Cannot be zero.

Return Type

A Range of bigints.

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@hongminhee/aitertools

Import symbol

import { range } from "@hongminhee/aitertools";
or

Import directly with a jsr specifier

import { range } from "jsr:@hongminhee/aitertools";

Add Package

pnpm i jsr:@hongminhee/aitertools
or (using pnpm 10.8 or older)
pnpm dlx jsr add @hongminhee/aitertools

Import symbol

import { range } from "@hongminhee/aitertools";

Add Package

yarn add jsr:@hongminhee/aitertools
or (using Yarn 4.8 or older)
yarn dlx jsr add @hongminhee/aitertools

Import symbol

import { range } from "@hongminhee/aitertools";

Add Package

vlt install jsr:@hongminhee/aitertools

Import symbol

import { range } from "@hongminhee/aitertools";

Add Package

npx jsr add @hongminhee/aitertools

Import symbol

import { range } from "@hongminhee/aitertools";

Add Package

bunx jsr add @hongminhee/aitertools

Import symbol

import { range } from "@hongminhee/aitertools";