import { Range } from "range-admin"
(new Range(1, 10)).isEqual(new Range(1, 10)) // true
(new Range(1, 10)).compare(new Range(5, 13)) // "OVERLAP"
(new Range(1, 10)).findCommon(new Range(5, 10)) // new Range(5, 10)
# npm
npm install range-admin
# yarn
yarn add range-admin
- Github Repository: https://github.com/jhk1090/range-admin
- NPM Library: https://npmjs.com/package/range-admin
new Range(1, 10)
toString()
- Returns string representation of the range: start~endtoArray(step: number)
- Returns array based on the rangeisEqual(otherRange: Range)
- Check if two ranges are equalisDisjoint(otherRange: Range)
- Check if two ranges are disjoint (no relationship)isSubsetOf(otherRange: Range)
- Check if range is subset of otherRange (range is contained in otherRange)isOverlap(otherRange: Range)
- Check if two ranges are overlapped with each otherisAdjacent(otherRange: Range)
- Check if two ranges are adjacentcompare(otherRange: Range)
- Compare relationship with other range.findCommon(otherRange: Range)
- Find common part of the range with other range.
(new Range(1, 11)).toArray() // [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
(new Range(0, 1001)).toArray(2) // [0, 2, 4, 6, ..., 998, 1000]
(new Range(3, 5)).compare(new Range(1, 4)) // "OVERLAP"
(new Range(3, 5)).compare(new Range(1, 5)) // "SUBSET"
The types of relationship are as follows: "equal", "subset", "superset", "disjoint", "overlap"
(new Range(3, 5)).compare(new Range(1, 4)) // new Range(3, 4)
(new Range(3, 5)).compare(new Range(9, 10)) // null
const range1 = new Range(1, 3)
const range2 = new Range(2, 5)
isEqual(range1, range1, range1) // true
isEqual(range2, range1, range1) // false
Check if all the ranges are equal.
const range1 = new Range(1, 3)
const range2 = new Range(3, 5)
isDisjoint(range1, range2, new Range(9, 10)) // true
isDisjoint(range1, range1, new Range(9, 10)) // false
Check if all the ranges are disjoint.
isSubset(new Range(1, 3), new Range(1, 8)) // false (2nd range is superset of 1st range)
isSubset(new Range(1, 100), new Range(1, 10), new Range(1, 2)) // true
Check if the range is subset of its preceding range. (e.g. 2nd range should be subset of the 1st range)
Opposite with isSuperset
.
isSuperset(new Range(1, 3), new Range(1, 8)) // false (2nd range is superset of 1st range)
isSuperset(new Range(1, 100), new Range(1, 10), new Range(1, 2)) // true
Check if the range is superset of its following range. (e.g. 2nd range should be superset of the 1st range)
Opposite with isSubset
.
isAdjacent(new Range(1, 2), new Range(2, 3), new Range(3, 10)) // true
isAdjacent(new Range(1, 2), new Range(4, 5), new Range(5, 6)) // false
Check if all the ranges are adjacent with each other.
makeRangeArray([0, 11], 2) // [0, 2, 4, 6, 8, 10]
makeRangeArray(new Range(0, 11), 2) // [0, 2, 4, 6, 8, 10]
// equivalent of new Range(0, 11).toArray(2)
Make array of range.
# build
npm run build
# build (using nodemon)
npm run dev
# test (using jest)
npm test