New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

jrange

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jrange

Python's range function for javascript

latest
Source
npmnpm
Version
1.2.3
Version published
Weekly downloads
6
100%
Maintainers
1
Weekly downloads
 
Created
Source

jrange

license Coveralls NPM downloads

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

/defaultrequired
start0no
end/yes
step1no

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 an Array.

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 []

Keywords

range

FAQs

Package last updated on 12 Sep 2023

Did you know?

Socket

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.

Install

Related posts