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

@readium/helpers

v1.0.0

Published

General-purpose browser helpers for Readium packages

Readme

@readium/helpers

General-purpose browser helpers for Readium packages: color parsing/contrast utilities and OS/browser detection.

Installation

import { colorToRgba, checkContrast, isDarkColor, isLightColor, getContrastingTextColor, adjustColorForContrast, getLuminance, sML, sMLWithRequest } from "@readium/helpers";

Color utilities

// Parse any CSS color value (including custom properties resolved by the browser) to RGBA
colorToRgba("rebeccapurple"): { r: number; g: number; b: number; a: number }

// Relative luminance per WCAG 2.2
getLuminance({ r: 255, g: 255, b: 255 }): number

// WCAG 2.2 contrast ratio between two colors (string or RGBA)
checkContrast("#000", "#fff"): number

// Whether a color reads as dark/light against an optional background it's blended with
isDarkColor("#333", "#fff"): boolean
isLightColor("#333", "#fff"): boolean

// "black" or "white", whichever contrasts best against the given color
getContrastingTextColor("#333"): "black" | "white"

// Lightens/darkens baseColor against backgroundColor until targetContrast (default 3) is met
adjustColorForContrast("#888", "#fff", 3): string

colorToRgba uses an offscreen canvas to resolve any value the browser's CSS engine understands (named colors, hsl(), oklch(), etc.) and caches results. Unparseable or special values (transparent, currentColor, gradients, CSS variables) log a warning and fall back to opaque white.

OS / browser detection

sML.OS   // { iOS, macOS, iPadOS, Windows, Android, ChromeOS, Linux, ... } — each a version array, e.g. [17, 4]
sML.UA   // { Chrome, Safari, Firefox, Edge, WebKit, Blink, ... } — each a version array
sML.Env  // string[] of all detected OS/UA flag names

sMLWithRequest.iOSRequest // "mobile" | "desktop" | undefined — iPadOS "Request Desktop Site" state

sML is a bundled subset of sML.js by Satoru Matsushima, MIT licensed. Falls back safely when navigator is unavailable (SSR).

Third-party licenses

This package is BSD-3-Clause, except for src/sML.ts, which vendors code from sML.js, Copyright (c) Satoru Matsushima, licensed under the MIT license (see the header of that file for the full notice).