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

closed-interval

v1.2.0

Published

Utilities for working with a range of items of any type

Downloads

8

Readme

closed-interval

closed-interval is a TypeScript port of the Apache Commons Range class offered for the JVM based languages.

The API aims to be identical to Apache Commons, with a few exceptions where the TypeScript implementation is simpler or not applicable.

Example usage

As usual, install the package

npm i closed-interval

and use the Range class in your code:

import Range from 'closed-interval'

// or as a CommonJS module
// const { default: Range } = require('closed-interval')

const range = Range.between(10, 100)
const containsOtherRange = range.contains(Range.between(40, 50)) // true
const isOverlappedByOtherRange = range.isOverlappedBy(Range.between(40, 50)) // false

API

Since the API closely resembles the implementation of Apache Commons, the documentation below borrows most of its descriptions from the relevant javadoc.

Range.between


Range.between<T>(fromInclusive: T, toInclusive: T, comparator: Comparator<T> | null = null): Range<T>

Deprecated Use Range.of

Range.of


Range.of<T>(fromInclusive: T, toInclusive: T, comparator: Comparator<T> | null = null): Range<T>

Creates a range with the specified minimum and maximum values (both inclusive).

The range uses the natural ordering of the elements (when applicable) to determine where values lie in the range unless a comparator is passed.

The arguments may be passed in the order (min,max) or (max,min). The getMinimum and getMaximum methods will return the correct values.

Range.is


Range.is<T>(element: T, comparator: Comparator<T> | null = null): Range<T>

Creates a range using the specified element as both the minimum and maximum in this range.

The range uses the natural ordering of the elements (when applicable) to determine where values lie in the range unless a comparator is passed.

contains


contains(element: T): boolean

Checks whether the specified element occurs within this range.

containsRange


containsRange(other: Range<T>): boolean

Checks whether this range contains all the elements of the specified range.

This method may fail if the ranges have two different comparators.

elementCompareTo


elementCompareTo(element: T): -1 | 0 | 1

Checks where the specified element occurs relative to this range.

fit


fit(element: T): T

Fits the given element into this range by returning the given element or, if out of bounds, the range minimum if below, or the range maximum if above.

getComparator


getComparator(): Comparator<T>

Gets the comparator being used to determine if objects are within the range.

Natural ordering uses an internal comparator implementation, thus this method never returns null.

getMaximum


getMaximum(): T

Gets the maximum value in this range.

getMinimum


getMinimum(): T

Gets the minimum value in this range.

intersectionWith


intersectionWith(other: Range<T>): Range<T>

Calculate the intersection of this and an overlapping Range.

isAfter


isAfter(element: T): boolean

Checks whether this range is after the specified element.

isAfterRange


isAfterRange(otherRange: Range<T>): boolean

Checks whether this range is completely after the specified range.

This method may fail if the ranges have two different comparators.

isBefore


isBefore(element: T): boolean

Checks whether this range is before the specified element.

isBeforeRange


isBeforeRange(otherRange: Range<T>): boolean

Checks whether this range is completely before the specified range.

This method may fail if the ranges have two different comparators.

isEndedBy


isEndedBy(element: T): boolean

Checks whether this range ends with the specified element.

isNaturalOrdering


isNaturalOrdering(): boolean

Whether or not the Range is using the natural ordering of the elements.

Natural ordering uses an internal comparator implementation, thus this method is the only way to check if a null comparator was specified.

isOverlappedBy


isOverlappedBy(otherRange: Range<T>): boolean

Checks whether this range is overlapped by the specified range.

Two ranges overlap if there is at least one element in common.

This method may fail if the ranges have two different comparators.

isStartedBy


isStartedBy(element: T): boolean

Checks whether this range starts with the specified element.

toString


toString(): string

Gets the range as a string.

The format of the string is '[min..max]'.