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

v0.2.0

Published

A class for generating gradients.

Downloads

1,447

Readme

Gradient.js

Generate you some gradients! Gradient.js is built on top of harthur/color https://github.com/harthur/color.

Using Gradient.js Server-side

Install the gradient module

npm install gradient

Add it to your source.

var Gradient = require('gradient');

Using Gradient.js Client-side

There are two ways to go about this.

Option 1.) Download gradient-min.js from github and include it within your page.

<script src="gradient-min.js"></script>

Option 2.) Build your own uncompressed or minified copy.

If you don't have Jake installed...

$ npm install -g jake

Then build and minify...

$ jake build
$ jake minify

Usage

A single class is exposed, Gradient, which takes a list of colors stops and steps.

// Colors can be given as an unlimited number of parameters.  Steps is always the last parameter
var grad = Gradient('#0071bc', '#662d91', '#e5005d', 10);

// Or they can be given as an array
var colorStops = ['#0071bc', '#662d91', '#e5005d'];
var grad = Gradient(colorStops, 10);

Colors can be inputted in any of mulitple formats: hex, rgb string, rgba string, or rgb hash.

var grad = Gradient('#0071bc', 'rgb(255, 67, 100)', { r: 100, g: 50, b: 10 }, 10);

The return value is a class instance which contains a .toArray method. If run without arguments this method will return an array of Color objects derived from https://github.com/harthur/color.

var grad = Gradient('#0071bc', '#662d91', '#e5005d', 10);
var colors = grad.toArray();

Optionally, a string value can be given indication the output format.

Possible values: hexString, rgbString, percentString, named

var grad = Gradient('#0071bc', '#662d91', '#e5005d', 10);
console.log(grad.toArray('hexString'));

>>>
[ '#0071BC',
  '#0F31AE',
  '#351D9F',
  '#652C90',
  '#662D91',
  '#662D91',
  '#9F1FAB',
  '#C71199',
  '#E6005C',
  '#E5005D' ]

Using Gradients in gRaphel Charts

Generate awesome colors for your gRaphael pie charts.

var paper = Raphael(10, 50, 640, 480);
var data = [55, 20, 13, 32, 5, 1, 2];
var colors = Gradient('#97aeba', '#0a3d54', data.length).toArray('rgbString');
paper.piechar(320, 240, 100, data, { colors: colors });

Stupid Gradient Tricks

Bring back 1998 with rainbow HTML.

function rainbowString (s) {
    var grad = Gradient('#0071bc', '#662d91', '#e5005d', s.length);
    return grad.toArray('hexString').map(function (x, i){
        return '<span>' + s[i] + '</span>';
    }).join('');
};

document.write(rainbowString("Hello World!"));

Running the Tests

node test/test.js