UNPKG

universal-common

Version:

Library that provides useful missing base class library functionality.

50 lines (49 loc) 2.07 kB
/** * Represents a MIME media type with type and subtype components. * Media types follow the format "type/subtype" (e.g., "text/html", "image/jpeg"). * * This class provides functionality to: * - Create media type objects from strings or separate type/subtype values * - Convert media type objects back to strings * - Look up media types based on file extensions */ export default class MediaType { /** * Returns the mapping between file extensions and their corresponding media types. * * @returns {Object} An object mapping file extensions to media type strings */ static get extensionMediaTypeMapping(): any; /** * Creates a MediaType instance from a file extension. * * @param {string} extension - The file extension (with or without leading dot) * @returns {MediaType?} A MediaType instance or null if not found * @throws {ArgumentError} Error message if extension parameter is missing * * Usage examples: * MediaType.fromExtension(".html") // Returns a MediaType for "text/html" * MediaType.fromExtension("jpg") // Returns a MediaType for "image/jpeg" */ static fromExtension(extension: string): MediaType | null; /** * Creates a new MediaType instance. * * @param {string} mediaType - Either a complete media type string ("type/subtype") or just the type component * @param {string} [subtype] - The subtype component (optional if mediaType contains both parts) * @throws {ArgumentError} Error message if parameters are invalid * * Usage examples: * new MediaType("text/html") // Creates from complete string * new MediaType("text", "html") // Creates from separate components */ constructor(mediaType: string, subtype?: string); type: string; subtype: string; /** * Converts the MediaType to its string representation. * * @returns {string} The media type string in "type/subtype" format */ toString(): string; }