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.
§Type Aliases
MediaType.CompareOptions | The |
MediaType.Parameter | The string tuple represents a MIME type parameter. |
§Constructors
The type of the MIME type.
The subtype of the MIME type.
The parameters of the MIME type.
The original string that was passed to the fromString
method.
§Properties
The +suffix (structured syntax suffix) of this MIME type.
const mediaType = MediaType.fromString('application/soap+xml; charset=utf-8;action="https://example.com/example"');
mediaType.suffix;
// → "+xml"
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
Determines whether the MIME type represented by this instance is equal to the MIME type represented by other instance.
The other instance of MediaType
.
The MediaType.CompareOptions
dictionary.
If two MIME types are equal, true
; Otherwise, false
.
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
Returns a value of a specified parameter of this MIME type.
The parameter name.
A parameter value. If the parameter does not exist, null
.
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
Returns whether this MIME type has the specified parameter.
The parameter name.
If this MIME type has the specified parameter, true
; Otherwise, false
.
const mediaType = MediaType.fromString('application/soap+xml; charset=utf-8;action="https://example.com/example"');
mediaType.hasParameter("charset");
// → true
mediaType.hasParameter("foo");
// → false
Returns a new iterator object that contains the names for each parameter in this MIME type.
A new iterator object.
const mediaType = MediaType.fromString('application/soap+xml; charset=utf-8;action="https://example.com/example"');
[ ...mediaType.parameterNames() ];
// → [ "charset", "action" ]
Returns a new iterator object that contains the name-value pairs for each parameter in this MIME type.
A new iterator object.
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"] ]
Returns a serialized string representation.
A serialized string representation.
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"'
Returns a serialized string representation.
A serialized string representation.
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"'
Returns a copy of this instance with no parameters.
A new instance.
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"'
Returns a copy of this instance with the specified parameters.
The set of parameter name-value pairs.
A new instance.
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"'