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 🙏

© 2026 – Pkg Stats / Ryan Hefner

okhsl

v0.2.0

Published

Dependency-free OkHSL and sRGB conversion with hex, CSS, integer, byte and HSL helpers

Downloads

26,404

Readme

okhsl

A small, dependency-free TypeScript library for converting OkHSL colors to standard sRGB and back.

OkHSL is a perceptual color-picker space built on Oklab. Unlike ordinary HSL, equal lightness and saturation changes are designed to feel substantially more uniform across hues.

Install

bun add okhsl

The published package ships browser-compatible ESM and TypeScript declarations. It has no runtime dependencies.

Usage

import okhsl from 'okhsl'

okhsl(346, 86, 67) // 'f26bbc'
okhsl(213, 92, 67, 56) // '1db6d08f'

okhsl.css(115, 100, 89, 100) // '#de0'
okhsl.integer(346, 86, 67) // 0xf26bbc
okhsl.integer(346, 86, 67, 50) // 0xf26bbc80
okhsl.hsl(309, 76, 80) // [272, 75, 84]
okhsl.bytes(66, 93, 67, 120) // [226, 141, 28, 120]

okhsl.fromRgb(29, 182, 208, 56) // [213, 92, 67, 56]
okhsl.fromHsl(272, 75, 84, 42) // [309, 76, 80, 42]
okhsl.fromHex('#de0') // [115, 100, 89]

All methods are also named exports:

import {bytes, css, fromHex, fromHsl, fromRgb, hsl, integer, okhsl} from 'okhsl'

Input forms

The channel-based methods accept positional channels, a readonly tuple or an object. For OkHSL and standard HSL inputs, omitted or undefined channels default independently to hue 0, saturation 100 and lightness 50. RGB input requires all three channels.

okhsl() // 'd70071' (OkHSL 0, 100, 50)
okhsl(213) // '00869a'
okhsl([undefined, 0] as const) // '777777'
okhsl({l: 0}) // '000000'
okhsl.fromHsl() // [29, 100, 57] (standard HSL 0, 100, 50 is sRGB red)

okhsl.fromRgb([242, 107, 188] as const)
okhsl.fromRgb({r: 242, g: 107, b: 188})

Pass alpha separately from a tuple or object. Four-channel input tuples throw RangeError so a byte alpha cannot be mistaken for a percentage:

okhsl([213, 92, 67], 56)
okhsl.bytes({h: 66, s: 93, l: 67}, 120)
okhsl.integer({}, 50) // 0xd7007180

API

| Function | Input | Output | Alpha | | --- | --- | --- | --- | | okhsl(h?, s?, l?, alpha?) | OkHSL | lowercase 6/8-digit sRGB hex without # | percentage 0–100, converted to a byte | | okhsl.css(h?, s?, l?, alpha?) | OkHSL | shortest exact CSS hex | percentage 0–100, converted to a byte | | okhsl.integer(h?, s?, l?, alpha?) | OkHSL | unsigned number in 0xRRGGBB or 0xRRGGBBAA order | percentage 0–100, converted to a byte | | okhsl.bytes(h?, s?, l?, alphaByte?) | OkHSL | integer sRGB byte tuple | byte 0–255, rounded | | okhsl.hsl(h?, s?, l?, alpha?) | OkHSL | rounded standard sRGB HSL tuple | percentage 0–100, preserved | | okhsl.fromRgb(r, g, b, alpha?) | sRGB bytes | rounded OkHSL tuple | percentage 0–100, preserved | | okhsl.fromHsl(h?, s?, l?, alpha?) | standard sRGB HSL | rounded OkHSL tuple | percentage 0–100, preserved | | okhsl.fromHex(hex) | CSS-style 3/4/6/8-digit hex | rounded OkHSL tuple | hex byte converted to a rounded percentage |

Hue inputs wrap into [0, 360). Finite saturation, lightness, RGB and alpha inputs are clamped to their documented ranges. After defaults are applied, nonfinite or nonnumeric channels throw RangeError. Invalid hex input throws TypeError.

Inverse color channels are rounded integers. Percentage alpha supplied directly to tuple-returning methods is preserved without rounding. fromHex() necessarily converts its 8-bit alpha channel to the nearest integer percentage.

Hex and integer output preserve an explicitly supplied opaque alpha:

okhsl(213, 92, 67, 100) // '1db6d0ff'

CSS output instead removes redundant opaque alpha, then uses #rgb or #rgba shorthand only when every byte is exactly representable by one hexadecimal digit.

Numerical behavior

Exact sRGB grays use hue 0 and saturation 0. HSL conversion uses unrounded sRGB channels. Hex, integer and byte output clip to the displayable sRGB range before rounding. Conversion through integer OkHSL is lossy: RGB → rounded OkHSL → RGB need not reproduce the original bytes.

Development

bun install --frozen-lockfile
bun run validate

validate runs ESLint, TypeScript, the Bun tests and the production build. bun run build uses Bundil to create the npm package in dist/okhsl/production/, with lib.js and lib.d.ts as its public entry points.

Attribution

The numerical core is adapted from Björn Ottosson’s OkHSL reference implementation via Brian Holbrook’s TypeScript port. Both copyright notices are included in license.txt.

License

MIT. See license.txt.