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

content-types-lite

v1.9.0

Published

Tiny, type-safe HTTP media type constants and utilities for parsing, formatting, matching, and validation

Readme

content-types-lite

npm version CI license

Tiny, type-safe HTTP media type constants and utilities for TypeScript and JavaScript. It provides a curated set of common values—not a large file-extension database—and focused helpers for working with Content-Type headers.

  • Zero runtime dependencies
  • Literal TypeScript types derived from one source of truth
  • ESM and CommonJS builds
  • Root and tree-shakeable subpath exports
  • Safe parsing and formatting of header parameters
  • Wildcard and structured-suffix matching
  • IANA-registered values with clearly named legacy aliases

Install

npm install content-types-lite

Requires Node.js 18.17 or newer when used in Node. The ESM build also works in modern browsers and bundlers.

Quick start

import contentTypes, {
    JSON,
    formatContentType,
    isJsonLike,
    matchesMediaType,
    parseContentType,
} from 'content-types-lite';

JSON; // 'application/json'
contentTypes.PDF; // 'application/pdf'

formatContentType(JSON, { charset: 'utf-8' });
// 'application/json; charset=utf-8'

parseContentType('Application/Problem+JSON; charset="utf-8"');
// { type: 'application/problem+json', parameters: { charset: 'utf-8' } }

isJsonLike('application/problem+json'); // true
matchesMediaType('application/problem+json', 'application/*+json'); // true

CommonJS is supported:

const { JSON, withCharset } = require('content-types-lite');

withCharset(JSON); // 'application/json; charset=utf-8'

Constants and types

Named constants use literal types. The default export is a frozen object for compatibility with 1.x.

import contentTypes, { type ContentTypeName, type MediaType, JSON } from 'content-types-lite';

const name: ContentTypeName = 'JSON';
const value: MediaType = JSON;

contentTypes[name]; // inferred as 'application/json' | ...

ContentType remains as a deprecated alias of ContentTypeName for compatibility.

The collection includes common text, structured data, multipart, document, archive, image, audio, video, and font types. Browse the typed contentTypes object in your editor for the complete list.

Canonical and legacy values

Canonical constants follow the IANA Media Types registry:

| Constant | Value | | ---------- | ------------------------- | | YAML | application/yaml | | MSGPACK | application/vnd.msgpack | | PROTOBUF | application/protobuf |

Older values remain available when integrating with systems that require them:

| Constant | Value | | ----------------- | ------------------------ | | YAML_LEGACY | application/x-yaml | | MSGPACK_LEGACY | application/x-msgpack | | PROTOBUF_LEGACY | application/x-protobuf | | NDJSON | application/x-ndjson |

Formatting

import { formatContentType, normalizeContentType, withCharset } from 'content-types-lite/format';

withCharset('text/html');
// 'text/html; charset=utf-8'

formatContentType('text/plain', { title: 'hello world' });
// 'text/plain; title="hello world"'

normalizeContentType('Text/HTML; Charset="utf-8"');
// 'text/html; charset=utf-8'

Invalid names, media types, and control characters throw TypeError during formatting. This prevents malformed values and header injection.

Parsing

import { getMediaType, parseContentType } from 'content-types-lite/parse';

parseContentType('text/html; charset=utf-8');
// { type: 'text/html', parameters: { charset: 'utf-8' } }

getMediaType('Text/HTML; Charset=UTF-8');
// 'text/html'

parseContentType('invalid');
// null

Parsing is strict and side-effect free. Duplicate parameters and malformed quoted strings return null.

Matching and guards

import { isJsonLike, isTextual } from 'content-types-lite/guards';
import { matchesMediaType } from 'content-types-lite/match';

matchesMediaType('image/avif', 'image/*'); // true
matchesMediaType('application/problem+json', 'application/*+json'); // true
isJsonLike('application/vnd.api+json'); // true
isTextual('application/yaml'); // true

Available guards are isContentType, isJsonLike, isXmlLike, isTextual, isImage, isAudio, and isVideo.

Multipart form data

In browsers, do not manually set Content-Type: multipart/form-data when sending a FormData body. Let fetch or XMLHttpRequest generate the header so its required boundary matches the encoded body.

The constant is intended for parsing, matching, server-side generation where a boundary is supplied separately, and integrations that explicitly require the bare media type.

Package scope

This package intentionally does not infer a media type from a filename or inspect file contents. Use a comprehensive MIME database or file-signature detector for those jobs. content-types-lite focuses on common HTTP values and correct header handling.

Development

npm ci
npm run check
npm run attw

npm run check runs linting, formatting, static type checks, runtime tests, public type tests, builds, and package validation.

See CONTRIBUTING.md for contribution and media-type inclusion rules.

License

MIT © Mohammad Montasim-Al-Mamun Shuvo