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

range-obj

v0.0.2

Published

A library for performing operations on ranges of numbers.

Downloads

13

Readme

RangeObj

A Node library for creating number range objects and performing operations on them.

View Full Documentation

Installation

npm install range-obj

Usage

Basic Usage

import { range } from 'range-obj';

const r1 = range(1, 10);    // default step of 1
const r2 = range(1, 10, 2); // step of 2

console.log(r1.toArray()); // [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
console.log(r2.toArray()); // [1, 3, 5, 7, 9]

console.log(r1.toString()); // [1, 10, 1] (start, end, step)
console.log(r2.toString()); // [1, 10, 2]

Unions and Intersections

The union of two ranges is the smallest range fully containing both ranges, while the intersection is the largest range fully contained by both ranges. For example, the union of the ranges [1, 10] and [5, 15] is [1, 15], while the intersection is [5, 10]. The union and intersection of two ranges can be computed using the union and intersection methods, respectively. If the ranges do not overlap, the union will be a range containing both ranges, while the intersection will be an empty range.

Note: Ranges must share the same step size to be unionable.

import { range } from 'range-obj';

const r1 = range(1, 10);
const r2 = range(5, 15);

console.log(r1.union(r2).toArray()); // [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
console.log(r1.intersection(r2).toArray()); // [5, 6, 7, 8, 9, 10]

Transformations

You can transform ranges using the transform method, which takes as parameters a function that transforms a number and an optional function that transforms the step size. For example, to multiply each number in a range by 2, you could do the following:

import { range } from 'range-obj';

const r = range(1, 10);
console.log(r.transform(n => n * 2, step => step * 2).toArray()); // [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]

If you do not provide a function to transform the step size, the step size will remain unchanged. For example, to shift a range by 5, you could do the following:

import { range } from 'range-obj';

const r = range(1, 10);
console.log(r.transform(n => n + 5).toArray()); // [6, 7, 8, 9, 10, 11, 12, 13, 14, 15]

For convenience, the library provides a number of predefined transformations as methods on range objects. For example, to multiply each number in a range by 2, you could do the following:

import { range, transformations } from 'range-obj';

const r = range(1, 10);
console.log(r.multiply(2).toArray()); // [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]

The following transformations are currently available:

  • add(n: number): Adds n to each number in the range. May be used to shift the range. Keeps the same step size.
  • subtract(n: number): Subtracts n from each number in the range. May be used to shift the range. Keeps the same step size.
  • multiply(n: number): Multiplies each number in the range by n. May be used to scale the range. Also multiplies the step size by n.
  • divide(n: number): Divides each number in the range by n. May be used to scale the range. Also divides the step size by n.