UNPKG

1.6 kBTypeScriptView Raw
1// Type definitions for media-typer 1.1
2// Project: https://github.com/jshttp/media-typer
3// Definitions by: BendingBender <https://github.com/BendingBender>
4// Piotr Błażejewicz <https://github.com/peterblazejewicz>
5// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
6
7/**
8 * Simple RFC 6838 media type parser.
9 * This module will parse a given media type into its component parts, like type, subtype, and suffix.
10 * A formatter is also provided to put them back together and the two can be combined to normalize media types into a canonical form.
11 * 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
12 */
13
14/**
15 * Parse a media type string
16 * @throws TypeError If the given type string is invalid
17 */
18export function parse(mediaType: string): MediaType;
19/**
20 * Format an object into a media type string.
21 * This will return a string of the mime type for the given object
22 * @throws TypeError If any of the given object values are invalid
23 */
24export function format(mediaTypeDescriptor: MediaType): string;
25
26/**
27 * Validate a media type string
28 */
29export function test(mediaType: string): boolean;
30
31export interface MediaType {
32 /**
33 * The type of the media type (always lower case). Example: `image`
34 */
35 type: string;
36 /**
37 * The subtype of the media type (always lower case). Example: `svg`
38 */
39 subtype: string;
40 /**
41 * The suffix of the media type (always lower case). Example: `xml`
42 */
43 suffix?: string;
44}