source: node_modules/drange/README.md

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 2.2 KB
RevLine 
[d24f17c]1# drange
2
3For adding/subtracting sets of range of numbers.
4
5[![Build Status](https://secure.travis-ci.org/fent/node-drange.svg)](http://travis-ci.org/fent/node-drange)
6[![Dependency Status](https://david-dm.org/fent/node-drange.svg)](https://david-dm.org/fent/node-drange)
7[![codecov](https://codecov.io/gh/fent/node-drange/branch/master/graph/badge.svg)](https://codecov.io/gh/fent/node-drange)
8
9# Usage
10
11```
12const DRange = require('drange');
13
14var allNums = new DRange(1, 100); //[ 1-100 ]
15var badNums = DRange(13).add(8).add(60,80); //[8, 13, 60-80]
16var goodNums = allNums.clone().subtract(badNums);
17console.log(goodNums.toString()); //[ 1-7, 9-12, 14-59, 81-100 ]
18var randomGoodNum = goodNums.index(Math.floor(Math.random() * goodNums.length));
19```
20
21# API
22### new DRange([low], [high])
23Creates a new instance of DRange.
24
25### DRange#length
26The total length of all subranges
27
28### DRange#add(low, high)
29Adds a subrange
30
31### DRange#add(drange)
32Adds all of another DRange's subranges
33
34### DRange#subtract(low, high)
35Subtracts a subrange
36
37### DRange#subtract(drange)
38Subtracts all of another DRange's subranges
39
40### DRange#intersect(low, range)
41Keep only subranges that overlap the given subrange
42
43### DRange#intersect(drange)
44Intersect all of another DRange's subranges
45
46### DRange#index(i)
47Get the number at the specified index
48
49```js
50var drange = new DRange()
51drange.add(1, 10);
52drange.add(21, 30);
53console.log(drange.index(15)); // 25
54```
55
56### DRange#numbers()
57Get contained numbers
58
59```js
60var drange = new DRange(1, 4)
61drange.add(6);
62drange.subtract(2);
63console.log(drange.numbers()); // [1, 3, 4, 6]
64```
65
66### DRange#subranges()
67Get copy of subranges
68
69```js
70var drange = new DRange(1, 4)
71drange.add(6, 8);
72console.log(drange.subranges());
73/*
74[
75 { low: 1, high: 4, length: 4 },
76 { low: 6, high: 8, length: 3 }
77]
78*/
79```
80
81### DRange#clone()
82Clones the drange, so that changes to it are not reflected on its clone
83
84
85# Install
86
87 npm install drange
88
89# Tests
90
91Tests are written with [mocha](https://mochajs.org)
92
93 npm test
94
95# Integration with TypeScript
96
97DRange includes TypeScript definitions.
98
99```typescript
100import * as DRange from "drange";
101const range: DRange = new Drange(2, 5);
102```
103
104Use dtslint to check the definition file.
105
106 npm install -g dtslint
107 npm run dtslint
Note: See TracBrowser for help on using the repository browser.