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 🙏

© 2025 – Pkg Stats / Ryan Hefner

classify-series

v0.3.2

Published

Classification algorithms for number-arrays.

Readme

classify-series

npm NpmLicense npm bundle size (minified) npm bundle size (minified + gzip) David David

Classification algorithms for number-arrays.

Description

This package provides pure javascript functions for classification of Number-arrays.

There are 4 different algorithms to choose from. See differences in docs. All algorithms take a number-array and the number of classes as parameters. The output is a bounds-array of length nbClass + 1. This bounds-array includes the minimum and maximum value of the series as well as the breakpoints for classification.

The package also exposes two helper functions to process bounds-arrays: classIdx(bounds, val) will take bounds and a concrete value and return the classification index. An index that ranges from 0 to nbClass - 1. You can use this for example to classify by a color-array. getRanges(bound) returns an array that represent the classes as strings. It can take a custom separator (default = ' - ') and a precision for rounding the values.

Example (two classes):

import { classifyEqInterval, getRanges, classIdx } from 'classify-series'

const serie = [1, 2, 3, 4]
const nbClass = 2

const bounds = classifyEqInterval(serie, nbClass) // [1, 2.5, 4]
const ranges = getRanges(bounds) // ['1 - 2.5', '2.5 - 4']

classIdx(bounds, 1) // 0
classIdx(bounds, 1.5) // 0
classIdx(bounds, 2.5) // 0
classIdx(bounds, 3) // 1
classIdx(bounds, 0) // -1

Example (classification by color).

// classification by color
const colors = ['#fff', '#000']
colors[classIdx(bounds, 1)] // '#fff'
colors[classIdx(bounds, 0)] // undefined
colors[classIdx(bounds, 0)] || '#888' // '#888' be careful for for falsible values in colors

for (let i = 0; i < ranges.length; i++) {
  console.log(`Class ${i + 1}: ${ranges[i]} | ${colors[i]}`)
  // Class 1: 1 - 2.5 | #fff
  // Class 2: 2.5 - 4 | #000
}

If you have falsible values in your classes-array ("null", "0", ...) and want to classify out of bound values this package provides a helper function: getClass(bounds, val, classes, oob). It safely classifies values out of the series range as the provided oob-value.

import { getClass } from 'classify-series'

getClass(bounds, 2, colors, '#888') // '#fff'
getClass(bounds, 0, colors, '#888') // '#888'

// it's basically this:
typeof colors[classIdx(bounds, 0)] !== 'undefined'
  ? colors[classIdx(bounds, 0)]
  : '#888' // '#888'

docs

todo...

Inspiration

Thanks to simogeo/geostats for the algorithm implementations. I altered them to use newer javascript syntax and functionality. Also this package provides each algorithm as a pure function. These changes result in a smaller build and make tree-shaking possible.

Known Issues

  • Jenks is behaving strange when number of classes is smaller or equal to series.length.