Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

MediaType

import { MediaType } from "https://raw.githubusercontent.com/i-xi-dev/mimetype.es/1.2.22/mod.ts";

The object representation of MIME type. The MediaType instances are immutable.

class MediaType {
private constructor(
typeName: string,
subtypeName: string,
parameters?: Array<MediaType.Parameter>,
original?,
);
get type(): string;
get subtype(): string;
get suffix(): string;
get essence(): string;
get originalString(): string;
 
equals(other: MediaType, options?: MediaType.CompareOptions): boolean;
getParameterValue(parameterName: string): string | null;
hasParameter(parameterName: string): boolean;
parameterNames(): IterableIterator<string>;
parameters(): IterableIterator<MediaType.Parameter>;
toJSON(): string;
toString(): string;
withoutParameters(): MediaType;
withParameters(parameters: Array<MediaType.Parameter>): MediaType;
 
static fromHeaders(headers: Headers): MediaType;
static fromString(text: string): MediaType;
}

§Type Aliases

MediaType.CompareOptions

The MediaType equivalent comparison option.

MediaType.Parameter

The string tuple represents a MIME type parameter.

§Constructors

§
new MediaType(typeName: string, subtypeName: string, parameters?: Array<MediaType.Parameter>, original?) private
[src]
@param typeName

The type of the MIME type.

@param subtypeName

The subtype of the MIME type.

@param parameters

The parameters of the MIME type.

@param original

The original string that was passed to the fromString method.

§Properties

§
type: string readonly
[src]

The type of this MIME type.

@example
const mediaType = MediaType.fromString('application/soap+xml; charset=utf-8;action="https://example.com/example"');

mediaType.type;
// → "application"
§
subtype: string readonly
[src]

The subtype of this MIME type.

@example
const mediaType = MediaType.fromString('application/soap+xml; charset=utf-8;action="https://example.com/example"');

mediaType.subtype;
// → "soap+xml"
§
suffix: string readonly
[src]

The +suffix (structured syntax suffix) of this MIME type.

@example
const mediaType = MediaType.fromString('application/soap+xml; charset=utf-8;action="https://example.com/example"');

mediaType.suffix;
// → "+xml"
§
essence: string readonly
[src]

The essence of this MIME type.

@example
const mediaType = MediaType.fromString('application/soap+xml; charset=utf-8;action="https://example.com/example"');

mediaType.essence;
// → "application/soap+xml"
§
originalString: string readonly
[src]

When this instance was generated by the fromString method, The original string that was passed to the fromString method; Otherwise, A serialized string representation.

§Methods

§
equals(other: MediaType, options?: MediaType.CompareOptions): boolean
[src]

Determines whether the MIME type represented by this instance is equal to the MIME type represented by other instance.

@param other

The other instance of MediaType.

@param options

The MediaType.CompareOptions dictionary.

@return

If two MIME types are equal, true; Otherwise, false.

@example
const mediaTypeA = MediaType.fromString('application/soap+xml; charset=utf-8;action="https://example.com/example"');

const mediaTypeB = MediaType.fromString('application/soap+xml; charset=utf-16;action="https://example.com/example"');
mediaTypeA.equals(mediaTypeB);
// → false

const mediaTypeC = MediaType.fromString('APPLICATION/SOAP+XML;ACTION="https://example.com/example";CHARSET=utf-8');
mediaTypeA.equals(mediaTypeC);
// → true

const mediaTypeD = MediaType.fromString('application/soap+xml; charset=UTF-8;action="https://example.com/example"');
mediaTypeA.equals(mediaTypeD);
// → false
mediaTypeA.equals(mediaTypeD, { caseInsensitiveParameters: ["charset"] });
// → true
§
getParameterValue(parameterName: string): string | null
[src]

Returns a value of a specified parameter of this MIME type.

@param parameterName

The parameter name.

@return

A parameter value. If the parameter does not exist, null.

@example
const mediaType = MediaType.fromString('application/soap+xml; charset=utf-8;action="https://example.com/example"');

mediaType.getParameterValue("charset");
// → "https://example.com/example"

mediaType.getParameterValue("foo");
// → null
§
hasParameter(parameterName: string): boolean
[src]

Returns whether this MIME type has the specified parameter.

@param parameterName

The parameter name.

@return

If this MIME type has the specified parameter, true; Otherwise, false.

@example
const mediaType = MediaType.fromString('application/soap+xml; charset=utf-8;action="https://example.com/example"');

mediaType.hasParameter("charset");
// → true

mediaType.hasParameter("foo");
// → false
§
parameterNames(): IterableIterator<string>
[src]

Returns a new iterator object that contains the names for each parameter in this MIME type.

@return

A new iterator object.

@example
const mediaType = MediaType.fromString('application/soap+xml; charset=utf-8;action="https://example.com/example"');

[ ...mediaType.parameterNames() ];
// → [ "charset", "action" ]
§
parameters(): IterableIterator<MediaType.Parameter>
[src]

Returns a new iterator object that contains the name-value pairs for each parameter in this MIME type.

@return

A new iterator object.

@example
const mediaType = MediaType.fromString('application/soap+xml; charset=utf-8;action="https://example.com/example"');

[ ...mediaType.parameters() ];
// → [ ["charset", "utf-8"], ["action", "https://example.com/example"] ]
§
toJSON(): string
[src]

Returns a serialized string representation.

@return

A serialized string representation.

@example
const mediaType = MediaType.fromString('application/soap+xml; charset=utf-8;action="https://example.com/example"');

mediaType.toJSON();
// → 'application/soap+xml;charset=utf-8;action="https://example.com/example"'
§
toString(): string
[src]

Returns a serialized string representation.

@return

A serialized string representation.

@example
const mediaType = MediaType.fromString('application/soap+xml; charset=utf-8;action="https://example.com/example"');

mediaType.toString();
// → 'application/soap+xml;charset=utf-8;action="https://example.com/example"'
§
withoutParameters(): MediaType
[src]

Returns a copy of this instance with no parameters.

@return

A new instance.

@example
const sourceMediaType = MediaType.fromString('application/soap+xml; charset=utf-8;action="https://example.com/example"');

const paramsRemovedClone = sourceMediaType.withoutParameters();
paramsRemovedClone.toString();
// → 'application/soap+xml'

sourceMediaType.toString();
// → 'application/soap+xml;charset=utf-8;action="https://example.com/example"'
§
withParameters(parameters: Array<MediaType.Parameter>): MediaType
[src]

Returns a copy of this instance with the specified parameters.

@param parameters

The set of parameter name-value pairs.

@return

A new instance.

@example
const sourceMediaType = MediaType.fromString('application/soap+xml; charset=utf-8;action="https://example.com/example"');

const paramsModifiedClone = sourceMediaType.withParameters([ ["charset": "UTF-16"] ]);
paramsModifiedClone.toString();
// → 'application/soap+xml;charset=UTF-16'

sourceMediaType.toString();
// → 'application/soap+xml;charset=utf-8;action="https://example.com/example"'

§Static Methods

§
fromHeaders(headers: Headers): MediaType
[src]
@param headers

The Headers object of Request or Response.

@return

A MediaType instance.

§
fromString(text: string): MediaType
[src]

Parses a string representation of a MIME type.

@param text

The string to be parsed.

@return

A MediaType instance.