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 🙏

© 2024 – Pkg Stats / Ryan Hefner

quick-scale

v0.2.0

Published

Create a Fast Linear Scaling Function. CPU Optimized. Reversible. Rounding.

Downloads

11,595

Readme

quick-scale

Create a Fast Linear Scaling Function

features

  • CPU Optimized
  • Reversible
  • Rounding

why

There's a lot of alternatives, but I believe quick-scale provides a mix of features not found together in another package, including the ability to simply reverse the scale and define a strategy for when the range is zero.

install

npm install quick-scale

basic usage

In this basic example, we scale values from an unsigned 16-bit range (common in satellite imagery) to an unsigned 8-bit range (common in JPG and PNG files).

import { createScaleFunction } from "quick-scale";

// the [min, max] values for a 16-bit image
const old_range = [0, 65536];

// the [min, max] values for an 8-bit RGB image
const new_range = [0, 255];

const scale = createScaleFunction(old_range, new_range);

// apply this scale function to a bunch of numbers
scale(65535); // highest possible input value
255

scale(0); // lowest possible input value
0

scale(32767); // a value close to the middle
127.49805447470817

advanced usages

We can round, flip and do more advanced things by passing in an options object:

const scale = createScaleFunction(old_range, new_range, {
  // flip the scale, so higher and lower values are reversed
  // the typical use case is if you want higher data values to appear
  // darker in an RGB(A) image
  flip: true,

  // sometimes the difference between the min and max of a source range
  // will be zero, like when an image transparency band is all 255
  // if you'd like to provide a value to return in this case, set no_range_value
  no_range_value: -99,

  // if your input range is zero and you don't set no_range_value,
  // then quick-scale will return the "highest", "lowest", or "middle" value of the new range
  // the default is to return the highest value of the new range
  no_range_value_strategy: "lowest",

  // round the result
  round: true
});

scale(65535);
0 // the highest value becomes the lowest because flip was set to true

scale(0);
255 // the lowest value becomes the highest because flip was set to true

scale(32767);
128 // rounded result

alternatives

  • https://github.com/d3/d3-scale
  • https://github.com/AoDev/scale-number
  • https://github.com/javiercejudo/rescale-util
  • https://github.com/javiercejudo/linear-converter