Skip to content

jimf/abbrev-range

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

abbrev-range

Utility method for abbreviating an array of integers into a more human-readable form.

npm Version Build Status Test Coverage Dependency Status

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

About

Utility method to abbreviate a range of sorted integers

Resources

License

Stars

Watchers

Forks

Packages