Registry / data / javascript-color-gradient

javascript-color-gradient

JSON →
library2.5.0jsnpmunverified

javascript-color-gradient is a lightweight JavaScript library designed for generating an array of color gradients. It allows users to define a gradient by providing two or more hexadecimal start and end colors, along with the desired number of midpoints. The library is currently at version 2.5.0 and appears to have an active, though not rapid, release cadence with updates focused on improvements and bug fixes, such as refactoring color generation logic and adding support for short hex codes in its most recent release. Its key differentiator is its simplicity and direct focus on generating color arrays for gradients, making it suitable for web and Node.js projects requiring programmatic color interpolation without complex UI components. It avoids external dependencies, offering a lean solution for color manipulation.

data
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

The library primarily uses ES modules (ESM). CommonJS `require()` may not work as expected in newer versions without specific transpilation or Node.js 'type: module' configuration.

import Gradient from 'javascript-color-gradient'

For dynamic ESM imports in environments that support it, or when mixing with CommonJS contexts.

const { default: Gradient } = await import('javascript-color-gradient')

Demonstrates how to initialize a gradient with two colors and retrieve an array of 10 interpolated hex color values.

import Gradient from "javascript-color-gradient"; const startColor = "#3F2CAF"; const endColor = "#e9446a"; const numberOfMidpoints = 10; // Default if not set const gradientGenerator = new Gradient(); const gradientArray = gradientGenerator .setColorGradient(startColor, endColor) .setMidpoint(numberOfMidpoints) // Explicitly setting, though it's the default .getColors(); console.log(gradientArray); /* Example output: [ '#3f2caf', '#522fa7', '#6531a0', '#783498', '#8b3790', '#9d3989', '#b03c81', '#c33f79', '#d64172', '#e9446a' ] */
Debug
Known footguns
breakingThe gradient color generation logic was refactored in v2.5.0. While intended as an improvement, it might introduce subtle changes in the interpolated color values.
breakingThe library's initialization method became more intuitive in v2.3.2, moving towards chained method calls (e.g., `new Gradient().setColorGradient(...)`). Older, direct constructor parameter patterns might be deprecated or no longer supported.
gotchaPrior to v2.5.0, there was a bug where the first color in the gradient might have been skipped from the output array returned by `getColors()`.
gotchaShort hex codes (e.g., `#fff`) were not supported before v2.5.0; only full 6-digit hex codes (e.g., `#ffffff`) were accepted.
gotchaThe library is written using ES6 syntax (e.g., `import`/`export`). Older browser environments or Node.js versions without full ES module support may require transpilation (e.g., Babel) or different module loading configurations.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
0 hits · last 30 days

No traffic data recorded yet.

Resources