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/content-type

v1.0.0

Published

Create and parse HTTP Content-Type headers and media types according to RFC 9110.

Readme

@prexjs/content-type

Create and parse HTTP Content-Type headers and media types according to RFC 9110.

npm version npm downloads License: MIT TypeScript

@prexjs/content-type is a high-performance utility for parsing and formatting HTTP Content-Type headers and MIME types according to RFC 9110 standards.

Features

  • Parse Content-Type header strings into type and parameter objects.
  • Format structured objects into valid Content-Type header strings with proper quote escaping.
  • Validate media types and token characters per RFC 9110.
  • Fast ASCII character bitmask lookup for high throughput.
  • Zero runtime dependencies.
  • Dual ES Module (.mjs) and CommonJS (.cjs) support with TypeScript definitions.

Installation

Install using your preferred package manager:

# npm
npm install @prexjs/content-type

# pnpm
pnpm add @prexjs/content-type

# Yarn
yarn add @prexjs/content-type

# Bun
bun add @prexjs/content-type

Quick start

import contentType from '@prexjs/content-type';

// Parse a Content-Type header
const parsed = contentType.parse('text/html; charset=utf-8');
console.log(parsed.type); // 'text/html'
console.log(parsed.parameters); // { charset: 'utf-8' }

// Format an object to a header string
const header = contentType.format({
  type: 'application/json',
  parameters: { charset: 'utf-8' },
});
console.log(header); // 'application/json; charset=utf-8'

Both default and named exports are supported:

import contentType, {
  parse,
  format,
  isTypeValid,
  isTokenValid,
  type ContentType,
  type ParsedContentType,
  type Parameters,
  type ParseOptions,
} from '@prexjs/content-type';

Examples

Parsing headers with parameters

import { parse } from '@prexjs/content-type';

const obj = parse('multipart/form-data; boundary="something_special"');
console.log(obj.type); // 'multipart/form-data'
console.log(obj.parameters.boundary); // 'something_special'

Formatting headers

import { format } from '@prexjs/content-type';

const header = format({
  type: 'image/svg+xml',
  parameters: {
    charset: 'utf-8',
  },
});
// 'image/svg+xml; charset=utf-8'

Type and token validation

import { isTypeValid, isTokenValid } from '@prexjs/content-type';

console.log(isTypeValid('application/json')); // true
console.log(isTypeValid('invalid type')); // false

console.log(isTokenValid('charset')); // true
console.log(isTokenValid('token with spaces')); // false

Compatibility

@prexjs/content-type is designed for JavaScript and TypeScript projects. It is distributed with ES Modules (.mjs), CommonJS (.cjs), and TypeScript declarations. It runs in any modern JavaScript runtime (Node.js, Deno, Bun, browser) without external dependencies.

License

This project is licensed under the MIT License. See LICENSE for the full license text.

Related projects

  • prex.js — prex.js monorepo and ecosystem.