Package Exports
- javascript-color-gradient
- javascript-color-gradient/src
- javascript-color-gradient/src/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (javascript-color-gradient) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme

JavasScript Color Gradient
Lightweight JavaScript library, used to generate an array of color gradients by providing start and finish colors, as well as the required number of midpoints.
Installation
For Node.js: Install the javascript-color-gradient
npm module:
npm install javascript-color-gradient
Then import the module into your JavaScript:
import Gradient from "javascript-color-gradient";
Demo
A demo is worth a thousand words.
Note: All the examples are using ES6, be sure is supported in your browser or modify as needed, Chrome recommended.
Methods
Method | Description | |
---|---|---|
setGradient() |
Initializes colorGradient with two or more hex color values. Should always be defined. |
|
setMidpoint(n) |
Defines number of midpoints. Defaults to 10. | |
getArray() |
Returns an array of hex color values . | |
getColor(n) |
Returns single hex color value corresponding to the provided index. |
Let's see them in action:
console.log(colorGradient.getArray());
// ["#4e4ab9", "#5d68c4", "#6d86ce", "#7ca4d9", "#8bc2e3"]
console.log(colorGradient.getColor(3));
// #6d86ce
Usage
Using two color gradients
import Gradient from "javascript-color-gradient";
colorGradient.setGradient("#3F2CAF", "#8BC2E3");
Or more:
import colorGradient from "javascript-color-gradient";
colorGradient.setGradient("#3F2CAF", "#e9446a", "#edc988", "#607D8B");
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
License
javascript-color-gradient
is MIT licensed.
Contributors
Special thanks to all the contributors who have contributed for this project.