range-overlaps
v1.0.0
Published
Checks whether two ranges/intervals overlap. Returns true or false.
Downloads
46
Maintainers
Readme
Range-Overlaps - check whether two intervals overlap
Checks whether two numeric ranges overlap. For example, [0, 3] and [1, 6] do overlap, while [0, 3] and [4, 6] do not overlap.
Usage
rangeOverlaps(range1, range2, exclusive = false)
The first two arguments are two intervals, each of which is an object with the
start
and end
fields:
const rangeOverlaps = require('range-overlaps');
// Prints `true`:
console.log(
rangeOverlaps({start: 0, end: 3}, {start: 1, end: 6})
);
Options
The third argument is a boolean value that indicates whether an exclusive search
should be performed. For example, [0, 3] and [3, 6] would normally be considered
overlapping. With exclusive search (true
), these will not be considered
overlapping.