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 🙏

© 2024 – Pkg Stats / Ryan Hefner

intervaljs

v1.0.10

Published

Library to operate on real intervals

Downloads

90

Readme

interval.js

Library implementing mathematical real numbers intervals arithmetics. Available operations:

  • union (A∪B)
  • difference (A\B)
  • intersection (A∩B)
  • exclusion (A△B)
  • inversion (A')
  • subset (A⊆B)
  • superset (A⊇B)
  • contains (A∍x)

Utils functions:

  • toString()
  • count()
  • forEach()
  • forEachPoint()
  • intervals()

Installation

Install with npm: npm install intervaljs

Install with bower: bower install intervaljs

Initializations

new Interval(start, [end=start])

Create Interval object.

new Interval().toString(); // ''
new Interval(2).toString(); // '{2}'
new Interval(1, 3).toString(); // [1;3]
new Interval.Endpoint(value, [open=false])

Create complex interval Endpoint.

var eStart = new Interval.Endpoint(2, false); // 'endpoint closed'
var eEnd = new Interval.Endpoint(3, true); // 'endpoint open'

new Interval(eStart, eEnd).toString() // [2, 3) - left closed, right open

API

.union(intervalObj) or .union(start, [end=start])

A∪B - Add intervals to interval.

new Interval(1, 3)
  .union(5, 7)
  .union(new Interval(6, Infinity))
  .toString();
// [1;3], [5;Infinity)
.difference(interval) or .difference(start, [end=start])

A\B - Substract interval from interval.

new Interval(1, 8)
  .diference(5, 9)
  .diference(3)
  .toString();
// [1;3), (3,5)
.intersection(interval) or .intersection(start, [end=start])

A∩B - Common part of intervals.

var interval = new Interval(2, 6)
  .intersection(4, 8);
// [4;6]
.exclusion(interval) or .exclusion(start, [end=start])

A△B - Exclusive OR or intervals.

var interval = new Interval(2, 6)
  .exclusion(4, 8);
// [2;4), (6;8]
.inversion()

A' - Invert interval.

new Interval(1, 8)
  .inversion()
// (-Infinity;1), (8,Infinity)
.subset(interval) or .subset(start, [end=start])

A⊆B - Check if interval is a subset of other interval

new Interval(5, 8)
  .subset(1, 8)
// true
new Interval(1, 8)
  .subset(2, 5);
// false
.superset(interval) or .superset(start, [end=start])

A⊇B - Check if interval is a superset for other interval

new Interval(1, 8)
  .superset(5, 8)
// true
new Interval(1, 8)
  .diference(5, 9)
  .superset(2, 5);
// false

var i1 = new Interval(1, 4)
  .union(6, 9)
var i2 = new Interval(1, 9)
  .diference(4, 6)
i1.superset(i2)
// true
.contains(value)

A∍x - Check if interval contains a memeber.

new Interval(1, 8)
  .contains(5)
// true

Utils

.intervals()

Return intervals array

var arr = new Interval(1, 6)
  .union(8)
  .intervals()
  
arr.length;
// 2
.forEach(callback(start, end), [step=0])

Iterate throught interval parts borders, with minimal step for open endpoints. For step equal 0, function return border values skipping open/close atributes.

new Interval(1, 6)
  .difference(4, 8) // we have [1;4)
  .forEach(function(start, end) {
    // start is 1
    // end = 4
  }, 0) // step = 0

// same case with step value
new Interval(1, 6)
  .difference(4, 8) // we have [1;4)
  .forEach(function(start, end) {
    // start is 1
    // end = 3.5
  }, 0.5) // step = 0.5
.forEachPoint(callback(point), [step=1])

Iterate throught interval points with assigned step (default 1)

new Interval(1, 6)
  .diference(4, 8)
  .forEach(function(point) {
    // point = 1, then 2, then 3
  })
.count()

Return count of intervals

new Interval(1, 6)
  .union(8)
  .count()
// 2
.toString()

Output intervals string

new Interval(1, 6)
  .diference(3, 4)
  .union(8)
  .toString()
// [1;3), (4,6], {8}