JavaScript implementation of HSLuv (revision 4)
TypeScript
36
21 commits
updated Jun 16, 2026
Install from NPM package repository:
npm install hsluv
ES modules:
import {Hsluv} from "hsluv";
CommonJS:
const {Hsluv} = require("hsluv");
HTML include:
<script src="hsluv-x.x.x.min.js"></script> to your HTMLwindow.HsluvThe API is designed to avoid heap allocation. The HSLuv class defines the following public fields:
hex:String, rgb_r:Float [0;1], rgb_g:Float [0;1], rgb_r:Float [0;1]xyz_x:Float, xyz_y:Float, xyz_z:Floatluv_l:Float, luv_u:Float, luv_v:Floatlch_l:Float, lch_c:Float, lch_h:Floathsluv_h:Float [0;360], hsluv_s:Float [0;100], hsluv_l:Float [0;100]hpluv_h:Float [0;360], hpluv_p:Float [0;100], hpluv_l:Float [0;100]To convert between color spaces, simply set the properties of the source color space, run the conversion methods, then read the properties of the target color space.
Use the following methods to convert to and from RGB:
hsluvToRgb(), hsluvToHex(), rgbToHsluv(), hexToHsluv()hpluvToRgb(), hpluvToHex(), rgbToHpluv(), hexToHpluv()Use the following methods to do step-by-step conversion:
hsluvToLch() (or hpluvToLch()), lchToLuv(), luvToXyz(), xyzToRgb(), rgbToHex()hexToRgb(), rgbToXyz(), xyzToLuv(), luvToLch(), lchToHsluv() (or lchToHpluv())For advanced usage, we also export the bounding lines in slope-intercept format, two for each RGB channel representing the limit of the gamut.
r0s, r0ir1s, r1ig0s, g0ig1s, g1ib0s, b0ib1s, b1iExample:
var conv = new Hsluv();
conv.hsluv_h = 10;
conv.hsluv_s = 75;
conv.hsluv_l = 65;
conv.hsluvToHex();
console.log(conv.hex); // Will print "#ec7d82"
Also available for Stylus. See here.
Our Node.js CI workflow
will build and test every push and PR to the main branch.
To publish a release, configure npm trusted publishing for the hsluv/hsluv-javascript repository and
npm-publish.yml workflow, then create a GitHub Release. The release tag must match the version in
package.json. The Publish to npm workflow
will build the package and publish it to npm with provenance. Prerelease versions (for example 1.2.3-rc.1)
are automatically published with the matching npm dist-tag.
Overall
Maintained
Code review
npm
Latest release
Releases this year
JavaScript implementation of HSLuv (revision 4)
TypeScript
36
21 commits
updated Jun 16, 2026
Install from NPM package repository:
npm install hsluv
ES modules:
import {Hsluv} from "hsluv";
CommonJS:
const {Hsluv} = require("hsluv");
HTML include:
<script src="hsluv-x.x.x.min.js"></script> to your HTMLwindow.HsluvThe API is designed to avoid heap allocation. The HSLuv class defines the following public fields:
hex:String, rgb_r:Float [0;1], rgb_g:Float [0;1], rgb_r:Float [0;1]xyz_x:Float, xyz_y:Float, xyz_z:Floatluv_l:Float, luv_u:Float, luv_v:Floatlch_l:Float, lch_c:Float, lch_h:Floathsluv_h:Float [0;360], hsluv_s:Float [0;100], hsluv_l:Float [0;100]hpluv_h:Float [0;360], hpluv_p:Float [0;100], hpluv_l:Float [0;100]To convert between color spaces, simply set the properties of the source color space, run the conversion methods, then read the properties of the target color space.
Use the following methods to convert to and from RGB:
hsluvToRgb(), hsluvToHex(), rgbToHsluv(), hexToHsluv()hpluvToRgb(), hpluvToHex(), rgbToHpluv(), hexToHpluv()Use the following methods to do step-by-step conversion:
hsluvToLch() (or hpluvToLch()), lchToLuv(), luvToXyz(), xyzToRgb(), rgbToHex()hexToRgb(), rgbToXyz(), xyzToLuv(), luvToLch(), lchToHsluv() (or lchToHpluv())For advanced usage, we also export the bounding lines in slope-intercept format, two for each RGB channel representing the limit of the gamut.
r0s, r0ir1s, r1ig0s, g0ig1s, g1ib0s, b0ib1s, b1iExample:
var conv = new Hsluv();
conv.hsluv_h = 10;
conv.hsluv_s = 75;
conv.hsluv_l = 65;
conv.hsluvToHex();
console.log(conv.hex); // Will print "#ec7d82"
Also available for Stylus. See here.
Our Node.js CI workflow
will build and test every push and PR to the main branch.
To publish a release, configure npm trusted publishing for the hsluv/hsluv-javascript repository and
npm-publish.yml workflow, then create a GitHub Release. The release tag must match the version in
package.json. The Publish to npm workflow
will build the package and publish it to npm with provenance. Prerelease versions (for example 1.2.3-rc.1)
are automatically published with the matching npm dist-tag.
Overall
Maintained
Code review
npm
Latest release
Releases this year