package
For adding, subtracting, and indexing discontinuous ranges of numbers
npm install drangeGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
Estimated unpacked size across 1 packages.
18.7 kB
Includes dependencies.
For adding/subtracting sets of range of numbers.
const DRange = require('drange');
let allNums = new DRange(1, 100); //[ 1-100 ]
let badNums = DRange(13).add(8).add(60,80); //[8, 13, 60-80]
let goodNums = allNums.clone().subtract(badNums);
console.log(goodNums.toString()); //[ 1-7, 9-12, 14-59, 81-100 ]
let randomGoodNum = goodNums.index(Math.floor(Math.random() * goodNums.length));Creates a new instance of DRange.
The total length of all subranges
Adds a subrange
Adds all of another DRange's subranges
Subtracts a subrange
Subtracts all of another DRange's subranges
Keep only subranges that overlap the given subrange
Intersect all of another DRange's subranges
Get the number at the specified index
let drange = new DRange()
drange.add(1, 10);
drange.add(21, 30);
console.log(drange.index(15)); // 25Get contained numbers
let drange = new DRange(1, 4)
drange.add(6);
drange.subtract(2);
console.log(drange.numbers()); // [1, 3, 4, 6]Get copy of subranges
let drange = new DRange(1, 4)
drange.add(6, 8);
console.log(drange.subranges());
/*
[
{ low: 1, high: 4, length: 4 },
{ low: 6, high: 8, length: 3 }
]
*/Clones the drange, so that changes to it are not reflected on its clone
npm install drangeTests are written with mocha
npm testDRange ships with TypeScript definitions.
import DRange from 'drange'; // requires esModuleInteropTo report a security vulnerability, please use the Tidelift security contact. Tidelift will coordinate the fix and disclosure.