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 🙏

© 2025 – Pkg Stats / Ryan Hefner

math.interval

v0.1.3

Published

Class to work with intervals of real numbers.

Downloads

625

Readme

Interval

Class to work with intervals of real numbers.

Version

0.1.1

Install

npm install math.interval

Usage

var Interval = require('math.interval')

var interval = new Interval('(1, 5)')

interval.isEmpty() // false
interval.contains(4) // true
interval.contains('[2, 3)') // true
interval.union('[8, 9)') // [new Interval('(1, 5)'), new Interval('[8, 9)')]
interval.union('(4, 6])') // [new Interval('(1, 6]')]

var isolatedInterval = new Interval('{3}') // equivalent to [3, 3]
isolatedInterval.isEmpty() // false
interval.contains(isolatedInterval) // true

API

Interval

constructor(interval)

Constructor creates an instance of Interval class. it throws an exception if interval is not IntervalCastable

Interval#isEmpty()

It returns true or false if interval is empty or not.

Example:

var Interval = require('math.interval')

var new Interval('[2, 4)')

interval.isEmpty() // returns false

Interval#contains(interval)

It returns true or false if instance contains interval passed by parameter. contains throws an exception if interval is not IntervalCastable

Example:

var Interval = require('math.interval')

var interval = new Interval('[1, 3)')

interval.contains('(1, 2)') // returns true
interval.contains(new Interval('[5, 6]')) // returns false

Interval#union(...intervals)

It returns an array of minimum disjoint intervals that represents the union of instance of interval with intervals passed by parameter.

var Interval = require('math.interval')

var interval = new Interval('[1, 3)')

interval.union('(2, 4)', '{5}', '(5, 6)')
// returns [new Interval('[1, 4)'), new Interval('[5, 6)')]

Interval.union(...intervals)

Interval also has static method that calculates the union of intervals in the same way as union method.

var Interval = require('math.interval')

Interval.union('[1, 3)', '(2, 4)', '{5}', '(5, 6)')
// returns [new Interval('[1, 4)'), new Interval('[5, 6)')]

Interval#toString()

It returns an string with a expression representation of interval

var Interval = require('math.interval')

var a = new Interval('(2, 5]')
var b = new Interval('(5, 2]') // empty
var c = new Interval('[2, 2]') // singleton interval

a.toString() // '(2, 5]'
b.toString() // '{}'
c.toString() // '{2}'

IntervalCastable

A value is IntervalCastable if it is one of this list of types:

  • instance of Interval.
  • string that parses with interval ('[2, 5]', '[0, 5)', '{3}', '(-2, 1)', etc).
  • data structure defined in math.interval-utils package.

Exported functions

rawInterval(interval)

It converts Interval instance to interval data structure defined in math.interval-utils package. It is posible to import this function thus:

var rawInterval = require('math.interval/src/raw-interval.js')

cast(interval)

It converts IntervalCastable value to interval data structure defined in math.interval-utils package. It is posible to import this function thus:

var rawInterval = require('math.interval/src/cast.js')

LICENSE

MIT