Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
discontinuous-range
Advanced tools
for adding, subtracting, and indexing discontinuous ranges of numbers
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.
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
The 'range-parser' package is used to parse HTTP Range headers. It is more specialized for handling byte ranges in HTTP requests, whereas 'discontinuous-range' is more general-purpose for any numerical ranges with gaps.
The 'interval-tree' package provides a data structure for storing intervals and efficiently querying them. It is more focused on interval queries and overlaps, while 'discontinuous-range' is focused on creating and manipulating ranges with gaps.
The 'buckets-js' package offers various data structures, including sets and maps, which can be used to manage ranges. However, it does not provide the same level of specialized functionality for discontinuous ranges as 'discontinuous-range'.
DiscontinuousRange(1, 10).subtract(4, 6); // [ 1-3, 7-10 ]
this is a pretty simple module, but it exists to service another project so this'll be pretty lacking documentation. reading the test to see how this works may help. otherwise, here's an example that I think pretty much sums it up
var all_numbers = new DiscontinuousRange(1, 100); //[ 1-100 ]
var bad_numbers = DiscontinuousRange(13).add(8).add(60,80); //[8, 13, 60-80]
var good_numbers = all_numbers.clone().subtract(bad_numbers);
console.log(good_numbers.toString()); //[ 1-7, 9-12, 14-59, 81-100 ]
var random_good_number = good_numbers.index(Math.floor(Math.random() * good_numbers.length));
FAQs
for adding, subtracting, and indexing discontinuous ranges of numbers
The npm package discontinuous-range receives a total of 1,967,460 weekly downloads. As such, discontinuous-range popularity was classified as popular.
We found that discontinuous-range demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.