https://github.com/euank/node-parse-numeric-range
Parses expressions like 1-10,20-30. Returns an energetic array.
https://github.com/euank/node-parse-numeric-range
Last synced: about 1 year ago
JSON representation
Parses expressions like 1-10,20-30. Returns an energetic array.
- Host: GitHub
- URL: https://github.com/euank/node-parse-numeric-range
- Owner: euank
- License: isc
- Created: 2014-06-19T09:19:31.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2021-08-22T03:46:19.000Z (almost 5 years ago)
- Last Synced: 2025-03-24T20:51:11.460Z (about 1 year ago)
- Language: JavaScript
- Size: 14.6 KB
- Stars: 25
- Watchers: 2
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
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`.
```javascript
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
```jsx
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(", ")}`,
);
```