Pretty Range
Simple Node.js module to prettify arrays of integers into ranges. This code is based upon a StackOverflow post by Christian C. Salvadó.
Here are a few examples:
[1,2,3]
->"1-3"
[1,2,3,5,6,7]
->"1-3, 5-7"
[1,2,5,6,7]
->"1, 2, 5-7"
[7,5,6,3,4,10]
->"3-7, 10"
Install
npm install pretty-range
Sample Usage
var prettyRange = ;var input = 7563410;var output = ;console;
The outputs is 3-7, 10
Express Middleware
If you're using Express and want access to prettyRange() in your views, add the following piece of middleware to your server:
var prettyRange = ;var express = ;var app = express; app;