New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

drange

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

drange

For adding, subtracting, and indexing discontinuous ranges of numbers

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
188K
decreased by-77.38%
Maintainers
1
Weekly downloads
 
Created
Source

drange

For adding/subtracting sets of range of numbers.

Build Status Dependency Status codecov

Usage

const DRange = require('drange');

var allNums = new DRange(1, 100); //[ 1-100 ]
var badNums = DRange(13).add(8).add(60,80); //[8, 13, 60-80]
var goodNums = allNums.clone().subtract(badNums);
console.log(goodNums.toString()); //[ 1-7, 9-12, 14-59, 81-100 ]
var 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

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

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

Keywords

FAQs

Package last updated on 05 Mar 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc