npm i set-of-ranges
-
import
import { RangeSet } from "set-of-ranges";
-
construct
let rs = new RangeSet("(10,20][40,infinity)"); //or let ranges = [ { value: 1, equal: true, }, { value: 2, equal: false, }, ]; // or = parseRanges("[1,2)"); let rs = new RangeSet(ranges);
If construct with a string, it will use parseRanges to parse the string to Ranges.
When use
parseRanges
, spaces and lower/uppercases are ignored. When input is not allowed, it throws an error. -
operate
import { parseRanges, RangeSet, stringifyRanges } from "set-of-ranges"; let rs1: RangeSet, rs2: RangeSet, rs3: RangeSet; rs1.union(rs2); // ============= rs1 = operate(truthTable_union, rs1, rs2); rs1.intersection(rs2); // ====== rs1 = operate(truthTable_intersection, rs1, rs2); // You can also do operation to more than 2 ranges. rs1.union(rs2, rs3); // ========== rs1 = operate(truthTable_union, rs1, operate(truthTable_union, rs4, rs3)); // You can use a customized truth table, too. rs1.operate( [ [false, false], [false, true], ], rs2 );
TruthTable
Copied from sourcecode.
export type OperateTruthTable = [ // R:true R:false /*L:true */ [boolean, boolean], /*L:flase*/ [boolean, boolean] ];
-
output
import { RangeSet, stringifyRanges } from "set-of-ranges"; let rs1 = new RangeSet("(10 ,20][ 40,infinity )"); console.log(stringifyRanges(rs1)); //=> "(10,20][40,infinity)"
MIT License