Intervals
Utilities for operate over intervals
Install
$ npm install --save @redtea/intervals
Usage
import { includes, merge, clip, select } from "@redtea/intervals"
// or
// const intervals = require("@redtea/intervals");
// or
// in html <script src="https://unpkg.com/@redtea/intervals"></script>
// 1 in [2, 3]
includes(2, 1, 3); // true
// 4 not in [1, 3]
includes(4, 1, 3); // false
merge([[1,3],[1,2],[4,5]]); // [[1,3],[4,5]]
merge([[1,3],[1,2],[4,5]], 1); // [[1,5]
clip([[1,3],[5,7],[9,11]], 1, 11) // [[3,5], [7,9]]
clip([[2,3],[5,6]], 1, 7) // [[1,2],[3,5],[6,7]]
select([[1,2]], 1, 2) // [[1, 2]]
select([[0,2],[1,3]], 1, 2) // [[0, 2], [1, 3]]
Utils
number
, start: number
, end: number
): boolean
**
includes(number: Test if number in interval [start, end] and return result.
[number, number][]
, maxDistance: number
= 0): [number, number][]
**
merge(intervals: Merge intervals that intersect or where distance between intervals less then maxDistance. Always return new list.
[number, number][]
, start: number
, end: number
): [number, number][]
**
clip(intervals: Exclude intervals intervals from interval [start, end]. Always return new list.
[number, number][]
, start: number
, end: number
): [number, number][]
**
select(intervals: Select all intervals that intersect or inside of interval [start, end]. Always return new list.