Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
parse-numeric-range
Advanced tools
Takes a string, such as "1,2,3-10,5-8" and turns it into an array of numbers
The parse-numeric-range npm package is a utility for parsing numeric ranges from strings. It can handle individual numbers, ranges, and combinations of both, making it useful for scenarios where you need to interpret and work with numeric ranges from user input or configuration files.
Parse Single Numbers
This feature allows you to parse a single number from a string and returns it as an array containing that number.
const parse = require('parse-numeric-range');
const result = parse('5');
console.log(result); // [5]
Parse Ranges
This feature allows you to parse a range of numbers from a string and returns an array containing all the numbers in that range.
const parse = require('parse-numeric-range');
const result = parse('1-5');
console.log(result); // [1, 2, 3, 4, 5]
Parse Combinations of Numbers and Ranges
This feature allows you to parse a combination of individual numbers and ranges from a string, returning an array containing all the specified numbers.
const parse = require('parse-numeric-range');
const result = parse('1-3,5,7-9');
console.log(result); // [1, 2, 3, 5, 7, 8, 9]
The range-parser package is used to parse HTTP Range headers, which specify a range of bytes to be sent from a server. While it is more specialized for HTTP use cases, it can also handle numeric ranges but is not as general-purpose as parse-numeric-range.
Parses expressions like 1-10,20-30. Returns an energetic (as opposed to lazy) array.
Comprehensive supported expression examples:
Expression | result |
---|---|
[] | |
1 | [1] |
1,2 | [1,2] |
-10 | [-10] |
-3,-3 | [-3, -3] |
-1-2,-2 | [-1,0,1,2,-2] |
-1--2 | [-1,-2] |
-1..2,-2 | [-1,0,1,2,-2] |
-1...3,-2 | [-1,0,1,2,-2] |
1⋯3 | [1,2] |
1…3 | [1,2] |
1‥3 | [1,2,3] |
What's this useful for? Well, letting users input these sorts of things and then making them programmatically useful.
First, npm install parse-numeric-range
.
const rangeParser = require("parse-numeric-range");
const numbers = rangeParser("4,6,8-10,12,14..16,18,20...23");
console.log(
`The first ${numbers.length} composite numbers are: ${numbers.join(", ")}`,
);
import rangeParser from "parse-numeric-range";
const numbers = rangeParser("4,6,8-10,12,14..16,18,20...23");
console.log(
`The first ${numbers.length} composite numbers are: ${numbers.join(", ")}`,
);
FAQs
Takes a string, such as "1,2,3-10,5-8" and turns it into an array of numbers
We found that parse-numeric-range demonstrated a not healthy version release cadence and project activity because the last version was released 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.