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

@phantom-factotum/colorutils

v0.0.1-a

Published

Color utilities. Color generation, basic color schemes, lighten/darken colors, console logging with color,etc.

Downloads

6

Readme

Color Generator

Dynamically generate colors create simple schemes, and do simple color manipulation

Usage

import {
  colorGenerator,
  colorManipulators,
  logColors,
  colorSchemes,
} from "@phantom-factotum/colorgenerator";

const totalColors = 28;
const startColor = "#5432FC";
const genConfig = {
  generatorType: "randomSchemes",
  startColor,
};
const printConfig = {
  printColors: true,
  // colors per line when printing
  itemsPerLine: 6,
  // whether to show hexCode when printing
  showHexCode: true,
};
const logText = text => {
  logColorText(text, {
    textColor: "#2446DD",
    bgColor: "#7E8FDE",
  });
};

logText("Printing colors with console");
const colors = colorGenerator(totalColors, genConfig);
console.log(colors);

logText("Colors printed using chalk");
logColors(colors, printConfig);

logText("Generating tetradic color scheme from", startColor);
const colorScheme = colorSchemes.getTetradicScheme(startColor);
logColors(colorScheme);

let lightenedColors = colors.map(color =>
  colorManipulators.lightenColor(color, 0.15)
);
logText("Generated colors, but a little lighter:");
logColors(lightenedColors, printConfig);

let darkenedColors = colors.map(color =>
  colorManipulators.darkenColor(color, 0.18)
);
logText("Generated colors, but a little  darker:");
logColors(darkenedColors, printConfig);

colorGenerator(length,generatorConfig)

  • length: <number>
  • generatorConfig: <object>Properties shared by all generators:
    • generatorType: <"goldenRatio | "randomSchemes |"random">
    • startColor: <string> first color in list

    goldenRatio

    Uses the golden ratio in HSV color space to distance colors. Color distance isnt checked, but colors usually are distinctgoldenRatio config properties:
    • startHue: <number> [0-1] If startColor is provided, then startHue will be startColor's hue
    • hueOffset: <number>
    • saturation: <number> [0-1]
    • useRandom: <boolean> introduces random variations to colors
    • variationRatio: <number> [0-1] that determines useRandom maximum color variation

    randomScheme

    Grabs a random color, generates the triadic scheme for that color, removes similar colors, and repeats until desired length is reachedrandomSchemes config properties:
    • thresholdLevelAttempts: <number> number of times to attempt getting colors before decreasing threshold level
    • attemptMultipler: <number> each time the threshold level decreases thresholdLevelAttempts will be multiplied by this value
    • startThreshold: <string | number>

    random

    Grabs random colors. Does not attempt to remove similar colors

returns <array> of hexcodes


function logColors(colors,config)

  • colors: <array> list of hexcodes
  • printConfig: <object>
    • itemsPerLine: <number>
    • showHexCode: <boolean> print hexcode
    • invertTextColor:<boolean> print text in background color complement

returns <array> of logColorText


function logColorText(text,config)

  • text: <string>
  • config: <object>
    • bgColor:<string> hexcode
    • textColor:<string> hexcode
    • printColor:<boolean> whether to log result

returns <string> manipulated with chalk.js to log colors


colorManipulators

Object containing color manipulator functions:

  • lightenColor(color,ratio)
    • ratio: <number> [0-1] (recommend [0-0.5])
  • darkenColor(color,ratio)
    • ratio: <number> [0-1] (recommend [0-0.5])
  • alterHSVByRatio(color,{h,s,v})
    • h | s | v : <number> [0-1]
  • setColorOpacity(color,opacity)
    • opacity: <number> between 0-1
  • RGBAToHex(rgba)
    • rgba: <string> rgba string
  • blend(color1,color2,alpha)
    • color1 | color2 <string>
    • alpha <number> [0-1] blend value

colorSchemes

Object containing scheme functions. Every scheme returns <array>

  • getComplementary(color)
  • getTetradicScheme(color)
  • getTriadicScheme(color)
  • getNeutralScheme(color)
  • getAnalogousScheme(color)
  • getAllSchemes(color)