Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

smooth-gradient

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

smooth-gradient

Generates a gradient and can return a calculated color from an input

  • 2.4.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

smooth-gradient.js Test

Calculate a gradient and get one of its colors at a given point, from an array of colors.

Install the smooth-gradient module

npm install smooth-gradient

Add it to your source.

import { Gradient } from "smooth-gradient"

Usage

A single class is exposed, Gradient, which takes as much color elements as you want as parameters, and the amount of steps to use.

// Colors can be given as an unlimited number of parameters
const gradient = new Gradient("#FF0000", "#00FF00", "#00FFFF", "#123456");

You can now retreive the color corresponding to your input in the gradiant spectrum. Only values between 0 and 100 are effective. Negatives will be considered as 0 and values above 100 as 100.

const color = gradient.getColorFromValue(50, 'rgb');
const colorHex = gradient.getColorFromValue(50);
console.log(color); // output => rgb(0, 255, 180)
console.log(colorHex); // output => #00ffb4

This package could be a great fit for gradients in progress bars, for example.

FAQs

Package last updated on 30 Sep 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc