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

@calvin-coomer/avatar-color-picker

v1.0.6

Published

Generate avatar material colors from a string

Downloads

4

Readme

Color Picker

This TypeScript module provides functions to get a color based on a string input and predefined options. It includes functionality to restrict colors to certain shades, exclude certain categories, and supports methods for retrieving RGB, Hex, and font colors.

Features

  • Get color based on string input: Converts a string to a color by hashing the string and selecting a color from a predefined list.
  • Customizable options: Allows for customizing the available shades, excluded categories, and theme.
  • RGB and Hex methods: Provides methods to retrieve the RGB and Hex values of the selected color.
  • Font color determination: Provides a method to determine the appropriate font color based on the selected color's brightness.

Installation

To use this module, you need to include it in your TypeScript project. You can install it via npm or yarn:

npm install @calvin-coomer/avatar-color-picker

or

yarn add @calvin-coomer/avatar-color-picker

Usage

Here's how you can use the getColor function and its associated methods:

Importing the Module

import { getColor, Category, Shade, Options } from '@calvin-coomer/avatar-color-picker';

Getting a Color

const color = getColor('calvin coomer');
console.log(color);

Getting RGB Value

const rgb = getColor.rgb('calvin coomer');
console.log(rgb);

Getting Hex Value

const hex = getColor.hex('calvin coomer');
console.log(hex);

Getting Font Color

const fontColor = getColor.fontColor('calvin coomer');
console.log(fontColor);

Customizing Options

You can customize the options for getColor by providing an Options object:

const options: Options = {
  shades: [Shade.Shade300, Shade.Shade400, Shade.Shade500],
  excludeCategories: [Category.red, Category.pink],
  darkTheme: true,
  lightFontColor: '#FFFFFF',
  darkFontColor: '#000000',
};

const customColor = getColor('calvin coomer', options);
console.log(customColor);

API

Enums

  • Category: Defines the available color categories.
  • Shade: Defines the available color shades.

Interfaces

  • Color: Represents a color object.

    • category: Category
    • shade: Shade
    • rgb: string
    • hex: string
    • font: boolean
  • Options: Represents the options for color selection.

    • excludeCategories: Category[]
    • shades: Shade[]
    • darkTheme: boolean
    • lightFontColor: string
    • darkFontColor: string

Functions

  • getColor(str: string, options?: Options): Color

    • Returns a color object based on the string input and options.
  • getColor.rgb(str: string, options?: Options): string

    • Returns the RGB value of the color.
  • getColor.hex(str: string, options?: Options): string

    • Returns the Hex value of the color.
  • getColor.fontColor(str: string, options?: Options): string

    • Returns the appropriate font color based on the color's brightness and the provided options.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Contributing

Contributions are welcome! Please open an issue or submit a pull request on GitHub.