npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

py-range-js

v1.0.0

Published

Python-like range for JavaScript/TypeScript

Readme

py-range-js

Python-style range utilities for JavaScript and TypeScript.

This small library provides a Range class and a range() factory function that behave similarly to Python's built-in range() — lazy, iterable, and typed for TypeScript projects.

Package: py-range-js
Version: 1.0.0

Highlights

  • Small, dependency-free TypeScript implementation
  • Iterables compatible with for..of, Array.from, and spread ([...])
  • Methods: length, at(), includes(), toString()
  • Supports positive and negative step values

Contents

  • Installation
  • Quick start (JavaScript & TypeScript)
  • API reference
  • Examples
  • Build from source
  • Contributing & license

Install

Install from npm:

npm install py-range-js
# or
yarn add py-range-js

If you are working with the repository locally, run:

npm install
npm run build

Quick Start (TypeScript)

import { range, Range } from 'py-range-js';

for (const n of range(5)) {
	console.log(n); // 0,1,2,3,4
}

const r = range(1, 10, 2); // Range from 1 up to (but not including) 10, step 2
console.log(r.length); // number of items
console.log(r.at(0)); // 1
console.log(r.includes(5)); // true

// Negative step
for (const n of range(5, -1, -1)) {
	console.log(n); // 5,4,3,2,1,0
}

Quick Start (JavaScript)

const { range } = require('py-range-js');

console.log([...range(3)]); // [0,1,2]

API Reference

  • class Range implements Iterable<number>

    • new Range(start: number, stop?: number, step: number = 1)
      • If stop is omitted, the constructor treats the first argument as stop and start defaults to 0 (like Python).
      • Throws an Error if step === 0.
    • readonly start: number — inclusive start value.
    • readonly stop: number — exclusive stop value.
    • readonly step: number — step increment (may be negative).
    • get length(): number — number of elements in the range.
    • at(index: number): number — return value at index. Negative index counts from the end. Throws RangeError if out-of-bounds.
    • includes(value: number): boolean — whether value is in the range (fast check using arithmetic).
    • [Symbol.iterator]() — yields values from start to stop by step.
    • toString() — returns a short string like Range(0, 5, 1).
  • function range(start: number, stop?: number, step?: number): Range — factory helper returning a Range instance.

Behavior notes:

  • stop is exclusive: values yielded satisfy start <= value < stop for positive step, or start >= value > stop for negative step.
  • length returns the number of yielded values and will be 0 for empty ranges.

Examples

  • Convert to array:
Array.from(range(0, 10, 2)); // [0,2,4,6,8]
  • Slicing-like access with at (negative index supported):
const r = range(0, 5);
r.at(-1); // 4
  • Membership:
range(2, 10, 2).includes(6); // true
range(2, 10, 2).includes(7); // false

Build & Distribution

This project uses TypeScript and Rollup to produce CommonJS and ES module builds plus type declarations in dist/.

  • Build:
npm run build
  • Output files (from package.json / rollup.config.js):
    • dist/index.esm.js (ESM)
    • dist/index.cjs.js (CJS)
    • dist/index.d.ts (TypeScript types)

Development notes

  • TypeScript settings are in tsconfig.json (target ES2020, declaration: true).
  • Rollup configuration is in rollup.config.js using @rollup/plugin-typescript.

Contributing

Contributions are welcome! Please open issues for bug reports or feature requests and submit pull requests for fixes and enhancements.

Guidelines:

  • Keep changes focused and well-tested.
  • Update or add examples if you introduce new behavior.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Author / Maintainer: michael9992155 (see package.json)