mcpField
C
color-utilities-in-javascript

color-utilities-in-javascript

github.com/rodydavisDevelopment6044 installsUpdated 2w ago
Repository

About color-utilities-in-javascript

A JavaScript reference for common color conversions, aimed at developers working with color values. It provides code examples for converting between RGB, HSL, and HEX formats.

Key features

  1. 01Convert RGB to HSL
  2. 02Convert HEX to RGB
  3. 03Convert HSL to HEX

Use cases

  1. 01Convert user-entered HEX colors for RGB-based code
  2. 02Change RGB values into HSL for color handling

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/rodydavis/skills --skill color-utilities-in-javascript

After installing, type/color-utilities-in-javascriptin Claude Code to confirm it loaded.

Details

From the project README

Color Utilities in JavaScript

Color utilities generated by GitHub Copilot.

Convert an RGB color to HSL
function rgbToHsl(r, g, b) {
    r /= 255;
    g /= 255;
    b /= 255;
    var max = Math.max(r, g, b);
    var min = Math.min(r, g, b);
    var h, s, l = (max + min) / 2;
    if (max == min) {
        h = s = 0;
    } else {
        var d = max - min;
        s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
        switch (max) {
            case r:
                h = (g - b) / d + (g < b ? 6 : 0);
                break;
            case g:
                h = (b - r) / d + 2;
                break;
            case b:
                h = (r - g) / d + 4;
                break;
        }
        h /= 6;
    }
    return [h, s, l];
} 
Convert HEX to RGB
function hexToRgb(hex) {
    var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
    return result ? {
        r: parseInt(result[1], 16),
        g: parseInt(result[2], 16),
        b: parseInt(result[3], 16)
    } : null;
}
Convert HSL to HEX
function hslToHex(h, s, l) {
    var r, g, b;
    if (s == 0) {
        r = g = b = l;
    } else {
        var hue2rgb = function hue2rgb(p, q, t) {
            if (t < 0) t += 1;
            if (t > 1) t -= 1;
            if (t < 1 / 6) return p + (q - p) * 6 * t;
            if (t < 1 / 2) return q;
            if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
            return p;
        };
        var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
        var p = 2 * l - q;
        r = hue2rgb(p, q, h + 1 / 3);
        g = hue2rgb(p, q, h);
        b = hue2rgb(p, q, h - 1 / 3);
    }
    return "#" + (1 << 24 | r << 16 | g << 8 | b).toString(16).slice(1);
}

Comments

Markdown supported