0.2.7 • Published 3 months ago

number-list v0.2.7

Weekly downloads
2
License
ISC
Repository
github
Last release
3 months ago

number-list

Description

Convert arrays of positive integers (such as page numbers) to comma-separated strings, with ranges represented with hyphens, or do the reverse, converting strings to arrays. Numbers are sorted in the output, and duplicates are removed. To avoid memory problems (and because this is designed for page numbers), the integers must be less than 1 million.

Installation

$ npm install --save number-list

Usage

const NumberList = require('number-list');

Methods

.parse(string)

The argument is a string made up of numbers and number ranges, separated by commas or whitespace.

console.log(NumberList.parse('1-3, 5'));
// [ 1, 2, 3, 5 ]

console.log(NumberList.parse('3-4 1-6 2,2'));
// [ 1, 2, 3, 4, 5, 6 ]

.stringify(array)

The argument is an array of positive integers.

console.log(NumberList.stringify([1, 2, 3, 5]));
// 1-3, 5

console.log(NumberList.stringify([2, 7, 3, 2, 6]));
// 2-3, 6-7
0.2.7

3 months ago

0.2.6

2 years ago

0.2.5

4 years ago

0.2.4

4 years ago

0.2.3

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago