npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

group-into-intervals

v1.1.1

Published

Group data into intervals

Readme

group-into-intervals

Scope: This module was developed as a 2-week school project for the course 1DV610.

group-into-intervals is a tool that supports statistical analysis of data by grouping data points into intervals.

  • Input an array of numbers and get it grouped for a quick and lightweight analysis.
  • Choose one of four color schemes to go with the intervals and use the result to visualize your data.
    Color schemes

Statistical background

The number of intervals (a.k.a. classes or bins) is calculated with Sturges' formula k = 1 + 3.322 * log10(number of data points).
The interval width (or class width) is calculated by dividing the range of the dataset with the number of intervals. In case the interval width multiplied with the number of intervals is too small to cover the range ot the dataset, the interval width is increased by 1 until the range is covered.

For more information about Sturges' rule and criticism of it, see Wikipedia.

Installation

To add the module to your application, run:

npm install group-into-intervals

Usage

The module takes an array of numbers and groups them into intervals. The output is returned as JSON.

Code examples

Requesting ascending intervals with color scheme #1:

import { getAscendingIntervalsWithColors } from 'group-into-intervals'

const colorSchemeId = 1
const input = [1, 3, -5, 17, 3]
const intervals = groupIntoIntervalsWithColorsAscending(input, colorSchemeId)

Will return this object (after JSON.parse):

[
  {
    lowerBoundary: -5,
    upperBoundary: 2,
    data: [ -5, 1 ],
    color: { hexValue: '#be2020', rgbValue: 'rgb(190, 32, 32)' }
  },
  {
    lowerBoundary: 3,
    upperBoundary: 10,
    data: [ 3, 3 ],
    color: { hexValue: '#7532a8', rgbValue: 'rgb(117, 50, 168)' }
  },
  {
    lowerBoundary: 11,
    upperBoundary: 18,
    data: [ 17 ],
    color: { hexValue: '#1a02f0', rgbValue: 'rgb(26, 2, 240)' }
  }
]

Examples for usage of output

Use the output to easily visualize your data, e.g. displaying it as intervals or creating a histogram of your data.

Examples made using the test-group-into-intervals repo and arrays containing random numbers.

Example of using color scheme 3 and displaying the resulting intervals

Output as intervals

Example of using color scheme 1 and displaying the result as histogram

Output as histogram

API

Fetch color schemes

You can fetch all color schemes or a specific one.

To get all color schemes, use:

getAllColorSchemes()

To fetch information about a specific color scheme, call this function with one of the color scheme ID's:

getColorScheme(colorSchemeId)

Get intervals (without colors)

Get ascending intervals of your input:

getAscendingIntervals(input)  // input = an array of numbers

Get descending intervals of your input:

getDescendingIntervals(input)  // input = an array of numbers

Get intervals (with colors)

Get the intervals together with a color for each interval. Specify the ID of the color scheme you want to use. Based on that scheme, the function will add as much colors as needed to give each interval its own color.
Please note: If your data results in more than 9 intervals, the created colors might be hard to distinguish visually.

Get ascending intervals with colors:

getAscendingIntervalsWithColors(input, colorSchemeId)  // input = an array of numbers

Get descending intervals with colors:

getDescendingIntervalsWithColors(input, colorSchemeId)  // input = an array of numbers

Get interval metadata

Returns the metadata that will be used when your input is grouped into intervals, e.g. range, number of intervals and interval width.

  • Set isAscending = true if the data should be sorted ascending
  • Set isAscending = false if the data should be sorted descending
getIntervalMetadata(input, isAscending)  // input = an array of numbers

Color schemes

| ID | Name | Color 1 | Color 2 | Color 3 | |----|------|---------|---------|---------| | 1 | red, violet, blue | red(190, 32, 32) | violet(117, 50, 168) | blue(26, 2, 240) | | 2 | red, yellow, blue | red(190, 32, 32) | yellow(214, 219, 66) | blue(26, 2, 240) | | 3 | violet, yellow, blue | violet(117, 50, 168) | yellow(214, 219, 66) | blue(26, 2, 240) | | 4 | white, light green, dark green | white(255, 255, 255) | light green(94, 193, 56) | dark green(58, 109, 37) |

Technical information

The module was developed with and tested for Node version 24.1.0.

Test report summary

For a summary of the latest unit test run, see the summary of test results.

For detailed information about the tests, see the test report.

Versions and releases

Version 1.1.0, released 2025-10-21.

Bugs and issues

If you find any vulnerabilities, bugs or issues, please add them as an issue.

License

MIT License

Contributing

Interested in contributing to this module? Please see the contribution guidelines.