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 🙏

© 2026 – Pkg Stats / Ryan Hefner

color-util-helpers

v0.0.21

Published

This is an Angular Module containing Components/Services using Material

Readme

Color Util Helpers

This lib contains a variety of very useful color utils

  • Color conversion (HEX<->RGB)
  • Generate a Color Pallette (from image - eg: Pintrest before image loads)
  • Color Extractor Directive (from inline image - eg: Pintrest before image loads)
  • Text Color - provides the color to use (you provide light and dark) based on color provided
  • Color Lighten Darken - Takes a color and you can darken or lighten
  • Generate Random Color - This function generates a random hue value between 0 and 360 degrees, and random saturation and lightness values between 50% and 100%.
  • Color Grabber - Directive when applied to a div will get the average color of the provided url of an image and then change the background color.

Installation

npm install color-util-helpers

Demo

Import the ColorUtilHelpersModule

add the selector <app-color-utilities-demo></app-color-utilities-demo>

Color Conversion Service

Converts RGB to HEX or HEX to RGB

Installation

npm install color-util-helpers

Usage

rgbToHex(rgb: number[]): string 

hexToRgb(hex: string): string

Color Pallette Service and Directive

Usage

Because this is a Directive - import the ColorExtractorDirective

define image path

this.colorSelectionService.getColorsFromImage('../assets/sample2.jpg')

Usage

this.colorSelectionService.palette.subscribe(data => this.palette = data)

Template Usage

<div *ngFor="let color of palette">
  <div style="display: flex;">
      <div 
          class="box"
          [style.background-color]="color.color"
      >
      Color
      </div>
      <div 
          class="box"
          [style.background-color]="color.complementaryColor"
      >
      Complementary
      </div>
  </div>
</div>

CSS Style

CSS
  .box {
    width: 100px; 
    height: 100px; 
    border: solid thin black; 
    color: black; 
    margin: 4px; 
    padding: 16px; 
    display: flex; 
    flex-wrap: wrap; 
    align-content: center; 
    justify-content: center;
}

Text Color Service

Provide a color that is used for a background and then provide the lightColor and darkColor The function will return the appropriate color based on the background color provided

Usage

This function takes bgColor and by providing the lightColor and darkColor compares them to the background and returns the color that will best work for the visibility of the background color.

These colors may be represented as RGB or HEX

textColorForBgColor(bgColor: string, lightColor: string, darkColor: string)

This function takes two colors and compares them and returns the darker color. The color may be represented as RGB or HEX

isColorDarker(color1: string, color2: string)

Color Lighten Darken Service

This function takes a color and percentage of lightness/darkness and returns the new color. The amount is a value between 0-1. This function changes the HSL of the color keeping the saturation values.

Example: .5 is 50%.

lighten(color: string, amount: number)
darken(color: string, amount: number)

Generate Random Color Service

This function takes a color '#3498db' and lightens the color by 20% and also darkens the color by 20%.

  const color = '#3498db'; // Your color
  const lighterColor = lighten(color, 0.2); // 20% lighter
  const darkerColor = darken(color, 0.2); // 20% darker

  console.log(lighterColor, darkerColor);

Color Grabber

This Angular Directive when applied to a div will get the average color of the provided url of an image and then change the background color to that color. Any test inside the div will be colored white or black based on the average color of the image that best suites it.

Usage

Because this is a Directive - import the ColorUtilitiesModule In the following example, the mat-card container has the colorGrab directive applied.

The [imageUrl]="image" is the image to grab the color from.

The [light]="'#FFFFFF'" is the light color to use if the average color is dark. The [dark]="'#000000'" is the dark color to use if the average color is light.

The mat-card contaner background color will change to this color

The Text inside this container will also change ether to black or white depending what suites best based on that colors image.

To use in the directive, use the following

image = "https://picsum.photos/id/1/5616/3744"
<mat-card style="margin: 8px;"
  colorGrab [imageUrl]="image" [light]="'rgb(220, 220, 220)'" [dark]="'rgb(47, 79, 79)'"
  class="box"
  >
    <h3>{{ item.author }}</h3>
    <img [src]="image" width="160" height="120" style="object-fit: cover;">
</mat-card>

Paramiter

imageUrl - provide the full URL of the image (png, jpg)

colorGrab [imageUrl]="item.download_url"