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

@prexjs/accepts

v1.0.0

Published

Higher-level HTTP content negotiation for Node.js, handling media types, encodings, charsets, and languages.

Readme

@prexjs/accepts

Higher-level HTTP content negotiation for Node.js, handling media types, encodings, charsets, and languages.

npm version npm downloads License: MIT TypeScript

@prexjs/accepts provides high-level content negotiation utilities based on @prexjs/negotiator and @prexjs/mime-types. It enables HTTP servers to easily inspect incoming request headers (Accept, Accept-Encoding, Accept-Charset, Accept-Language) and select the best response representation for clients.

Features

  • Media Type Negotiation: Inspect Accept headers with automatic extension resolution (e.g. 'html', 'json').
  • Encoding Selection: Negotiate compression algorithms such as gzip, deflate, br, or identity.
  • Charset & Language Resolution: Prioritize character encodings and locales based on client quality factors (q values).
  • Flexible Argument Parsing: Accepts arguments as arrays or spread strings (types('json', 'html') or types(['json', 'html'])).
  • Dual Module Support: Full ESM (.mjs) and CommonJS (.cjs) builds with TypeScript types out of the box.

Installation

Install using your preferred package manager:

# npm
npm install @prexjs/accepts

# pnpm
pnpm add @prexjs/accepts

# Yarn
yarn add @prexjs/accepts

# Bun
bun add @prexjs/accepts

Quick start

import http from 'node:http';
import accepts from '@prexjs/accepts';

const server = http.createServer((req, res) => {
  const accept = accepts(req);

  // Negotiate media type
  switch (accept.type(['json', 'html', 'text'])) {
    case 'json':
      res.setHeader('Content-Type', 'application/json');
      res.end(JSON.stringify({ message: 'Hello, World!' }));
      break;
    case 'html':
      res.setHeader('Content-Type', 'text/html');
      res.end('<h1>Hello, World!</h1>');
      break;
    case 'text':
      res.setHeader('Content-Type', 'text/plain');
      res.end('Hello, World!');
      break;
    default:
      res.statusCode = 406;
      res.end('Not Acceptable');
      break;
  }
});

server.listen(3000);

API

accepts(req) / new Accepts(req)

Creates a new Accepts instance for the given request.

  • req: An object with HTTP headers (e.g., standard http.IncomingMessage).

accept.types(types?) (alias: accept.type(...))

  • Returns all accepted media types when called with no arguments.
  • Returns the best match when passed an array or list of candidate types/extensions.
  • Returns false if none of the candidates match.
// Given Accept: text/html, application/json;q=0.9
accept.types('html', 'json'); // => 'html'
accept.types(['json', 'image/png']); // => 'json'
accept.types(); // => ['text/html', 'application/json']

accept.encodings(encodings?) (alias: accept.encoding(...))

  • Returns all accepted encodings ordered by quality when called with no arguments.
  • Returns the best matching encoding or false.
// Given Accept-Encoding: gzip, deflate;q=0.8
accept.encodings('gzip', 'deflate', 'identity'); // => 'gzip'
accept.encodings(); // => ['gzip', 'deflate', 'identity']

accept.charsets(charsets?) (alias: accept.charset(...))

  • Returns accepted character sets ordered by quality preference.
  • Returns the best match from the provided options or false.
// Given Accept-Charset: utf-8, iso-8859-1;q=0.2
accept.charsets('utf-8', 'iso-8859-1'); // => 'utf-8'

accept.languages(languages?) (aliases: lang, langs, language)

  • Returns accepted languages ordered by client preference.
  • Returns the best matching language code or false.
// Given Accept-Language: en;q=0.8, es, pt
accept.languages('en', 'es', 'fr'); // => 'es'

Compatibility

  • Node.js >= 18.0.0
  • Supports both ESM and CommonJS
  • TypeScript 5.0+

Related Packages

License

MIT