Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

discontinuous-range

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

discontinuous-range

for adding, subtracting, and indexing discontinuous ranges of numbers

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.5M
decreased by-18.26%
Maintainers
1
Weekly downloads
 
Created

What is discontinuous-range?

The 'discontinuous-range' npm package allows you to create and manipulate ranges of numbers that can have gaps. This is useful for scenarios where you need to handle ranges that are not continuous, such as time slots, IP ranges, or any other numerical ranges with exclusions.

What are discontinuous-range's main functionalities?

Create a Range

This feature allows you to create a continuous range of numbers. In this example, a range from 1 to 10 is created.

const Range = require('discontinuous-range');
const range = new Range(1, 10);
console.log(range.toString()); // '1-10'

Add a Sub-Range

This feature allows you to add a sub-range to an existing range. In this example, a sub-range from 20 to 30 is added to the initial range of 1 to 10.

const Range = require('discontinuous-range');
const range = new Range(1, 10);
range.add(20, 30);
console.log(range.toString()); // '1-10,20-30'

Remove a Sub-Range

This feature allows you to remove a sub-range from an existing range. In this example, the sub-range from 5 to 7 is removed from the range '1-10,20-30'.

const Range = require('discontinuous-range');
const range = new Range(1, 10);
range.add(20, 30);
range.remove(5, 7);
console.log(range.toString()); // '1-4,8-10,20-30'

Check if a Number is in Range

This feature allows you to check if a specific number is within the defined range. In this example, 5 is within the range '1-10,20-30' but 15 is not.

const Range = require('discontinuous-range');
const range = new Range(1, 10);
range.add(20, 30);
console.log(range.contains(5)); // true
console.log(range.contains(15)); // false

Other packages similar to discontinuous-range

Keywords

FAQs

Package last updated on 14 Nov 2024

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