UNPKG

1.31 kBTypeScriptView Raw
1/**
2 * Simple RFC 6838 media type parser.
3 * This module will parse a given media type into its component parts, like type, subtype, and suffix.
4 * A formatter is also provided to put them back together and the two can be combined to normalize media types into a canonical form.
5 * If you are looking to parse the string that represents a media type and its parameters in HTTP (for example, the Content-Type header), use the content-type module
6 */
7
8/**
9 * Parse a media type string
10 * @throws TypeError If the given type string is invalid
11 */
12export function parse(mediaType: string): MediaType;
13/**
14 * Format an object into a media type string.
15 * This will return a string of the mime type for the given object
16 * @throws TypeError If any of the given object values are invalid
17 */
18export function format(mediaTypeDescriptor: MediaType): string;
19
20/**
21 * Validate a media type string
22 */
23export function test(mediaType: string): boolean;
24
25export interface MediaType {
26 /**
27 * The type of the media type (always lower case). Example: `image`
28 */
29 type: string;
30 /**
31 * The subtype of the media type (always lower case). Example: `svg`
32 */
33 subtype: string;
34 /**
35 * The suffix of the media type (always lower case). Example: `xml`
36 */
37 suffix?: string | undefined;
38}