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

pex-ramp

v0.0.1

Published

Package description.

Downloads

42

Readme

pex-ramp

Create and sample numeric ramps and RGBA color gradients. Ramps and gradients are plain, JSON-serializable objects.

import {
  createRamp,
  createGradient,
  sampleRamp,
  sampleGradient,
} from "pex-ramp";

const ramp = createRamp();
const gradient = createGradient();

const value = sampleRamp(ramp, 0.5); // Approximately 0.5
const color = sampleGradient(gradient, 0.5); // [r, g, b, a]

createRamp()

Returns a new numeric ramp with a smooth Bézier transition from 0 to 1. Takes no arguments; each call creates independent points and handles.

const ramp = createRamp();
// {
//   type: "ramp",
//   version: 1,
//   interpolation: "bezier",
//   points: [
//     { position: 0, value: 0, handleMode: "smooth", out: [1 / 3, 0] },
//     { position: 1, value: 1, handleMode: "smooth", in: [2 / 3, 1] },
//   ],
// }

Set interpolation to "linear" for straight segments or "bezier" for cubic Bézier segments. Handles use absolute [position, value] coordinates, not offsets. Missing handles default to one third of the straight segment from the corresponding endpoint.

A ramp requires at least two points with strictly increasing positions in [0, 1], starting at 0 and ending at 1. Values and handle coordinates are also in [0, 1]; handles stay within their adjacent segment's position range.

createGradient()

Returns a new opaque black-to-white gradient. Takes no arguments; each call creates independent stops and colors.

const gradient = createGradient();
// {
//   type: "gradient",
//   version: 1,
//   interpolation: "smooth",
//   colorSpace: "oklab",
//   stops: [
//     { position: 0, color: [0, 0, 0, 1] },
//     { position: 1, color: [1, 1, 1, 1] },
//   ],
// }

Each stop has a position and an sRGB color array [r, g, b, a], with all components in [0, 1]. A gradient requires at least two stops with strictly increasing positions in [0, 1]. The first and last stops can be anywhere within that range; their colors extend outward.

| interpolation | Behavior | | --- | --- | | "linear" | Straight interpolation between adjacent stops. | | "smooth" | Monotone cubic interpolation per channel in the selected color space. | | "step" | Hold each stop's color until the next stop, then switch immediately. |

| colorSpace | RGB interpolation space | | --- | --- | | "oklab" | Oklab; the default for new gradients. | | "srgb" | Interpolate encoded sRGB components directly. Also used when colorSpace is omitted. | | "linear" | Convert sRGB to linear RGB before interpolation. |

Input and output RGB values remain sRGB regardless of the interpolation space. Alpha is interpolated separately, without premultiplying RGB. Step mode copies the stop color directly, regardless of color space.

sampleRamp(ramp, t)

Returns the numeric value of ramp at position t without modifying the ramp.

| Parameter | Description | | --- | --- | | ramp | A valid ramp object. | | t | Finite numeric position, clamped to [0, 1]. |

For Bézier ramps, t is the horizontal position on the curve, not the Bézier parameter. The sampler solves for that position before evaluating the value.

const ramp = createRamp();
ramp.interpolation = "linear";
ramp.points = [
  { position: 0, value: 0 },
  { position: 0.5, value: 1 },
  { position: 1, value: 0 },
];

sampleRamp(ramp, 0.25); // 0.5
sampleRamp(ramp, 0.5); // 1
sampleRamp(ramp, 2); // 0 (last point)

Throws RangeError if t is not finite, including NaN and infinities. The ramp structure is expected to be valid and is not validated during sampling.

sampleGradient(gradient, t, out?)

Returns the RGBA color of gradient at position t without modifying the gradient. Before the first stop or after the last, returns that endpoint's color. At a stop's exact position, returns that stop's color.

| Parameter | Description | | --- | --- | | gradient | A valid gradient object. | | t | Finite numeric position, usually in [0, 1]. | | out | Optional writable array or floating-point typed array with room for four components. Written to and returned. Defaults to a new array. |

const gradient = createGradient();
gradient.interpolation = "linear";
gradient.colorSpace = "srgb";
gradient.stops = [
  { position: 0, color: [1, 0, 0, 1] },
  { position: 1, color: [0, 0, 1, 0.5] },
];

sampleGradient(gradient, 0.5); // [0.5, 0, 0.5, 0.75]

const out = new Float32Array(4);
sampleGradient(gradient, 0.5, out); // Returns out

For three equally sized color zones, use step interpolation with stops at 0, 1/3, and 2/3. The final color extends to 1 and beyond. Uniformly distributed t values in [0, 1] then select each color with equal probability.

const palette = createGradient();
palette.interpolation = "step";
palette.stops = [
  { position: 0, color: [1, 0, 0, 1] },
  { position: 1 / 3, color: [0, 1, 0, 1] },
  { position: 2 / 3, color: [0, 0, 1, 1] },
];

sampleGradient(palette, 0.2); // [1, 0, 0, 1]
sampleGradient(palette, 1 / 3); // [0, 1, 0, 1]
sampleGradient(palette, 0.9); // [0, 0, 1, 1]

Throws RangeError if t is not finite, including NaN and infinities. The gradient structure is expected to be valid and is not validated during sampling.