Skip to main content

getColorNameFromHsl()

function getColorNameFromHsl(options): GetColorNameFromHexOutput

Retrieves the color name from a given HSL color.

Parameters

ParameterTypeDescription
optionsobjectThe options for converting HSL to color name.
options.hnumberThe hue component of the HSL color (0-360).
options.lnumberThe lightness component of the HSL color (0-100).
options.snumberThe saturation component of the HSL color (0-100).

Returns

GetColorNameFromHexOutput

An object containing information about the color:

  • hexcode: The input hex code, normalized to lowercase with '#' prefix.
  • colorName: The name of the closest matching color.
  • isExactMatch: Boolean indicating if an exact match was found.
  • shadeHex: The hex code of the closest matching color.
  • shadeName: The name of the closest matching color (same as colorName).
  • distance: The color distance between the input and the closest match (0 for exact matches).

Throws

If unable to find a closest color match.

Example

const result = getColorNameFromHsl({ h: 0, s: 100, l: 50 });
// Returns: { hexcode: '#ff0000', colorName: 'Red', isExactMatch: true, shadeHex: '#ff0000', shadeName: 'Red', distance: 0 }

Defined in

colorname/colorname.ts:98