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

gradient-steps-string-generator

v0.0.4

Published

This project was bootstrapped with [TSDX](https://github.com/jaredpalmer/tsdx).

Downloads

2

Readme

Gradient Step/String Generator

This project was bootstrapped with TSDX.

Installation

yarn add gradient-steps-string-generator

or

npm i gradient-steps-string-generator

Basic Usage

With no arguments, generateGradientCSSString will return values from #000 to #fff over 11 stops.

import { generateGradientCSSString } from 'gradient-steps-string-generator';

const linearString = generateGradientCSSString();
// resolves to linear-gradient(45deg, rgb(0, 0, 0), rgb(26, 26, 26), rgb(51, 51, 51), rgb(77, 77, 77), rgb(102, 102, 102), rgb(128, 128, 128), rgb(153, 153, 153), rgb(179, 179, 179), rgb(204, 204, 204), rgb(230, 230, 230), rgb(255, 255, 255));

Standard Arguments

generateGradientCSSString takes an array of colors as it's first argument, colors can be formatted as hex, rgb(a), string, or hsl(a). The second argument is the number of color stops (plus 1).

import { generateGradientCSSString } from 'gradient-steps-string-generator';

const linearString = generateGradientCSSString(['red', 'blue'], 5);
// resolves to linear-gradient(45deg, rgb(255, 0, 0), rgb(204, 0, 51), rgb(153, 0, 102), rgb(102, 0, 153), rgb(51, 0, 204), rgb(0, 0, 255));

Options Argument

generateGradientCSSString takes an optional third argument. options has two properties customStepDirection and customStepStops. customStepDirection will replace 45deg in the returned string, you can use any string value (recommend (N)deg). customStepStops is an array of strings or empty indices. You can use this to apply percentage values after each new color value.

import { generateGradientCSSString } from 'gradient-steps-string-generator';

const linearString = generateGradientCSSString(['red', 'blue'], 5, {
        customStepDirection: 'to left',
        customStepStops: [,'30%', '50%']
      }));
// resolves to linear-gradient(to left, rgb(255, 0, 0), rgb(204, 0, 51) 30%, rgb(153, 0, 102) 50%, rgb(102, 0, 153), rgb(51, 0, 204), rgb(0, 0, 255));

generateGradientSteps

This package also exposes generateGradientSteps, which can be helpful if you need the raw values of each gradient step. This is particularly helpful with Canvas and SVGs. generateGradientSteps takes the same standard arguments as generateGradientCSSString and no optional arguments (I'd like to add a means of configuring the offset, but it seems best to do it case by case as shown below)

import { generateGradientSteps } from 'gradient-steps-string-generator';

const gradientSteps = generateGradientSteps(['red', 'blue'], 5);
// resolves to ['rgb(255, 0, 0)', 'rgb(204, 0, 51)', 'rgb(153, 0, 102)', 'rgb(102, 0, 153)', 'rgb(51, 0, 204)', 'rgb(0, 0, 255)']

<svg>
  ...
  {gradientSteps.map((color, i) => (
    <stop
      key={color}
      stopColor={color}
      offset={`${(i * 100) / (gradientSteps.length - 1)}%`}
    />
  ))}
</svg>