drange

WebJar for drange

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

drange
Last Version

Last Version

1.1.1
Release Date

Release Date

Type

Type

jar
Description

Description

drange
WebJar for drange
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/fent/node-drange

Download drange

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/drange/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>drange</artifactId>
    <version>1.1.1</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/drange/
implementation 'org.webjars.npm:drange:1.1.1'
// https://jarcasting.com/artifacts/org.webjars.npm/drange/
implementation ("org.webjars.npm:drange:1.1.1")
'org.webjars.npm:drange:jar:1.1.1'
<dependency org="org.webjars.npm" name="drange" rev="1.1.1">
  <artifact name="drange" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='drange', version='1.1.1')
)
libraryDependencies += "org.webjars.npm" % "drange" % "1.1.1"
[org.webjars.npm/drange "1.1.1"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

drange

For adding/subtracting sets of range of numbers.

Build Status Dependency Status codecov

Usage

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));

API

new DRange([low], [high])

Creates a new instance of DRange.

DRange#length

The total length of all subranges

DRange#add(low, high)

Adds a subrange

DRange#add(drange)

Adds all of another DRange's subranges

DRange#subtract(low, high)

Subtracts a subrange

DRange#subtract(drange)

Subtracts all of another DRange's subranges

DRange#intersect(low, range)

Keep only subranges that overlap the given subrange

DRange#intersect(drange)

Intersect all of another DRange's subranges

DRange#index(i)

Get the number at the specified index

let drange = new DRange()
drange.add(1, 10);
drange.add(21, 30);
console.log(drange.index(15)); // 25

DRange#numbers()

Get contained numbers

let drange = new DRange(1, 4)
drange.add(6);
drange.subtract(2);
console.log(drange.numbers()); // [1, 3, 4, 6]

DRange#subranges()

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 }
]
*/

DRange#clone()

Clones the drange, so that changes to it are not reflected on its clone

Install

npm install drange

Tests

Tests are written with mocha

npm test

Integration with TypeScript

DRange includes TypeScript definitions.

import * as DRange from "drange";
const range: DRange = new Drange(2, 5);

Use dtslint to check the definition file.

npm install -g dtslint
npm run dtslint

Versions

Version
1.1.1
1.0.1