Socket
Socket
Sign inDemoInstall

@convergence/color-assigner

Package Overview
Dependencies
1
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @convergence/color-assigner

Assigned colors to unique resources


Version published
Weekly downloads
162
decreased by-28%
Maintainers
1
Install size
155 kB
Created
Weekly downloads
 

Readme

Source

Color Assigner

Build Status

The color assigner will manage assigning consistent colors to unique resources in your application. This could be users, labels, etc. You may define a palette or preferred colors to use. The colors from the palette will be used in a least recently used (LRU) fashion. If a color from the palette is available, it will be assigned. Otherwise, a random color will be generated. When a resource no longer needs the color, the color may be released. If a color being released is one from the palette, it will be place on the end of the list of available palette colors.

Installation

npm install --save @convergence/color-assigner or npm install --save-dev @convergence/color-assigner

Basic Usage

// Create a new ColorAssigner using the default palette of colors.
import {ColorAssigner} from "@convergence/color-assigner";

const ca = new ColorAssigner();

// Get a new color for "id1"
const color1a = ca.getColorAsHex("id1");

// The same color will be returned again
const color1b = ca.getColorAsHex("id1");

// Release the color
ca.releaseColor("id1");

// A new color will be returned for id1.
const color1b = ca.getColorAsHex("id1");

// Get a color as an rgba string e.g. 'rgba (234, 40, 132, 255)'
const color2 = ca.getColorAsRgba("id2");

Advanced Usage

// Create a new ColorAssigner using one of the built in palettes.
import {ColorAssigner} from "@convergence/color-assigner";

const ca1 = new ColorAssigner(ColorAssigner.Palettes.DEFAULT);
const ca2 = new ColorAssigner(ColorAssigner.Palettes.DARK_12);
const ca3 = new ColorAssigner(ColorAssigner.Palettes.LIGHT_12);

// Create a new ColorAssigner using your own palette. 
// Any css color format is acceptable.
const colors = [
  'royalblue',               // css color name
  '#ff0000',                 // hex
  'rgba(128, 255, 128, 255)' // rgba
];
const ca4 = new ColorAssigner(colors);

Keywords

FAQs

Last updated on 24 Jan 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc