npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

hsluv

v1.0.1

Published

Human-friendly HSL

Downloads

1,081,777

Readme

HSLuv - Human-friendly HSL

CI npm

Installation

Install from NPM package repository:

npm install hsluv

ES modules:

import {Hsluv} from "hsluv";

CommonJS:

const {Hsluv} = require("hsluv");

HTML include:

  • Download the latest hsluv.min.js
  • Add <script src="hsluv-x.x.x.min.js"></script> to your HTML
  • Access it via the global window.Hsluv

Usage

The API is designed to avoid heap allocation. The HSLuv class defines the following public fields:

  • RGB: hex:String, rgb_r:Float [0;1], rgb_g:Float [0;1], rgb_r:Float [0;1]
  • CIE XYZ: xyz_x:Float, xyz_y:Float, xyz_z:Float
  • CIE LUV: luv_l:Float, luv_u:Float, luv_v:Float
  • CIE LUV LCh: lch_l:Float, lch_c:Float, lch_h:Float
  • HSLuv: hsluv_h:Float [0;360], hsluv_s:Float [0;100], hsluv_l:Float [0;100]
  • HPLuv: 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:

  • HSLuv: hsluvToRgb(), hsluvToHex(), rgbToHsluv(), hexToHsluv()
  • HPLuv: hpluvToRgb(), hpluvToHex(), rgbToHpluv(), hexToHpluv()

Use the following methods to do step-by-step conversion:

  • Forward: hsluvToLch() (or hpluvToLch()), lchToLuv(), luvToXyz(), xyzToRgb(), rgbToHex()
  • Backward: 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.

  • R < 0: r0s, r0i
  • R > 1: r1s, r1i
  • G < 0: g0s, g0i
  • G > 1: g1s, g1i
  • B < 0: b0s, b0i
  • B > 1: b1s, b1i

Example:

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.

Development

Our GitHub Actions workflow will build and test every push and PR to the main branch. When a main branch receives a commit that updates the project version in package.json, the workflow will tag the commit, create a draft release on GitHub and publish the npm package. Mark your versions with the -rc suffix to create pre-releases.

Changelog

1.0.1

  • Fix TypeScript d.ts resolution for certain configurations.

1.0.0

  • New API to avoid heap allocation.
  • Transpiled from hsluv-haxe and converted manually to TypeScript.
  • New GitHub Actions CI for build, test and publishing automation.

0.1.0

  • Provide Typescript definitions in the NPM package.

0.0.3

  • Expose intermediate functions in the public API.

0.0.2

  • Improve packaging and minification.

0.0.1

  • Initial release under the name HSLuv. Old releases can be found here.