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

@stealthscale/provider-locale

v0.1.0

Published

Decides which locale a page is read in, remembers the choice, and writes the direction that follows.

Readme

@stealthscale/provider-locale

@stealthscale/provider-locale decides which locale a page is read in, remembers the choice, and writes the direction that follows onto the document.

Install

pnpm add @stealthscale/provider-locale

The package peers on @stealthscale/provider-environment, @stealthscale/provider-i18n, @stealthscale/settings and react.

Usage

import { I18nProvider, LocaleProvider } from "@stealthscale/provider-locale";
import { catalogues } from "virtual:i18n";

<LocaleProvider app="orders" locales={["en-US", "nl", "ar-EG"]}>
  <I18nProvider catalogues={catalogues}>
    <App />
  </I18nProvider>
</LocaleProvider>;

locales lists what the application offers, the first being its fallback. The locale in force is what a person chose. Where they chose nothing, it is the best match for what their browser asks for, and where nothing matches, the first in the list. The choice is remembered under app, so two applications on one origin keep their own.

This package's own I18nProvider mounts the one from @stealthscale/provider-i18n in whichever locale is in force, so changing the locale changes every string below. Leave catalogues out and it mounts catalogues holding nothing, so every key resolves to itself.

Reading it

const { direction, locale, locales, setLocale } = useLocale();

setLocale ignores a tag the application does not offer. direction follows from the locale's script: rtl for Arabic, Hebrew, Persian, Urdu and Divehi, ltr for everything else, including ar-Latn.

lang and dir go onto the document root, because the stylesheet's logical properties, a screen reader's voice and the browser's own controls all read them there. Inside an iframe or a shadow root they go onto whichever document @stealthscale/provider-environment names.

A component that positions itself by direction reads useLocale().direction and passes dir to its machine.

Letting something else drive

Pass locale and onLocaleChange and the provider uses the locale it is given, remembering nothing itself. A router that carries the locale in the URL drives it this way, and isPending reports to a switcher that a transition is under way.

<LocaleProvider
  app="orders"
  isPending={isPending}
  locale={params.locale}
  locales={LOCALES}
  onLocaleChange={(next) => startTransition(() => navigate(next))}
/>

Matching on the server

preferences reads an Accept-Language header into the tags a client will accept, dropping the wildcard and anything at q=0. negotiate matches those against what an application offers.

const locale = negotiate(
  preferences(request.headers.get("accept-language")).map((one) => one.tag),
  LOCALES,
  LOCALES[0],
);

Matching is ECMA-402's lookup: each requested tag is truncated in turn, so nl-BE matches nl. Where truncation finds nothing, both sides widen to their likely script and region, so zh-HK matches zh-Hant and en-GB matches en-US.

Reading a tag

canonical, parts, widened, chain, widenedChain and directionOf read a BCP 47 tag through the engine's own Intl. Each returns undefined, or an empty array, for a string that is not a tag.