
Security News
Meet Socket at Black Hat Europe and BSides London 2025
Socket is heading to London! Stop by our booth or schedule a meeting to see what we've been working on.
@rawify/interval
Advanced tools
Interval.js is a lightweight JavaScript library for working with mathematical intervals, providing a wide range of operations useful in computational geometry, scheduling, numerical analysis and when using Unix timestamps also date ranges.
You can install Interval.js via npm:
npm install @rawify/interval
Or with yarn:
yarn add @rawify/interval
Alternatively, download or clone the repository:
git clone https://github.com/rawify/Interval.js
Include the interval.min.js file in your project:
<script src="path/to/interval.min.js"></script>
Or in a Node.js project:
const Interval = require('@rawify/interval');
or
import Interval from '@rawify/interval';
Intervals can be created using the Interval constructor:
let i1 = new Interval(1, 5);
let i2 = new Interval(3, 7);
Empty intervals are represented by [0, 0].
intersection(i)Finds the intersection of two intervals. Returns null if they don’t intersect.
let i1 = new Interval(1, 5);
let i2 = new Interval(3, 7);
let inter = i1.intersection(i2); // [3, 5]
union(i)Returns the convex hull (minimal covering interval) of two intervals.
let uni = i1.union(i2); // [1, 7]
equals(i)Checks if two intervals are equal.
i1.equals(new Interval(1, 5)); // true
overlaps(i)Checks if two intervals overlap.
i1.overlaps(i2); // true
touches(i)Checks if two intervals are adjacent (share a boundary point).
containsInterval(i)Checks if the current interval fully contains another interval.
new Interval(1, 10).containsInterval(new Interval(3, 5)); // true
isInside(x)Checks if a point x lies inside the interval.
isEmpty()Returns true if the interval is empty (i.e. a >= b).
size()Returns the length of the interval.
midPoint()Returns the midpoint of the interval.
gap(i)Computes the distance between two intervals (0 if overlapping or touching).
translate(dx)Shifts the interval by dx.
extend(da, db)Extends the start and end of the interval.
scaleAroundMid(f)Scales the interval around its midpoint by factor f.
subtract(i)Subtracts interval i from the current interval. May return up to two disjoint intervals.
subtractAll(list)Subtracts multiple intervals, returning a normalized list of disjoint intervals.
toString()Returns a string representation of the interval.
Interval.empty()Creates an empty interval [0,0].
Interval.sort(list)Sorts an array of intervals by start, then end.
Interval.mergeAll(list)Merges overlapping or adjacent intervals in a list, returning disjoint intervals.
Interval.hull(list)Returns the minimal covering interval of a list of intervals.
Interval.intersectionAll(list)Computes the intersection of all intervals in a list.
As every library I publish, Interval.js is also built to be as small as possible after compressing it with Google Closure Compiler in advanced mode. Thus the coding style orientates a little on maxing-out the compression rate. Please make sure you keep this style if you plan to extend the library.
After cloning the Git repository run:
npm install
npm run build
Copyright (c) 2025, Robert Eisele Licensed under the MIT license.
FAQs
The RAW Interval and Range library
We found that @rawify/interval demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket is heading to London! Stop by our booth or schedule a meeting to see what we've been working on.

Security News
OWASP’s 2025 Top 10 introduces Software Supply Chain Failures as a new category, reflecting rising concern over dependency and build system risks.

Research
/Security News
Socket researchers discovered nine malicious NuGet packages that use time-delayed payloads to crash applications and corrupt industrial control systems.