Disjoint continuous ranges
Warning: Package is still in testing stage. Please open an issue if you encounter a bug.
yarn add disjoint-range
or
npm install disjoint-range
const {Range, DisjointRange} = require('disjoint-range')
const r1 = new Range(0, 6, {includesEnd: false}) // Open end range
const r1 = new Range(4, 10, {includesStart: false}) // Open start range
const dr1 = new DisjointRange()
.add(r1)
.add(r2)
console.log(dr1.toString()) // [0, 10]
console.log(dr1.includes(5.5)) // true
const dr2 = new DisjointRange()
.add(new Range(-10, 20))
.remove(dr1)
console.log(dr2.toString()) // [-10, 0), (10, 20]
console.log(dr2.includes(15)) // true
console.log(dr2.includes(10)) // false
Continuous range
readonly
Start of range
readonly
End of range
readonly
Range includes start
readonly
Range includes end
options: {includesStart: boolean = true, includesEnd: boolean = true}
If start > end || (start === end && !(includesStart && includesEnd)
then
throws InvalidRangeError
Returns true
if range
is equal to other
Returns true
if range
includes other
Clones the range
Converts range
to string
extends Error
Thrown by new Range()
readonly
readonly
readonly
readonly
Disjoint continuous ranges
readonly
Returns true
if disjointRange
is equal to other
Returns union of disjointRange
and other
Returns difference of disjointRange
and other
Returns intersection of disjointRange
and other
Returns true
if disjointRange
includes other
Clones the disjointRange
Converts disjointRange
to string