
Research
NPM targeted by malware campaign mimicking familiar library names
Socket uncovered npm malware campaign mimicking popular Node.js libraries and packages from other ecosystems; packages steal data and execute remote code.
advanced-color-utils
Advanced tools
Unleash the full potential of color manipulation with the ColorUtils library! Designed for developers who need precise control over color processing
A TypeScript library for working with colors, providing functionality to find distinct colors from a list based on a similarity threshold.
Unleash the full potential of color manipulation with the ColorUtils library! Designed for developers who need precise control over color processing, this TypeScript library provides powerful tools to efficiently find and manipulate distinct colors from any color palette. Whether you're working on data visualization, graphic design, or user interface development, ColorUtils ensures your colors are perfectly balanced and aesthetically pleasing.
Install the library using npm:
npm install advanced-color-utils
You can import the ColorUtils class from the library as follows:
import { ColorUtils } from '@color-utils/ColorUtils';
getDistinctColors
Finds a specified number of distinct colors from a list based on a similarity threshold.
- Parameters:
hexColors
(string[]): The list of hex color strings (e.g., ['#ff0000', '#00ff00']
).
numColors
(number): The number of distinct colors to retrieve.
threshold
(number): The threshold for color similarity (lower values mean more similar).
- Returns:
(string[]): The list of distinct hex color strings.
- Example:
const colors = ['#ff0000', '#00ff00', '#0000ff', '#ff00ff'];
const numColorsToRetrieve = 2;
const threshold = 20;
const distinctColors = ColorUtils.getDistinctColors(colors, numColorsToRetrieve, threshold);
console.log(distinctColors); // Output: ['#ff0000', '#00ff00']
labToHex
Converts a LAB color to a hex color string.
- Parameters:
lab
(LabColor): The LAB color object.
- Returns:
(string): The hex color string.
- Example:
const lab = { L: 53.23288, a: 80.10933, b: 67.22006 };
const hex = ColorUtils.labToHex(lab);
console.log(hex); // Output: '#ff0000'
hexToLab
Converts a hex color to a LAB color object.
- Parameters:
hex
(string): The hex color string (e.g., '#ff0000').
- Returns:
(LabColor): The LAB color object.
- Example:
const hex = '#ff0000';
const lab = ColorUtils.hexToLab(hex);
console.log(lab); // Output: { L: 53.23288, a: 80.10933, b: 67.22006 }
rgbToHex
Converts an RGB color to a hex color string.
- Parameters:
rgb
(RGBColor): The RGB color object.
- Returns:
(string): The hex color string.
- Example:
const rgb = { R: 255, G: 0, B: 0 };
const hex = ColorUtils.rgbToHex(rgb);
console.log(hex); // Output: '#ff0000'
hexToRgb
Converts a hex color to an RGB color object.
- Parameters:
hex
(string): The hex color string (e.g., '#ff0000').
- Returns:
(RGBColor): The RGB color object. - Example:
const hex = '#ff0000';
const rgb = ColorUtils.hexToRgb(hex);
console.log(rgb); // Output: { R: 255, G: 0, B: 0 }
generateColorPalette
Generates a color palette based on a given hex color and the desired number of colors.
- Parameters:
hex
(string): The hex color string (e.g., '#ff0000').
numColors (number): The number of colors in the palette.
- Returns:
(string[]): The array of hex color strings in the palette.
- Example:
const palette = ColorUtils.generateColorPalette('#ff0000', 5);
console.log(palette); // Output: ['#ff0000', '#ff3333', '#ff6666', '#ff9999', '#ffcccc']
getComplementaryColor
Generates a complementary color for a given hex color.
- Parameters:
hex
(string): The hex color string (e.g., '#ff0000').
- Returns:
(string): The complementary hex color string.
- Example:
const complementaryColor = ColorUtils.getComplementaryColor('#ff0000');
console.log(complementaryColor); // Output: '#00ffff'
generateShades
Generates a list of shades from a base color.
- Parameters:
hex
(string): The base hex color string (e.g., '#ff0000').
numShades
(number): The number of shades to generate.
- Returns:
(string[]) An array of hex color strings representing the shades.
- Example:
const shades = ColorUtils.generateShades('#ff0000', 5);
console.log(shades); // Output: ['#ff0000', '#bb1909', '#7a1b0c', '#3f1508', '#000000']
generateTints
Generates a list of tints from a base color.
- Parameters:
hex
(string): The base hex color string (e.g., '#ff0000').
numTints
(number): The number of tints to generate.
- Returns:
(string[]) An array of hex color strings representing the tints.
- Example:
const tints = ColorUtils.generateTints('#ff0000', 5);
console.log(tints); // Output: ['#ff0000', '#ff4040', '#ff8080', '#ffbfbf', '#ffffff']
blendColors
Blends two hex colors together.
- Parameters:
color1
(string): The first hex color string.
color2
(string): The second hex color string.
ratio
(number): The ratio of blending (0 to 1). 0 means full color1, 1 means full color2.
colorSpace
(InterpolationMode): The color space to use for blending (default is 'lab').
Possible values for colorSpace
are "rgb" | "hsl" | "hsv" | "hsi" | "lab" | "oklab" | "lch" | "oklch" | "hcl" | "lrgb"
- Returns:
(string) The blended hex color string.
Example:
const blendedColor = ColorUtils.blendColors('#ff0000', '#0000ff', 0.5, 'lab');
console.log(blendedColor); // Output: '#b400b4'
hexToHsl
Converts a hex color string to an HSL object.
- Parameters:
hex
(string): The hex color string (e.g., '#ff0000').
- Returns:
(HSLColor) The HSL color object.
- Example:
const hsl = ColorUtils.hexToHsl('#ff0000');
console.log(hsl); // Output: { h: 0, s: 100, l: 50 }
getContrastRatio
Calculates the contrast ratio between two hex colors.
- Parameters:
color1
(string): The first hex color string.
color2
(string): The second hex color string.
- Returns:
(number) The contrast ratio.
- Example:
const ratio = ColorUtils.getContrastRatio('#ff0000', '#0000ff');
console.log(ratio); // Output: 4.5
generateRandomColor
Generates a random hex color.
- Returns: (string) The random hex color string.
- Example:
const randomColor = ColorUtils.generateRandomColor();
console.log(randomColor); // Output: e.g., '#a1b2c3'
generateAnalogousColors
Generates a list of analogous colors based on a base color.
Parameters:
hex
(string): The base hex color string (e.g., '#ff0000').
numColors
(number): The number of analogous colors to generate.
- Returns:
(string[]) An array of hex color strings representing the analogous colors.
- Example:
const analogousColors = ColorUtils.generateAnalogousColors('#ff0000', 5);
console.log(analogousColors); // Output: ['#ff0000', '#ff3333', '#ff6666', '#ff9999', '#ffcccc']
This library is licensed under the MIT License.
Feel free to contribute or report issues via the GitHub repository.
FAQs
Unleash the full potential of color manipulation with the ColorUtils library! Designed for developers who need precise control over color processing
The npm package advanced-color-utils receives a total of 12 weekly downloads. As such, advanced-color-utils popularity was classified as not popular.
We found that advanced-color-utils demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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.
Research
Socket uncovered npm malware campaign mimicking popular Node.js libraries and packages from other ecosystems; packages steal data and execute remote code.
Research
Socket's research uncovers three dangerous Go modules that contain obfuscated disk-wiping malware, threatening complete data loss.
Research
Socket uncovers malicious packages on PyPI using Gmail's SMTP protocol for command and control (C2) to exfiltrate data and execute commands.