mrkeyoor.com_
Sat 08 Aug 21:02 UTC
npmUtilsupdated 08 Aug 2026

hsl-to-rgb-for-reals

hsl-to-rgb-for-reals is a single CommonJS function that converts an HSL color into three rounded RGB byte values. Give it hue in degrees from 0 up to but not including 360, plus saturation and lightness as fractions from 0 to 1, and it returns an array such as `[93, 121, 192]`. It has no dependencies, parser, alpha-channel support, formatting helpers, types, or input validation.

Verdict

A frozen but understandable converter for code that already supplies clean numeric HSL values. New projects should usually choose color-convert or write this small formula locally with explicit validation and types.

API stability5/5The API is one positional function and the published README, converter.js, and tests all agree on its contract: degrees for hue, fractional saturation and lightness, and a rounded RGB array. Version 1.1.1 has not changed since 2019, so consumers are very unlikely to face API churn, though the lack of change also means known rough edges remain.
Docs2/5The README gives the required ranges, installation command, one accurate example, and an unusually useful warning not to use version 1.0.0 because it forgot the export. It does not explain behavior for invalid values, hue wrapping, rounding, CSS percentage conversion, Unicode or string inputs, module interoperability, browser support, alpha, or the undefined-hue special case visible in source.
Maintenance1/5npm shows 1.1.1 as the latest release from September 2019, and GitHub reports the last repository push at the same time. The repository is not formally archived, but there is no recent release or code activity and open reports remain, so users should not plan around future validation, types, ESM packaging, or bug fixes.
Ecosystem2/5The package recorded 4,822,711 downloads in the measured week and has zero runtime dependencies, largely because it appears transitively in established trees. Its direct ecosystem is otherwise minimal: no plugins, declarations, adapters, documentation site, multi-space API, or companion modules, and the repository has no GitHub stars despite the high install count.

Use it if

  • You already have numeric HSL components and only need an RGB byte tuple
  • You maintain CommonJS code and want a dependency-free converter with a tiny public surface
  • You can validate and normalize hue, saturation, and lightness before calling it
  • You are preserving an existing dependency and its exact rounded output
Skip it if

Setup reality

npm install hsl-to-rgb-for-reals is the whole installation. There are no dependencies, peer dependencies, native extensions, credentials, configuration files, or build-time generation. CommonJS code gets the converter with require('hsl-to-rgb-for-reals'). Modern bundlers normally interoperate with that export, but the package has no ESM entry point, export map, or bundled TypeScript declaration, so strict projects may need a local declaration for `(hue: number, saturation: number, lightness: number) => [number, number, number]`. The bigger first-run surprise is the input convention. Hue is degrees in the half-open range 0 through less than 360, while saturation and lightness are fractions, not the percentage numbers shown in CSS. The README example therefore passes 0.44 for 44 percent. The function does no parsing, clamping, wrapping, or validation. Exactly 360 is not treated like 0, out-of-range values can yield nonsensical channels, and an undefined hue is silently special-cased to black even though other missing arguments are not handled safely. It returns a mutable three-element array of rounded bytes and has no alpha channel or formatter. If inputs come from users, CSS, or another color library, normalize and validate them in a wrapper before conversion. With no release or push since 2019, assume these module-format and validation gaps will remain.

Patterns

Convert fractional HSL to RGBconvert-hsl

const hslToRgb = require('hsl-to-rgb-for-reals');

const rgb = hslToRgb(223, 0.44, 0.56);
console.log(rgb); // [93, 121, 192]

Saturation and lightness are fractions from 0 to 1, not CSS percentage numbers.

Convert HSL components read as percentagesconvert-css-components

const hslToRgb = require('hsl-to-rgb-for-reals');

function fromPercentages(hue, saturationPct, lightnessPct) {
  return hslToRgb(hue, saturationPct / 100, lightnessPct / 100);
}

console.log(fromPercentages(223, 44, 56));

This converts numeric components only; it does not parse an `hsl(...)` CSS string.

Format the result as a CSS rgb() valueformat-rgb-css

const hslToRgb = require('hsl-to-rgb-for-reals');

const [r, g, b] = hslToRgb(223, 0.44, 0.56);
const css = `rgb(${r} ${g} ${b})`;
console.log(css);

The package returns an array and does not supply CSS formatting or alpha support.

Format converted channels as hexadecimalformat-hex

const hslToRgb = require('hsl-to-rgb-for-reals');

function toHex(h, s, l) {
  return '#' + hslToRgb(h, s, l)
    .map((channel) => channel.toString(16).padStart(2, '0'))
    .join('');
}

console.log(toHex(223, 0.44, 0.56)); // #5d79c0

Validate inputs first; out-of-range channels do not reliably produce two-digit hex.

Wrap arbitrary hue into the supported rangewrap-hue

const hslToRgb = require('hsl-to-rgb-for-reals');

function wrapHue(degrees) {
  return ((degrees % 360) + 360) % 360;
}

const rgb = hslToRgb(wrapHue(420), 0.8, 0.5);

Hue 360 is outside the documented half-open range and produces NaN without wrapping.

Reject invalid components before conversionvalidate-inputs

const hslToRgb = require('hsl-to-rgb-for-reals');

function convertChecked(h, s, l) {
  if (![h, s, l].every(Number.isFinite)) throw new TypeError('HSL must be finite numbers');
  if (h < 0 || h >= 360 || s < 0 || s > 1 || l < 0 || l > 1) {
    throw new RangeError('HSL component out of range');
  }
  return hslToRgb(h, s, l);
}

The package itself does not validate or clamp, apart from returning black when hue is undefined.

Convert an achromatic HSL colorconvert-grayscale

const hslToRgb = require('hsl-to-rgb-for-reals');

const middleGray = hslToRgb(0, 0, 0.5);
console.log(middleGray); // [128, 128, 128]

When saturation is zero, hue has no visual effect, but it must still be within the implemented range.

Convert a palette of HSL tuplesconvert-palette

const hslToRgb = require('hsl-to-rgb-for-reals');

const hslPalette = [[0, 0.8, 0.5], [120, 0.8, 0.5], [240, 0.8, 0.5]];
const rgbPalette = hslPalette.map(([h, s, l]) => hslToRgb(h, s, l));
console.log(rgbPalette);

Each call allocates a new mutable array; copy or freeze results if callers share them.

Add alpha when formatting CSSadd-alpha-css

const hslToRgb = require('hsl-to-rgb-for-reals');

function toRgbCss(h, s, l, alpha = 1) {
  if (alpha < 0 || alpha > 1) throw new RangeError('alpha');
  const [r, g, b] = hslToRgb(h, s, l);
  return `rgb(${r} ${g} ${b} / ${alpha})`;
}

console.log(toRgbCss(223, 0.44, 0.56, 0.6));

Alpha is formatting added by your wrapper; the converter has no alpha-channel API.

Alternatives

PackageRegistryPick it when
color-convertnpmYou need maintained conversions among many color spaces with rounded and raw variants
tinycolor2npmYou need color-string parsing, alpha, manipulation, and output formatting
chroma-jsnpmYou need color scales, interpolation, contrast work, or perceptual color spaces
hsl-to-rgbnpmYou must match the older package this fork copied, after checking its export behavior in your toolchain