Skip to content

lwe8/iana-media-types

Repository files navigation

iana-media-types

TypeScript and JavaScript access to the IANA media types registry.

This package ships generated data from the IANA media types registry and exposes lookup functions for resolving either a media subtype key or an exact full media type.

Install

npm install iana-media-types

Usage

import { searchMediaType, searchFullMediaType } from "iana-media-types";

const bySubtype = searchMediaType("json");
const exact = searchFullMediaType("application/json");

console.log(bySubtype);
console.log(exact);
// {
//   topLevelMediaType: "application",
//   mediaType: "application/json",
//   lastUpdated: "2026-05-20"
// }

If the key is not found, the function returns undefined.

import { searchMediaType } from "iana-media-types";

const result = searchMediaType("not-a-real-subtype");

console.log(result);
// undefined

API

function searchMediaType(key: MimeKey):
  | {
      topLevelMediaType: string;
      mediaType: string;
      lastUpdated: string;
    }
  | undefined;

function searchFullMediaType(mediaType: string):
  | {
      topLevelMediaType: string;
      mediaType: string;
      lastUpdated: string;
    }
  | undefined;

key

  • A media subtype key from the generated MimeKey union.
  • The lookup uses the subtype only, not the full type/subtype string.

mediaType

  • A full media type string such as application/json.
  • This lookup is exact and avoids subtype collisions across top-level media types.

Return value

  • topLevelMediaType: the IANA top-level type that matched, such as application or image.
  • mediaType: the full media type string.
  • lastUpdated: the registry date embedded from the generated IANA source.
  • undefined: returned when no subtype matches.

Exact Lookup

Use searchFullMediaType() when you want unambiguous lookup by the full type/subtype string.

import { searchFullMediaType } from "iana-media-types";

const result = searchFullMediaType("text/javascript");

console.log(result);
// {
//   topLevelMediaType: "text",
//   mediaType: "text/javascript",
//   lastUpdated: "2026-05-20"
// }

If the input is malformed or the exact media type is not present in the generated IANA data, the function returns undefined.

Important Behavior

This package currently searches by subtype only.

That means:

  • You pass json, not application/json.
  • Some subtype names can exist under more than one top-level media type.
  • When duplicates exist, the function returns the first match encountered in the generated top-level order: application, audio, example, font, haptics, image, message, model, multipart, text, video.

If you need unambiguous lookup by full media type, use searchFullMediaType() instead.

Data Source

The generated registry data comes from the IANA media types registry:

  • https://www.iana.org/assignments/media-types/media-types.txt

The registry metadata currently reports:

  • Last updated: 2026-05-20
  • Included top-level media types: application, audio, example, font, haptics, image, message, model, multipart, text, video

The repository script that refreshes the generated files is mime.js.

License

The code in this repository is licensed under Apache-2.0. See LICENSE.

The upstream IANA protocol registry data is separate from this repository's code license. IANA publishes licensing terms for protocol registries stating that the protocol registries may be freely used and that any applicable rights IANA and the IETF may have in those registries are subject to the Creative Commons CC0 1.0 dedication:

  • https://www.iana.org/help/licensing-terms

This package repackages factual registry data from IANA. It does not claim ownership of the IANA registry content, and users should review IANA's licensing page for the original terms and disclaimers.

About

No description, website, or topics provided.

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors