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

@danmat/accept-query

v0.1.2

Published

Parse, build, and content-negotiate the Accept-Query HTTP header (RFC 10008) for the QUERY method. Zero dependencies, fully typed.

Readme

@danmat/accept-query

CI npm version minified + gzip size License: MIT

Parse, build, and content-negotiate the Accept-Query HTTP header (RFC 10008) — the response header a server uses to advertise which query-format media types it accepts on a QUERY request.

Zero dependencies. Fully typed. Isomorphic (Node, Deno, Bun, browsers, edge).

import { negotiateQuery } from "@danmat/accept-query";

// The server told us what it accepts; we pick the best format we can produce.
const format = negotiateQuery(response.headers.get("accept-query") ?? "", [
  "application/json",
  "application/sql",
]);
// → "application/sql"

Why?

RFC 10008 introduces the QUERY method — a safe, idempotent request with a body. To tell clients how to shape that body, a server answers with an Accept-Query response header:

Accept-Query: application/sql;q=0.9, application/json;q=0.4, application/graphql

It's the Accept grammar (media ranges + q weights + parameters), but for query payloads. This library gives you the three things you actually need for it: parse it, negotiate against it, and build it (for servers).

Install

npm install @danmat/accept-query

API

parseAcceptQuery(value: string): MediaRange[]

Parses a header value into media ranges, sorted by quality then specificity. Parsing is lenient — malformed entries are skipped, quoted parameter values are respected, and types/subtypes/param keys are lowercased.

parseAcceptQuery("application/sql;q=0.8, application/json");
// [
//   { type: "application", subtype: "json", quality: 1,   params: {} },
//   { type: "application", subtype: "sql",  quality: 0.8, params: {} },
// ]

negotiateQuery(acceptQuery: string, offered: string[]): string | null

Given the server's Accept-Query value and the media types your client can produce (in your preference order), returns the best one to send — or null if the server accepts none of them. Wildcards (application/*, */*) and q=0 exclusions are handled per HTTP content-negotiation rules; the most specific matching range decides an offer's quality.

negotiateQuery("application/sql;q=0.9, application/json;q=0.4", [
  "application/json",
  "application/sql",
]);
// → "application/sql"   (higher server quality wins)

negotiateQuery("application/json", ["text/csv"]);
// → null                (server accepts none of ours)

formatAcceptQuery(ranges: MediaRangeInput[]): string

Builds a header value from strings and/or structured ranges — for servers advertising what they accept. Omits q when it's 1, trims trailing zeros, and quotes non-token parameter values.

formatAcceptQuery([
  "application/json",
  { type: "application", subtype: "sql", quality: 0.8 },
]);
// → "application/json, application/sql;q=0.8"

Types & errors

interface MediaRange {
  type: string; // lowercased, "*" for wildcard
  subtype: string; // lowercased, "*" for wildcard
  quality: number; // 0–1, defaults to 1
  params: Record<string, string>; // non-q params, lowercased keys
}

AcceptQueryError is thrown only for programmer misuse (e.g. formatAcceptQuery on a range missing its type/subtype). Parsing never throws — it's deliberately liberal in what it accepts.

The @danmat QUERY suite

▶️ See them work together: query-suite-example — a runnable demo using all four, with a 🌐 live playground.

License

MIT © Dan Matthew