🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

parse-numeric-range

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

parse-numeric-range

Takes a string, such as "1,2,3-10,5-8" and turns it into an array of numbers

latest
Source
npmnpm
Version
1.3.0
Version published
Weekly downloads
1.3M
11.79%
Maintainers
1
Weekly downloads
 
Created
Source

node-parse-numeric-range

Parses expressions like 1-10,20-30. Returns an energetic (as opposed to lazy) array.

Supported Expressions

Comprehensive supported expression examples:

Expressionresult
[]
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.

Usage

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(", ")}`,
);

ES6

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(", ")}`,
);

Keywords

parse

FAQs

Package last updated on 22 Aug 2021

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