parse-numeric-range
Takes a string, such as "1,2,3-10,5-8" and turns it into an array of numbers
Last updated 12 years ago by euank .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install parse-numeric-range 
SYNC missed versions from official npm registry.

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:

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.

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

Current Tags

  • 1.3.0                                ...           latest (5 years ago)

6 Versions

  • 1.3.0                                ...           5 years ago
  • 1.2.0                                ...           6 years ago
  • 1.1.0                                ...           6 years ago
  • 1.0.0                                ...           6 years ago
  • 0.0.2                                ...           11 years ago
  • 0.0.1                                ...           12 years ago
Maintainers (1)
Downloads
Today 0
This Week 2
This Month 5
Last Day 0
Last Week 3
Last Month 1
Dependencies (0)
None
Dev Dependencies (2)

Copyright 2013 - present © cnpmjs.org | Home |