
Security News
How Enterprise Security Is Adapting to AI-Accelerated Threats
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.
@convergence/color-assigner
Advanced tools
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.
npm install --save @convergence/color-assigner
or
npm install --save-dev @convergence/color-assigner
// 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");
// 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);
FAQs
Assigned colors to unique resources
We found that @convergence/color-assigner demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.

Security News
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.