Utilities
Alpha / Hex Utilities
Section titled “Alpha / Hex Utilities”addAlphaToHex
Section titled “addAlphaToHex”Add an alpha channel to a hex color.
addAlphaToHex(input: string, alpha: number): HEXimport { addAlphaToHex } from 'colorizr';
addAlphaToHex('#ff0044', 0.5); // '#ff004480'addAlphaToHex('#ff0044', 1); // '#ff0044'Playground
#ff004480
convertAlphaToHex
Section titled “convertAlphaToHex”Convert an alpha value (0-1) to its 2-character hex representation.
convertAlphaToHex(input: number): stringimport { convertAlphaToHex } from 'colorizr';
convertAlphaToHex(0.5); // '80'convertAlphaToHex(1); // 'ff'convertAlphaToHex(0); // '00'Playground
80
extractAlphaFromHex
Section titled “extractAlphaFromHex”Extract the alpha value from a hex color. Returns 1 if no alpha channel is present.
extractAlphaFromHex(input: string): numberimport { extractAlphaFromHex } from 'colorizr';
extractAlphaFromHex('#ff004480'); // 0.5extractAlphaFromHex('#ff0044'); // 1Playground
0.5
removeAlphaFromHex
Section titled “removeAlphaFromHex”Strip the alpha channel from a hex color.
removeAlphaFromHex(input: string): HEXimport { removeAlphaFromHex } from 'colorizr';
removeAlphaFromHex('#ff004480'); // '#ff0044'removeAlphaFromHex('#ff0044'); // '#ff0044'Playground
#ff0044
Scale Helpers
Section titled “Scale Helpers”getScaleStepKeys
Section titled “getScaleStepKeys”Get the step keys that will be generated for a given number of steps. Useful for understanding the output shape of scale().
getScaleStepKeys(steps: number): number[]import { getScaleStepKeys } from 'colorizr';
getScaleStepKeys(11); // [50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950]getScaleStepKeys(5); // [100, 300, 500, 700, 900]getScaleStepKeys(3); // [100, 500, 900]Playground
[ 100, 300, 500, 700, 900 ]