This package works with Node.js, Deno, Bun, BrowsersIt is unknown whether this package works with Cloudflare Workers




JSR Score
100%
Published
2 years ago (1.2.6)
jrange
The range function of Python implemented using JavaScript.
range(start, end, step)
Install
npm i jrange -S
Usage
- in browser
<script src="/dist/jrange.umd.js"></script> <script> const list = jrange(10); </script>
- esm
import jrange from 'jrange'; const list = jrange(10, 1, -1);
- CommonJS
const range = require('jrange'); // rename to range const list = range(1, 100, 2);
arguments
| / | default | required |
|---|---|---|
| start | 0 | no |
| end | / | yes |
| step | 1 | no |
range(10) -> range(0, 10, 1)
range(1, 10) -> range(1, 10, 1)
different with python
- In Python, the range function returns a
Range Class, while jrange returns anArray.
python
rng = range(0, 10) print(rng, type(rng))) # range(0, 10) <class 'range'> # Convert to list list = list(rng)
javascript
const list = jrange(0, 10) console.log(Array.isArray(list)) // true
- In Python, if the step is zero, the range function will throw an exception, while jrange will return an empty array.
python
range(1, 10, 0) # ValueError: range() arg 3 must not be zero
javascript
jrange(1, 10, 0); // return []
Add Package
deno add jsr:@aram/jrange
Import symbol
import * as jrange from "@aram/jrange";
Import directly with a jsr specifier
import * as jrange from "jsr:@aram/jrange";
Add Package
pnpm i jsr:@aram/jrange
pnpm dlx jsr add @aram/jrange
Import symbol
import * as jrange from "@aram/jrange";
Add Package
yarn add jsr:@aram/jrange
yarn dlx jsr add @aram/jrange
Import symbol
import * as jrange from "@aram/jrange";
Add Package
vlt install jsr:@aram/jrange
Import symbol
import * as jrange from "@aram/jrange";
Add Package
npx jsr add @aram/jrange
Import symbol
import * as jrange from "@aram/jrange";
Add Package
bunx jsr add @aram/jrange
Import symbol
import * as jrange from "@aram/jrange";