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

http-accept-language-kit

v0.1.0

Published

Parse and format Accept-Language headers with structured diagnostics.

Readme

http-accept-language-kit

License: MPL-2.0 CI

Parse, inspect, format, and lightly match HTTP Accept-Language headers.

http-accept-language-kit is a clean-room TypeScript package for apps that need the raw header turned into predictable data. It has no runtime dependencies, no mutable global language registry, and no Node-only APIs.

Demo

Try the browser demo: packages.wasta-wocket.fr/http-accept-language-kit.

Package quality

  • TypeScript types are generated from the source.
  • ESM-only package with no runtime dependencies.
  • Marked as side-effect free for bundlers.
  • CI runs npm ci, typecheck, build, and test.
  • Tested on Node.js 20 and 22 with GitHub Actions.
  • Browser-friendly implementation with no Node-only APIs.

Install

npm install http-accept-language-kit

Quick Start

import { formatAcceptLanguage, parseAcceptLanguage, pickAcceptedLanguage } from "http-accept-language-kit";

const parsed = parseAcceptLanguage("fr-CA, fr;q=0.8, en-US;q=0.6");

if (parsed.ok) {
  console.log(parsed.languages[0]);
  // { range: "fr-CA", quality: 1, order: 0, raw: "fr-CA", subtags: ["fr", "CA"] }
}

const selected = pickAcceptedLanguage(parsed.input, ["en-US", "fr-FR"]);
// "fr-FR"

const normalized = formatAcceptLanguage(parsed.languages);
// "fr-CA, fr;q=0.8, en-US;q=0.6"

Why This Package

Use this when you want to inspect the header itself before deciding what to do:

  • stable diagnostics for malformed ranges, duplicate q values, and wildcard handling;
  • sorted structured results while preserving original order and raw tokens;
  • a tiny matcher for exact, base-language, and wildcard cases;
  • browser-friendly code that also works in workers, CLIs, and server middleware.

It is not a full locale negotiation framework and does not try to implement every language matching algorithm from ECMA-402 or BCP 47.

By default, q-values follow HTTP qvalue precision and allow at most three decimal places. Import tools that need to accept looser legacy input can opt into allowExtendedQualityPrecision.

API

parseAcceptLanguage(input, options?)

Returns { ok, input, languages, diagnostics }. Valid languages are sorted by quality by default.

const result = parseAcceptLanguage("da, en-GB;q=0.8, en;q=0.7");

formatAcceptLanguage(languages, options?)

Formats parsed language items back to a compact header value.

formatAcceptLanguage(result.languages, { precision: 2 });

pickAcceptedLanguage(header, supportedLanguages, options?)

Returns the first supported language matched by quality order. Matching is intentionally small: exact match, base language match, then wildcard.

pickAcceptedLanguage("fr-CA, en;q=0.8", ["en-US", "fr-FR"]);

Parse Options

| Option | Default | Description | | --- | --- | --- | | allowWildcard | true | Accept * ranges while still reporting a wildcard diagnostic. | | allowExtendedQualityPrecision | false | Accept q-values with more than three decimal places. | | clampQuality | false | Clamp out-of-range q values instead of rejecting them. | | keepInvalid | false | Include invalid items in languages for UI review flows. | | sort | true | Sort by descending q value and then original order. |

Format Options

| Option | Default | Description | | --- | --- | --- | | includeQualityOne | false | Emit ;q=1 for full-quality ranges. | | precision | 3 | Maximum decimal places for q values. |

Diagnostics

Diagnostics are stable strings intended for logs, UI hints, and tests:

  • invalid-input
  • empty-header
  • empty-item
  • invalid-language-range
  • invalid-parameter
  • invalid-quality
  • quality-precision-exceeded
  • duplicate-quality
  • quality-clamped
  • wildcard-range

License

MPL-2.0