Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pretty-range

Package Overview
Dependencies
Maintainers
2
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pretty-range

Node module to prettify arrays of integers into ranges.

  • 0.1.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
2
Weekly downloads
 
Created
Source

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 = require("pretty-range");
var input = [7,5,6,3,4,10];
var output = prettyRange(input);
console.log(output);

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 = require("pretty-range");
var express = require("express");
var app = express.createServer();

app.use(prettyRange.middleware);

FAQs

Package last updated on 14 Mar 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc