Skip to main content
@spa-tools/utilities

shade

The shade function adds black to a color.

Usage

import { shade } from '@spa-tools/utilities';

const redShadedExponentially = shade('#FF0000', 0.5);
console.log(redShadedExponentially.toHex());
// --> #b40000
const redShadedLinearly = shade('#FF0000', 0.5, true);
console.log(redShadedLinearly.toHex());
// --> #800000

Arguments

NameTypeRequired?DefaultDescription
rgbOrRgbaOrHexstringyes-RGB(A) or hex color string
rationumberyes-Interpolation ratio between 0 and 1
linearbooleannofalseIf true uses a linear interpolation algorithm; otherwise, exponential interpolation will be used

Returns

ColorObject object.