abbrev-range
v1.0.0
Published
Utility method to abbreviate a range of sorted integers
Downloads
348
Readme
abbrev-range
Utility method for abbreviating an array of integers into a more human-readable form.
Installation
Install using npm:
$ npm install abbrev-range
Usage
Note: This function assumes the array of values contains integers, and those integers are sorted and contain no duplicates.
var abbrevRange = require('abbrev-range');
abbrevRange([]); // ''
abbrevRange([1]); // '1'
abbrevRange([1, 2, 3]); // '1-3'
abbrevRange([1, 2, 3, 5]); // '1-3, 5'
abbrevRange([1, 3, 5]); // '1, 3, 5'
abbrevRange([1, 2, 3, 5, 6, 7]); // '1-3, 5-7'
abbrevRange([1, 2]); // '1, 2'
abbrevRange([1, 3, 4, 8]); // '1, 3, 4, 8'
License
MIT