### Install color2k Source: https://color2k.com/ Install the library using npm. ```bash npm i color2k ``` -------------------------------- ### Basic Usage Source: https://color2k.com/ Import and use color manipulation functions. ```javascript import { darken, transparentize } from 'color2k'; // e.g. darken('blue', 0.1); transparentize('red', 0.5); ``` -------------------------------- ### Import color2k via Skypack Source: https://color2k.com/ Use the library directly in supported environments like Deno or modern browsers. ```javascript import { darken, transparentize } from 'https://cdn.skypack.dev/color2k?min'; ``` -------------------------------- ### getScale(colors) Source: https://color2k.com/ Creates a scale function from a series of colors. ```APIDOC ## getScale(colors) ### Description Given a series colors, this function will return a scale(x) function that accepts a percentage as a decimal between 0 and 1 and returns the color at that percentage in the scale. ### Parameters #### Path Parameters - **colors** (string[]) - Required ``` -------------------------------- ### getContrast(color1, color2) Source: https://color2k.com/ Calculates the contrast ratio between two colors. ```APIDOC ## getContrast(color1, color2) ### Description Returns the contrast ratio between two colors based on W3's recommended equation for calculating contrast. ### Parameters #### Path Parameters - **color1** (string) - Required - **color2** (string) - Required ``` -------------------------------- ### Create Color Scales Source: https://color2k.com/ Generate a scale function from a series of colors to interpolate values. ```javascript const scale = getScale('red', 'yellow', 'green'); console.log(scale(0)); // rgba(255, 0, 0, 1) console.log(scale(0.5)); // rgba(255, 255, 0, 1) console.log(scale(1)); // rgba(0, 128, 0, 1) ``` ```javascript const _scale = getScale('red', 'yellow', 'green'); const scale = x => _scale(x / 100); console.log(scale(0)); // rgba(255, 0, 0, 1) console.log(scale(50)); // rgba(255, 255, 0, 1) console.log(scale(100)); // rgba(0, 128, 0, 1) ``` -------------------------------- ### Color Conversion and Parsing Source: https://color2k.com/ Functions for converting between color formats and parsing color strings into numerical components. ```APIDOC ## hsla(hue, saturation, lightness, alpha) ### Description Takes in hsla parts and constructs an hsla string. ### Parameters #### Request Body - **hue** (number) - Required - The color circle (0-360) - **saturation** (number) - Required - Percentage as decimal (0-1) - **lightness** (number) - Required - Percentage as decimal (0-1) - **alpha** (number) - Required - Percentage as decimal (0-1) ## rgba(red, green, blue, alpha) ### Description Takes in rgba parts and returns an rgba string. ### Parameters #### Request Body - **red** (number) - Required - 0-255 - **green** (number) - Required - 0-255 - **blue** (number) - Required - 0-255 - **alpha** (number) - Required - 0-1 ## parseToHsla(color) ### Description Parses a color in hue, saturation, lightness, and the alpha channel. ## parseToRgba(color) ### Description Parses a color into red, green, blue, alpha parts. ``` -------------------------------- ### hasBadContrast(color, standard, background) Source: https://color2k.com/ Checks if a color has bad contrast against a background. ```APIDOC ## hasBadContrast(color, standard, background) ### Description Returns whether or not a color has bad contrast against a background according to a given standard. ### Parameters #### Path Parameters - **color** (string) - Required - **standard** ('decorative' | 'readable' | 'aa' | 'aaa') - Optional - Default: 'aa' - **background** (string) - Optional - Default: '#fff' ``` -------------------------------- ### getLuminance(color) Source: https://color2k.com/ Returns the luminance of a color. ```APIDOC ## getLuminance(color) ### Description Returns a number (float) representing the luminance of a color. ### Parameters #### Path Parameters - **color** (string) - Required ``` -------------------------------- ### desaturate(color, amount) Source: https://color2k.com/ Desaturates the input color by the given amount. ```APIDOC ## desaturate(color, amount) ### Description Desaturates the input color by the given amount via subtracting from the s in hsla. ### Parameters #### Path Parameters - **color** (string) - Required - **amount** (number) - Required - The amount to desaturate, given as a decimal between 0 and 1 ``` -------------------------------- ### Color Manipulation Functions Source: https://color2k.com/ Functions for modifying color properties such as lightness, saturation, and opacity. ```APIDOC ## lighten(color, amount) ### Description Lightens a color by a given amount. This is equivalent to darken(color, -amount). ### Parameters #### Request Body - **color** (string) - Required - **amount** (number) - Required - The amount to darken, given as a decimal between 0 and 1 ## saturate(color, amount) ### Description Saturates a color by converting it to hsl and increasing the saturation amount. Equivalent to desaturate(color, -amount). ### Parameters #### Request Body - **color** (string) - Required - Input color - **amount** (number) - Required - The amount to darken, given as a decimal between 0 and 1 ## opacify(color, amount) ### Description Takes a color and un-transparentizes it. Equivalent to transparentize(color, -amount). ### Parameters #### Request Body - **color** (string) - Required - **amount** (number) - Required - The amount to increase the opacity by, given as a decimal between 0 and 1 ## transparentize(color, amount) ### Description Takes in a color and makes it more transparent by converting to rgba and decreasing the amount in the alpha channel. ### Parameters #### Request Body - **color** (string) - Required - **amount** (number) - Required - The amount to increase the transparency by, given as a decimal between 0 and 1 ``` -------------------------------- ### Color Analysis Source: https://color2k.com/ Functions for analyzing color properties and determining contrast. ```APIDOC ## readableColor(color) ### Description Returns black or white for best contrast depending on the luminosity of the given color. ## readableColorIsBlack(color) ### Description Returns whether or not the readable color should be black. ``` -------------------------------- ### guard(low, high, value) Source: https://color2k.com/ Clamps a value between a low and high range. ```APIDOC ## guard(low, high, value) ### Description A simple guard function: Math.min(Math.max(low, value), high) ### Parameters #### Path Parameters - **low** (number) - Required - **high** (number) - Required - **value** (number) - Required ``` -------------------------------- ### adjustHue(color, degrees) Source: https://color2k.com/ Adjusts the current hue of the color by the given degrees. ```APIDOC ## adjustHue(color, degrees) ### Description Adjusts the current hue of the color by the given degrees. Wraps around when over 360. ### Parameters #### Path Parameters - **color** (string) - Required - input color - **degrees** (number) - Required - degrees to adjust the input color, accepts degree integers (0 - 360) and wraps around on overflow ``` -------------------------------- ### Guard Numeric Values Source: https://color2k.com/ Clamp a value between a low and high boundary. ```javascript Math.min(Math.max(low, value), high) ``` -------------------------------- ### darken(color, amount) Source: https://color2k.com/ Darkens a color by subtracting from the lightness component. ```APIDOC ## darken(color, amount) ### Description Darkens using lightness. This is equivalent to subtracting the lightness from the L in HSL. ### Parameters #### Path Parameters - **color** (string) - Required - **amount** (number) - Required - The amount to darken, given as a decimal between 0 and 1 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.